Awesome
Informers
:fire: Fast transformer inference for Ruby
For non-ONNX models, check out Transformers.rb :slightly_smiling_face:
Installation
Add this line to your application’s Gemfile:
gem "informers"
Getting Started
Models
Embedding
- sentence-transformers/all-MiniLM-L6-v2
- Xenova/multi-qa-MiniLM-L6-cos-v1
- mixedbread-ai/mxbai-embed-large-v1
- Supabase/gte-small
- intfloat/e5-base-v2
- nomic-ai/nomic-embed-text-v1
- BAAI/bge-base-en-v1.5
- jinaai/jina-embeddings-v2-base-en
- Snowflake/snowflake-arctic-embed-m-v1.5
- Xenova/all-mpnet-base-v2
Reranking
sentence-transformers/all-MiniLM-L6-v2
sentences = ["This is an example sentence", "Each sentence is converted"]
model = Informers.pipeline("embedding", "sentence-transformers/all-MiniLM-L6-v2")
embeddings = model.(sentences)
For a quantized version, use:
model = Informers.pipeline("embedding", "Xenova/all-MiniLM-L6-v2", quantized: true)
Xenova/multi-qa-MiniLM-L6-cos-v1
query = "How many people live in London?"
docs = ["Around 9 Million people live in London", "London is known for its financial district"]
model = Informers.pipeline("embedding", "Xenova/multi-qa-MiniLM-L6-cos-v1")
query_embedding = model.(query)
doc_embeddings = model.(docs)
scores = doc_embeddings.map { |e| e.zip(query_embedding).sum { |d, q| d * q } }
doc_score_pairs = docs.zip(scores).sort_by { |d, s| -s }
mixedbread-ai/mxbai-embed-large-v1
query_prefix = "Represent this sentence for searching relevant passages: "
input = [
"The dog is barking",
"The cat is purring",
query_prefix + "puppy"
]
model = Informers.pipeline("embedding", "mixedbread-ai/mxbai-embed-large-v1")
embeddings = model.(input)
Supabase/gte-small
sentences = ["That is a happy person", "That is a very happy person"]
model = Informers.pipeline("embedding", "Supabase/gte-small")
embeddings = model.(sentences)
intfloat/e5-base-v2
doc_prefix = "passage: "
query_prefix = "query: "
input = [
doc_prefix + "Ruby is a programming language created by Matz",
query_prefix + "Ruby creator"
]
model = Informers.pipeline("embedding", "intfloat/e5-base-v2")
embeddings = model.(input)
nomic-ai/nomic-embed-text-v1
doc_prefix = "search_document: "
query_prefix = "search_query: "
input = [
doc_prefix + "The dog is barking",
doc_prefix + "The cat is purring",
query_prefix + "puppy"
]
model = Informers.pipeline("embedding", "nomic-ai/nomic-embed-text-v1")
embeddings = model.(input)
BAAI/bge-base-en-v1.5
query_prefix = "Represent this sentence for searching relevant passages: "
input = [
"The dog is barking",
"The cat is purring",
query_prefix + "puppy"
]
model = Informers.pipeline("embedding", "BAAI/bge-base-en-v1.5")
embeddings = model.(input)
jinaai/jina-embeddings-v2-base-en
sentences = ["How is the weather today?", "What is the current weather like today?"]
model = Informers.pipeline("embedding", "jinaai/jina-embeddings-v2-base-en", model_file_name: "../model")
embeddings = model.(sentences)
Snowflake/snowflake-arctic-embed-m-v1.5
query_prefix = "Represent this sentence for searching relevant passages: "
input = [
"The dog is barking",
"The cat is purring",
query_prefix + "puppy"
]
model = Informers.pipeline("embedding", "Snowflake/snowflake-arctic-embed-m-v1.5")
embeddings = model.(input, model_output: "sentence_embedding", pooling: "none")
Xenova/all-mpnet-base-v2
sentences = ["This is an example sentence", "Each sentence is converted"]
model = Informers.pipeline("embedding", "Xenova/all-mpnet-base-v2")
embeddings = model.(sentences)
mixedbread-ai/mxbai-rerank-base-v1
query = "How many people live in London?"
docs = ["Around 9 Million people live in London", "London is known for its financial district"]
model = Informers.pipeline("reranking", "mixedbread-ai/mxbai-rerank-base-v1")
result = model.(query, docs)
jinaai/jina-reranker-v1-turbo-en
query = "How many people live in London?"
docs = ["Around 9 Million people live in London", "London is known for its financial district"]
model = Informers.pipeline("reranking", "jinaai/jina-reranker-v1-turbo-en")
result = model.(query, docs)
BAAI/bge-reranker-base
query = "How many people live in London?"
docs = ["Around 9 Million people live in London", "London is known for its financial district"]
model = Informers.pipeline("reranking", "BAAI/bge-reranker-base")
result = model.(query, docs)
Other
You can use the feature extraction pipeline directly.
model = Informers.pipeline("feature-extraction", "Xenova/all-MiniLM-L6-v2", quantized: false)
embeddings = model.(sentences, pooling: "mean", normalize: true)
The model must include a .onnx
file (example). If the file is not at onnx/model.onnx
or onnx/model_quantized.onnx
, use the model_file_name
option to specify the location.
Pipelines
Embedding
embed = Informers.pipeline("embedding")
embed.("We are very happy to show you the 🤗 Transformers library.")
Reranking
rerank = Informers.pipeline("reranking")
rerank.("Who created Ruby?", ["Matz created Ruby", "Another doc"])
Named-entity recognition
ner = Informers.pipeline("ner")
ner.("Ruby is a programming language created by Matz")
Sentiment analysis
classifier = Informers.pipeline("sentiment-analysis")
classifier.("We are very happy to show you the 🤗 Transformers library.")
Question answering
qa = Informers.pipeline("question-answering")
qa.("Who invented Ruby?", "Ruby is a programming language created by Matz")
Feature extraction
extractor = Informers.pipeline("feature-extraction")
extractor.("We are very happy to show you the 🤗 Transformers library.")
Zero-shot classification [unreleased]
classifier = Informers.pipeline("zero-shot-classification")
classifier.("text", ["label1", "label2", "label3"])
Fill mask [unreleased]
unmasker = Informers.pipeline("fill-mask")
unmasker.("Paris is the [MASK] of France.")
Image classification [unreleased]
classifier = Informers.pipeline("image-classification")
classifier.(URI("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"))
Zero-shot image classification [unreleased]
classifier = Informers.pipeline("zero-shot-image-classification")
classifier.(URI("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"), ["cat", "dog", "tiger"])
Object detection [unreleased]
detector = Informers.pipeline("object-detection")
detector.(URI("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"))
Image feature extraction [unreleased]
extractor = Informers.pipeline("image-feature-extraction")
extractor.(URI("https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/pipeline-cat-chonk.jpeg"))
Credits
This library was ported from Transformers.js and is available under the same license.
Upgrading
1.0
Task classes have been replaced with the pipeline
method.
# before
model = Informers::SentimentAnalysis.new("sentiment-analysis.onnx")
model.predict("This is super cool")
# after
model = Informers.pipeline("sentiment-analysis")
model.("This is super cool")
History
View the changelog
Contributing
Everyone is encouraged to help improve this project. Here are a few ways you can help:
- Report bugs
- Fix bugs and submit pull requests
- Write, clarify, or fix documentation
- Suggest or add new features
To get started with development:
git clone https://github.com/ankane/informers.git
cd informers
bundle install
bundle exec rake download:files
bundle exec rake test