FastText › Using Pretrained FastText Models
Language AI HandbookAll chapters FastText › Using Pretrained FastText ModelsOne section · Sections in this chapter11 / 15 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Training FastText from scratch requires a large corpus and substantial compute time. For most applications, a better starting point is one of the pretrained models that Meta (Facebook AI Research) distributes publicly. These cover 157 languages and were trained on Wikipedia and Common Crawl text, giving broad coverage across both formal and informal registers.
The fasttext Python package provides a clean interface for loading and querying these models. The steps below show the main operations you will use in practice:
# Install the library (run once in your environment):
# uv pip install fasttext-wheel
import fasttext
import fasttext.util
# Download the English model (this downloads ~4GB of data on first run):
fasttext.util.download_model("en", if_exists="ignore")
ft_en = fasttext.load_model("cc.en.300.bin")
# Query word vectors, including OOV words:
vec_running = ft_en.get_word_vector("running") # shape: (300,)
vec_runing = ft_en.get_word_vector("runing") # OOV typo, still gets a vector
# Find nearest neighbors in the pretrained space:
neighbors = ft_en.get_nearest_neighbors("runner", k=5)
# Returns list of (similarity, word) tuples# Reduce dimensionality for memory efficiency (optional):
# fasttext.util.reduce_model(ft_en, 100) # reduce from 300 to 100 dimensions
# ft_en.save_model('cc.en.100.bin')
# Cross-lingual: load models for multiple languages and align them
# (requires MUSE alignment matrices, see Meta's multilingual tools)The pretrained models use the full production settings: 300-dimensional embeddings, 2 million hash buckets, n-gram range 3 to 6, and training on datasets orders of magnitude larger than our toy example. The nearest-neighbor results from these models reflect semantic and morphological relationships captured from billions of tokens of text.
One practical note: the .bin format includes the full n-gram table needed for OOV inference. If you only need embeddings for known vocabulary words, you can use the .vec format, which is a simple text file of word-to-vector mappings. The .vec format is much smaller (a few hundred MB versus several GB) but loses OOV capability entirely.