npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mitie

v1.0.0

Published

Node bindings for MIT Information Extraction https://github.com/mit-nlp/MITIE

Downloads

6

Readme

MITIE

This project is a node binding for the MIT Information Extraction library. It's written in C++ and js.

I've implemented both the Named Entity Recognition extractor and the Binary Relation detector.

Why?

The purpose of this library is to extract information from free-form text. It allows us to extract two different types of information.

Named Entities

Named Entities are typically a (person, location, organization, etc) but you can train your own model to find any type of named entity.

For example, suppose we take the sentence:

Barack Obama was born in Hawaii and graduated from Harvard Law School in Cambridge Massachusetts.

This library can extract and tag the named entities:

person: Barack Obama
location: Hawaii
organization: Harvard Law School
location: Cambridge Massachusetts

Binary Relations

Binary Relations allow us to predict relations bewteen our named entity. We must use different models for each relationship (MITIE comes with a number of classifiers but you can also train your own). As an example, suppose we run our example sentence through the model binary_relations/rel_classifier_people.person.place_of_birth.svm. It would show us that Entity 'Barack Obama' is related to Entity 'Hawaii'.

Barack Obama <born in> Hawaii

API

var mitie = require('mitie');

// Point it at a ner model .dat file
// You can also find where to get these on the main MIT project repo

var nerFile = '/usr/local/Cellar/mitie/0.4/share/MITIE-models/english/ner_model.dat';
var neExtractor = new mitie.EntityExtractor(nerFile);

// Feed in some data to the predict method

var data = "Barack Obama visited New Orleans today for the anniversary of Hurricane Katrina."
var results = neExtractor.predict(data);

/**
 * results => {
 *  tags:
 *    [ { tagNumber: 0,
 *        score: 1.0957487452879051,
 *        tagType: 'PERSON',
 *        tokens: 'Barack Obama' },
 *      { tagNumber: 1,
 *        score: 0.8764343236070008,
 *        tagType: 'LOCATION',
 *        tokens: 'New Orleans' } ] }
 */

var relFile = '/usr/local/Cellar/mitie/0.4/share/MITIE-models/english/binary_relations/rel_classifier_people.person.place_of_birth.svm';
var relExtractor = new mitie.RelationExtractor(nerFile, relFile);

data = "Donald Trump says that Barack Obama was born in Kenya, not Hawaii.";
results = relExtractor.predict(data);

/**
 * results => {
 *   tags:
 *    [ { tagNumber: 0, tagType: 'PERSON', tokens: 'Donald Trump' },
 *      { tagNumber: 0, tagType: 'PERSON', tokens: 'Barack Obama' },
 *      { tagNumber: 1, tagType: 'LOCATION', tokens: 'Kenya' },
 *      { tagNumber: 1, tagType: 'LOCATION', tokens: 'Hawaii' } ],
 *   relations:
 *    [ { score: 0.5990590608043147,
 *        first: 'Barack Obama',
 *        second: 'Kenya' } ] } 
 */

Installing

The quickest way to get the mitie dependency is with homebrew:

brew install mitie

You can install with npm on the command line or in your package.json:

npm install mitie --save

Testing

Install with development deps:

npm install --dev

Set two env vars however you like (you can also inline):

export NER_MODEL=/usr/local/Cellar/mitie/0.4/share/MITIE-models/english/ner_model.dat
export REL_MODEL=/usr/local/Cellar/mitie/0.4/share/MITIE-models/english/binary_relations/rel_classifier_people.person.place_of_birth.svm

Run mocha tests:

npm test

TODO

  • No error handling on C++ level
  • The the js API is not too good and it's not very efficient
  • Consider implementing trainers