What is fastText

  • fastText is just linear-classifier with explicit low-rank constraint (the embedding table)

1.1 Notation

  • Vocabulary of features (tokens and n-grams): size .
  • Number of classes: .
  • Embedding dimension (hidden size): .
  • Document → multiset (because the same words/n-grams can appear multiple times) of features

fastText represents a document as a normalized bag-of-features vector:

This is just like a one-hot vector but divided by the number of features in .

Two parameter matrices:

  • Embedding / input matrix
  • Output matrix

The document representation (hidden feature) is:

Concretely, because ​ is a normalized bag, i.e. average of the embeddings of all features (words + n-grams).

The class scores are just a linear projection:

To obtain the final probablities, we can just use softmax or hierarchical softmax if the number of classes is too large.

1.2 Low-rank view

If you define a single big weight matrix:

then

So fastText is exactly a linear classifier in the bag-of-features space with weight matrix WWW, but constrained to have rank ≤ .

N-gram features + hashing trick

The base model uses word unigrams, but fastText improves results significantly with word n-grams (bigrams, trigrams, etc.).

2.1 Bag of n-grams

Instead of just:

you also include:

  • word bigrams:
  • maybe trigrams, up to some max order.

All of these are simply treated as additional “tokens” in the vocabulary and embedded in the same space:

  • Each n-gram has its own column in .
  • The document representation is still the average of all present tokens and n-grams.

This partially injects word order information into an otherwise bag-of-words model.

2.2 Hashing trick for n-grams

Explicitly storing full n-gram vocabulary is memory-expensive (billions of possible n-grams), so they use the hashing trick:

  • Choose a fixed number of bins :
    • If only bigrams:
    • If higher n-grams:
  • For each n-gram string , compute a hash
  • Map n-gram to a bucket index

This index behaves like a synthetic “token id” used to index the columns of AAA. Collisions between distinct n-grams mean their embeddings are shared, which introduces a bit of noise but works well in practice.

The final input feature set is then:

How to train it in practice

Deepseek-Math

  • Deepseek-Math used it as binary classifier for math web pages
  • They train it using the fastText library
  • Task: binary classification: math vs non-math web pages
  • Training data:
    • 500k positives from OpenWebMath
    • 500k negatives sampled from Common Crawl
  • fastText hyperparameters (explicit in the paper):
    • dim = 256 (embedding size)
    • lr = 0.1
    • wordNgrams = 3 (max length of word n-gram)
    • minCount = 3 (minimum word occurrences)
    • epoch = 3
    • minn = 0, maxn = 0 (no char n-grams mentioned; they only talk about word n-grams)
    • Loss function isn’t specified; they just say “fastText (Joulin et al. 2016)” → in practice that usually means default supervised settings

FineWeb

FineWeb itself uses fastText only as a language detector, not a custom classifier:

  • Task: language ID to keep (mostly) English text.
  • Model: off-the-shelf fastText language classifier (e.g. lid.176.*).
  • Filtering rule: keep samples where English probability ≥ 0.65