Skip to content

About

Embarrassingly parallel fasttext batch inference in Rust.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Latest commit

 

History

9 Commits

Folders and files

Repository files navigation

Installion

uv pip install fastertext

Usage

On a model such as glotlid you should expect around a 7x-10x speedup compared to regular fasttext.

! wget https://huggingface.co/cis-lmu/glotlid/resolve/main/model_v3.bin
from fastertext import load_model

model = load_model("model_v3.bin")
labels, probs = model.batch(["hello world", "bonjour le monde"], k=2)

id2label = model.get_labels()
print(id2label[int(labels[0, 0])], probs[0, 0])

Benchmark on longer Wikipedia documents

fastertext: 2.93s  34,114 texts/s
fasttext:   17.84s  5,604 texts/s
speedup:    6.1x
top-1 agreement: 100.0000%

Train your model

from fastertext import train_supervised

model = train_supervised("train.txt", epoch=25, lr=0.5, wordNgrams=2)
model.save_model("model.bin")
labels, probs = model.batch(["some text to classify"], k=1)

# hyperparameter search
model = train_supervised("train.txt", autotuneValidationFile="valid.txt", autotuneDuration=300)

Contributing

Need to support many linux builds through docker container to publish release wheels:

set -e
rustup target add x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu
uv pip install 'maturin[zig]'

for rust_target in x86_64-unknown-linux-gnu aarch64-unknown-linux-gnu; do
    maturin build --release --zig --target "$rust_target" --compatibility manylinux2014
done

uv publish target/wheels/*.whl

Citations

@misc{shippole2026fastertext,
  author       = {Shippole, Enrico},
  title        = {fastertext: embarrassingly parallel fasttext batch inference in rust},
  year         = {2026},
  howpublished = {\url{https://github.com/teraflop-ai/fastertext}}
}

@article{joulin2016bag,
  title={Bag of Tricks for Efficient Text Classification},
  author={Joulin, Armand and Grave, Edouard and Bojanowski, Piotr and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1607.01759},
  year={2016}
}

@article{bojanowski2016enriching,
  title={Enriching Word Vectors with Subword Information},
  author={Bojanowski, Piotr and Grave, Edouard and Joulin, Armand and Mikolov, Tomas},
  journal={arXiv preprint arXiv:1607.04606},
  year={2016}
}

@misc{messense_fasttext_rs,
  author       = {messense},
  title        = {fasttext-rs: fastText Rust binding},
  howpublished = {\url{https://github.com/messense/fasttext-rs}}
}

@misc{wang_fasttext_parallel,
  author       = {Congyu Wang},
  title        = {fasttext-parallel: multithreaded batch processing for fasttext},
  howpublished = {\url{https://github.com/Congyuwang/fasttext-parallel}}
}

About

Embarrassingly parallel fasttext batch inference in Rust.

Topics

Resources

Stars

5 stars

Watchers

0 watching

Forks

Packages

Contributors

Languages