Informers
๐ State-of-the-art natural language processing for Ruby
Supports:
- Sentiment analysis
- Question answering
- Named-entity recognition
- Text generation
Installation
Add this line to your applicationโs Gemfile:
gem "informers"
Getting Started
- Sentiment analysis
- Question answering
- Named-entity recognition
- Text generation
- Feature extraction
- Fill mask
Sentiment Analysis
First, download the pretrained model.
Predict sentiment
model = Informers::SentimentAnalysis.new("sentiment-analysis.onnx")
model.predict("This is super cool")
This returns
{label: "positive", score: 0.999855186578301}
Predict multiple at once
model.predict(["This is super cool", "I didn't like it"])
Question Answering
First, download the pretrained model.
Ask a question with some context
model = Informers::QuestionAnswering.new("question-answering.onnx")
model.predict(
question: "Who invented Ruby?",
context: "Ruby is a programming language created by Matz"
)
This returns
{answer: "Matz", score: 0.9980658360049758, start: 42, end: 46}
Note: The question and context combined are limited to 384 tokens
Named-Entity Recognition
First, export the pretrained model.
Get entities
model = Informers::NER.new("ner.onnx")
model.predict("Nat works at GitHub in San Francisco")
This returns
[
{text: "Nat", tag: "person", score: 0.9840519576513487, start: 0, end: 3},
{text: "GitHub", tag: "org", score: 0.9426134775785775, start: 13, end: 19},
{text: "San Francisco", tag: "location", score: 0.9952414982243061, start: 23, end: 36}
]
Text Generation
First, export the pretrained model.
Pass a prompt
model = Informers::TextGeneration.new("text-generation.onnx")
model.predict("As far as I am concerned, I will", max_length: 50)
This returns
As far as I am concerned, I will be the first to admit that I am not a fan of the idea of a "free market." I think that the idea of a free market is a bit of a stretch. I think that the idea
Feature Extraction
First, export a pretrained model.
model = Informers::FeatureExtraction.new("feature-extraction.onnx")
model.predict("This is super cool")
Fill Mask
First, export a pretrained model.
model = Informers::FillMask.new("fill-mask.onnx")
model.predict("This is a great <mask>")
Models
Task | Description | Contributor | License | Link |
---|---|---|---|---|
Sentiment analysis | DistilBERT fine-tuned on SST-2 | Hugging Face | Apache-2.0 | Link |
Question answering | DistilBERT fine-tuned on SQuAD | Hugging Face | Apache-2.0 | Link |
Named-entity recognition | BERT fine-tuned on CoNLL03 | Bayerische Staatsbibliothek | In-progress | Link |
Text generation | GPT-2 | OpenAI | Custom | Link |
Some models are quantized to make them faster and smaller.
Deployment
Check out Trove for deploying models.
trove push sentiment-analysis.onnx
Credits
This project uses many state-of-the-art technologies:
- Transformers for transformer models
- Bling Fire and BERT for high-performance text tokenization
- ONNX Runtime for high-performance inference
Some code was ported from Transformers and is available under the same license.
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
export MODELS_PATH=path/to/onnx/models
bundle exec rake test