fasttext-js

1.0.2 • Public • Published

fasttext-js

Build Status

Node.js interface for fastText

Setup

We can install fasttext-js locally by running:

npm install --save fasttext-js

or

yarn add fasttext-js

Usage

import { predictAsync, trainAsync } from 'fasttext-js';
 
const dataPath = './inbound.txt';
/* inbound.txt content
Opt in __label__N
Opt out __label_Y
Hello __label__N
...
*/
const modelPath = './model.bin';
 
// Train supervised text classifiers
trainAsync(dataPath, modelPath)
  .then(() => {
    const messages = [
      'Opt in',
      'Opt out'
    ];
 
    // Obtain the most likely label for an array of of sentences with confidence rate
    return predictAsync(modelPath, messages);
  })
  .then(({ predictions }) => {
    console.log(predictions);
    /*
    "predictions": [
        {
            "label": "N",
            "confidence": 0.986328
        },
        {
            "label": "Y",
            "confidence": 0.693359
        }
    ]
    */
  })
  .catch((err) => {
    console.log(err);
  });

References

Train supervised text classifiers with txt file at dataPath and store model to modelPath.

trainAsync(dataPath, modelPath) // > Promise

Obtain the most likely label for an array of of sentences with confidence rate using model at modelPath.

predictAsync(modelPath, sentences) // > Promise

Readme

Keywords

none

Package Sidebar

Install

npm i fasttext-js

Weekly Downloads

4

Version

1.0.2

License

MIT

Last publish

Collaborators

  • cea-admin
  • humbertolopez
  • m2mathew
  • thomasjasonm1
  • vattila2049
  • hai-cea