An excerpt from the repository, fetched Nov 13, 2026.
Read the project’s introduction
fastText
fastText is a library for efficient learning of word representations and sentence classification.
Table of contents
Resources
Models
Supplementary data
FAQ
Cheatsheet
Requirements
Building fastText
Getting the source code
Building fastText using make (preferred)
Building fastText using cmake
Building fastText for Python
Example use cases
Word representation learning
Obtaining word vectors for out-of-vocabulary words
Text classification
Full documentation
References
Enriching Word Vectors with Subword Information
Bag of Tricks for Efficient Text Classification
FastText.zip: Compressing text classification models
Join the fastText community
License
Resources
Models
Recent state-of-the-art English word vectors.
Word vectors for 157 languages trained on Wikipedia and Crawl.
Models for language identification and various supervised tasks.
Supplementary data
The preprocessed YFCC100M data used in [2].
FAQ
You can find answers to frequently asked questions on our website.
Cheatsheet
We also provide a cheatsheet full of useful one-liners.
Requirements
We are continuously building and testing our library, CLI and Python bindings under various docker images using circleci.
Generally, fastText builds on modern Mac OS and Linux distributions.
Since it uses some C++11 features, it requires a compiler with good C++11 support.
These include :
(g++-4.7.2 or newer) or (clang-3.3 or newer)
Compilation is carried out using a Makefile, so you will need to have a working make.
If you want to use cmake you need at least version 2.8.9.
One of the oldest distributions we successfully built and tested the CLI under is Debian jessie.
For the word-similarity evaluation script you will need:
Python 2.6 or newer
NumPy & SciPy
For the python bindings (see the subdirectory python) you will need:
Python version 2.7 or >=3.4
NumPy & SciPy
pybind11
One of the oldest distributions we successfully built and tested the Python bindings under is Debian jessie.
If these requirements make it impossible for you to use fastText, please open an issue and we will try to accommodate you.
Building fastText
We discuss building the latest stable version of fastText.
Getting the source code
You can find our latest stable release in the usual place.
There is also the master branch that contains all of our most recent work, but comes along with all the usual caveats of an unstable branch. You might want to use this if you are a developer or power-user.
Building fastText using make (preferred)
$ wget https://github.com/facebookresearch/fastText/archive/v0.9.2.zip
$ unzip v0.9.2.zip
$ cd fastText-0.9.2
$ make
This will produce object files for all the classes as well as the main binary fasttext.
If you do not plan on using the default system-wide compiler, update the two macros defined at the beginning of the Makefile (CC and INCLUDES).
Building fastText using cmake
For now this is not part of a release, so you will need to clone the master branch.
$ git clone https://github.com/facebookresearch/fastText.git
$ cd fastText
$ mkdir build && cd build && cmake ..
$ make && make install
This will create the fasttext binary and also all relevant libraries (shared, static, PIC).
Building fastText for Python
For now this is not part of a release, so you will need to clone the master branch.
$ git clone https://github.com/facebookresearch/fastText.git
$ cd fastText
$ pip install .
For further information and introduction see python/README.md
Example use cases
This library has two main use cases: word representation learning and text classification.
These were described in the two papers 1 and 2.
Word representation learning
In order to learn word vectors, as described in 1, do:
$ ./fasttext skipgram -input data.txt -output model
where data.txt is a training file containing UTF-8 encoded text.
By default the word vectors will take into account character n-grams from 3 to 6 characters.
At the end of optimization the program will save two files: model.bin and model.vec.
model.vec is a text file containing the word vectors, one per line.
model.bin is a binary file containing the parameters of the model along with the dictionary and all hyper parameters.
The binary file can be used later to compute word vectors or to restart the optimization.
Obtaining word vectors for out-of-vocabulary words
The previously trained model can be used to compute word vectors for out-of-vocabulary words.
Provided you have a text file queries.txt containing words for which you want to compute vectors, use the following command:
$ ./fasttext print-word-vectors model.bin < queries.txt
This will output word vectors to the standard output, one vector per line.
This can also be used with pipes:
$ cat queries.txt | ./fasttext print-word-vectors model.bin
See the provided scripts for an example. For instance, running:
$ ./word-vector-example.sh
will compile the code, download data, compute word vectors and evaluate them on the rare words similarity dataset RW [Thang et al. 2013].
Text classification
This library can also be used to train supervised text classifiers, for instance for sentiment analysis.
In order to train a text classifier using the method described in 2, use:
$ ./fasttext supervised -input train.txt -output model
where train.txt is a text file containing a training sentence per line along with the labels.
By default, we assume that labels are words that are prefixed by the string __label__.
This will output two files: model.bin and model.vec.
Once the model was trained, you can evaluate it by computing the precision and recall at k (P@k and R@k) on a test set using:
$ ./fasttext test model.bin test.txt k
The argument k is optional, and is equal to 1 by default.
In order to obtain the k most likely labels for a piece of text, use:
$ ./fasttext predict model.bin test.txt k
or use predict-prob to also get the probability for each label
$ ./fasttext predict-prob model.bin test.txt k
where test.txt contains a piece of text to
Read the full README on GitHub