Skip to content
fastText native bindings for ⬡.js
C++ Python JavaScript
Branch: develop
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode
src
test
vendor/fasttext
.gitignore
.gitmodules
.npmignore
.travis.yml
README.md
binding.gyp
index.js
mocha.opts
package-lock.json
package.json

README.md

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')
  }
})
You can’t perform that action at this time.