Skip to content

messense/fasttext-rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

214 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fasttext-rs

CI codecov Crates.io docs.rs

Pure Rust implementation of fastText

Installation

Add it to your Cargo.toml:

[dependencies]
fasttext = "0.8"

Usage

Training a model

use fasttext::FastText;
use fasttext::args::{Args, ModelName};

let mut args = Args::default();
args.input = "data.txt".into();
args.model = ModelName::Supervised;
args.epoch = 25;
args.lr = 1.0;

let model = FastText::train(args).unwrap();
model.save_model("model.bin").unwrap();

Loading and predicting

use fasttext::FastText;

let model = FastText::load_model("model.bin").unwrap();
let predictions = model.predict("Which baking dish is best?", 3, 0.0);
for pred in &predictions {
    println!("{} {}", pred.label, pred.prob);
}

Nearest neighbors

use fasttext::FastText;

let model = FastText::load_model("model.bin").unwrap();
let neighbors = model.get_nn("king", 10);
for (score, word) in &neighbors {
    println!("{word}\t{score}");
}

CLI

A command-line tool compatible with the C++ fastText CLI is available behind the cli feature:

cargo install fasttext --features cli

It supports C++-style single-dash flags (e.g. -epoch 25) as well as standard double-dash flags (--epoch 25):

fasttext supervised -input data.txt -output model -epoch 25 -lr 1.0
fasttext predict model.bin test.txt
fasttext test model.bin test.txt
fasttext nn model.bin

License

This work is released under the MIT license. A copy of the license is provided in the LICENSE file.

About

Rust implementation of fastText

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages