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

fasttextweb

v1.0.4

Published

fastTextWeb is a custom version of Facebook's text classification library (fastText) that is intended for use in the browser.

Downloads

26

Readme

fastTextWeb

fastText is a library provided by Facebook, Inc. for efficient text classification and representation learning. It's great for creating highly accurate text classification models in a short period. However, it can't easily be used to serve predictions on the web - fastTextWeb aims to solve this issue. The project was compiled into JavaScript using Emscripten and can be used in a browser or run using Node.

Installation

$ npm install fasttextweb

Usage

fastTextWeb only supports two commands, which helps keep the project files small. I chose to remove all of the other functions because they're not required in order to make predictions. This means that a potential user could train a model using vanilla fastText and then use fastTextWeb to deploy the model and form predictions on the web.

All arguments are expected to be strings, so ensure you use quotation marks when you input arguments.

loadModel

Use loadModel to load a fastText model. The command takes in one argument, model.

$ node
> const fastText = require('fasttextweb');
> fastText.loadModel(<model>);

This function only takes in one argument, model, which is the relative file path of the model you want to load.

makePrediction

Use makePrediction to obtain the most likely labels for a piece of text. The command takes in four arguments, predictionType, textToClassify, k, and th.

$ node
> const fastText = require('fasttextweb');
> fastText.loadModel(<model>);
> fastText.makePrediction(<predictionType>, <textToClassify>, <k>, <th>);

This function takes in multiple arguments, which are all required.

<predictionType>: You can use either "predict" or "predict-prob". Use "predict" to obtain the k most likely labels for a piece of text. Alternatively, use "predict-prob" to obtain the k most likely labels for a piece of text with probabilities.

<textToClassify>: Simply enter the piece of text you want to classify, as a string.

<k>: The top k labels you want to return through the prediction.

<th>: The probability threshold ("0.0" was the default used during production).

Tests

The folder tests contains several usage examples of fastTextWeb. Below is an example use case of fastTextWeb with the balesModel dataset.

$ node
> const fastText = require('fasttextweb');
> fastText.loadModel("working/tests/balesModel/compressedModel.ftz");
The model has successfully been loaded!

> fastText.makePrediction("predict", "today was a really amazing day!", "1", "0.0");
__label__B

> fastText.makePrediction("predict-prob", "how about we put the spoons in the dishwasher?", "2", "0.0");
__label__C 0.959634 __label__B 0.0348174

What's Next

  • [x] Publish this package to the npm registry.
  • [x] Remove more unrequired functions and parts of the source code.
  • [x] Change some of the source code so that the 'index.js' file can be included in a website.

Acknowledgements

  1. Stuart Watt (Chief Technology Officer of Turalt) - I really appreciate the resources, help, and support that Stuart has provided. This project really wouldn't have been possible without him!
  2. fastText - A library provided by Facebook, Inc. for efficient text classification and representation learning.
  3. Emscripten - A toolchain for compiling to WebAssembly, built using LLVM, that lets you run C and C++ on the web at near-native speed without plugins.