Skip to content

ankane/informers

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Informers

🙂 State-of-the-art natural language processing for Ruby

Supports:

  • Sentiment analysis
  • Question answering
  • Named-entity recognition
  • Text generation

Build Status

Installation

Add this line to your application’s Gemfile:

gem "informers"

Getting Started

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}

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:

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:

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