mitie

Named-entity recognition for Ruby


Keywords
named-entity-recognition, ner
License
BSL-1.0
Install
gem install mitie -v 0.1.1

Documentation

MITIE

MITIE - named-entity recognition and binary relation detection - for Ruby

  • Finds people, organizations, and locations in text
  • Detects relationships between entities, like PERSON was born in LOCATION

Build Status Build status

Installation

Add this line to your application’s Gemfile:

gem 'mitie'

And download the pre-trained model for your language:

Getting Started

Load an NER model

model = Mitie::NER.new("ner_model.dat")

Create a document

doc = model.doc("Nat Friedman is the CEO of GitHub, which is headquartered in San Francisco")

Get entities

doc.entities

This returns

[
  {text: "Nat Friedman",  tag: "PERSON",       score: 1.099661347535191, offset: 0},
  {text: "GitHub",        tag: "ORGANIZATION", score: 0.344641651251650, offset: 27},
  {text: "San Francisco", tag: "LOCATION",     score: 1.428241888939011, offset: 61}
]

Get tokens

doc.tokens

Get tokens and their offset

doc.tokens_with_offset

Get all tags for a model

model.tags

Binary Relation Detection

Detect relationships betweens two entities, like:

  • PERSON was born in LOCATION
  • ORGANIZATION was founded in LOCATION
  • FILM was directed by PERSON

There are 21 detectors for English. You can find them in the binary_relations directory in the model download.

Load a detector

detector = Mitie::BinaryRelationDetector.new("rel_classifier_film.film.directed_by.svm")

And create a document

doc = model.doc("The Shawshank Redemption was directed by Frank Darabont")

Get relations

detector.relations(doc)

This returns

[{first: "Shawshank Redemption", second: "Frank Darabont", score: 1.124211742912441}]

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/mitie.git
cd mitie
bundle install
bundle exec rake vendor:all

export MITIE_MODELS_PATH=path/to/MITIE-models/english
bundle exec rake test