🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fasttext-js

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fasttext-js

Node.js interface for fastText

1.0.2
latest
Source
npm
Version published
Weekly downloads
4
300%
Maintainers
2
Weekly downloads
 
Created
Source

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

FAQs

Package last updated on 22 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts