0.2.2 • Published 6 years ago

fasttext-native v0.2.2

Weekly downloads
2
License
MIT
Repository
github
Last release
6 years ago

fasttext-native

fastText native bindings for ⬡.js

npm Travis David

Forked from pragonauts's fast-text

Features

  • Executing prediction models
  • Searching nearest neighbour
  • Prebuilt binaries for Linux and macOS (Windows is not supported by fastText)
  • Tracking latest fastText upstream version (currently version 0.1.0)

Usage

Prediction

There is a simple class for executing prediction models:

const path = require('path')
const { Classifier } = require('fasttext-native')

const model = path.resolve(__dirname, './classification.bin')

const classifier = new Classifier(model)

classifier.predict('how it works', 1, (err, res) => {
  if (err) {
    console.error(err)
  } else if (res.length > 0) {
    const tag = res[0].label // __label__someTag
    const score = res[0].valuel // 1.3455345
  } else {
    console.log('No matches')
  }
})

Nearest neighbour

There is a simple class for searching nearest neighbours:

const path = require('path')
const { Query } = require('fasttext-native')

const model = path.resolve(__dirname, './skipgram.bin')

const query = new Query(model)

query.nn('word', 10, (err, res) => {
  if (err) {
    console.error(err)
  } else if (res.length > 0) {
    const tag = res[0].label // letter
    const score = res[0].valuel // 0.99992
  } else {
    console.log('No matches')
  }
})