Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations
Back to Writing

Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations

Michael Brenndoerfer•November 2, 2025•12 min read•2,848 words•Interactive

A comprehensive guide covering FastText and subword tokenization, including character n-gram embeddings, handling out-of-vocabulary words, morphological processing, and impact on modern transformer tokenization methods.

History of Language AI Cover
Part of History of Language AI

This article is part of the free-to-read History of Language AI book

View full handbook
Reading Level

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.

2016: Subword Tokenization and FastText

By 2016, word embeddings had become a fundamental tool in natural language processing, with word2vec demonstrating that dense vector representations could capture rich semantic and syntactic relationships. However, the field confronted a persistent challenge: how to handle words that appeared rarely or never in training corpora. These out-of-vocabulary words presented a fundamental limitation for embedding methods that treated each word as an atomic unit. Facebook AI Research, led by Piotr Bojanowski, Edouard Grave, Armand Joulin, and Tomas Mikolov, introduced FastText, a method that addressed this limitation by learning embeddings not just for words, but for subword components. This innovation opened new possibilities for handling morphologically rich languages, rare words, and domain-specific terminology.

The problem of rare and unseen words had been recognized since the earliest embedding methods. Word2vec and similar approaches assigned each word in the vocabulary a unique embedding vector. When encountering a word that wasn't in the training vocabulary, these methods had no principled way to represent it. This limitation particularly affected morphologically rich languages like Finnish, Turkish, or German, where words could have dozens of inflected forms, each appearing infrequently in corpora. Even in English, technical terminology, proper nouns, and new coinages presented challenges. A sentiment analysis system trained on general text might encounter domain-specific terms in user reviews, medical terms in patient reports, or technical jargon in engineering documents, all completely unrepresented in its vocabulary.

FastText emerged at a moment when the NLP community was seeking solutions to these vocabulary limitations. The method built on insights from morphological analysis and character-level language modeling, which had shown that subword information could be valuable for understanding word structure and meaning. By learning embeddings for character n-grams alongside word-level embeddings, FastText could construct representations for unseen words by combining the embeddings of their subword components. A word like "unseen" could be represented through embeddings for its character sequences, such as "<un", "uns", "nse", "see", "een", "en>", where "<" and ">" indicated word boundaries.

The significance of FastText extended beyond its technical innovation. The method demonstrated that neural word embeddings could be made more robust and generalizable by incorporating morphological and subword information. This insight would influence later developments in tokenization, particularly the move toward subword tokenization schemes like Byte Pair Encoding (BPE) and SentencePiece that would become standard in transformer-based language models. FastText showed that treating words as atomic units was not necessary, and that richer representations could emerge from modeling the internal structure of words.

The Problem

Word-level embedding methods like word2vec treated each word as an indivisible unit, assigning a single embedding vector to each vocabulary item. This approach worked well for frequent words that appeared many times in training corpora, allowing the model to learn reliable representations. However, it failed catastrophically for rare words and out-of-vocabulary terms. A word appearing only a handful of times during training received insufficient updates, leading to embeddings that captured little meaningful information. Completely unseen words received no representation at all, forcing systems to fall back to random vectors or special unknown word tokens that provided no semantic information.

The problem became particularly acute in morphologically rich languages. In languages like Finnish, a single root word might generate dozens of inflected forms through compounding and suffixation. The word "talo" (house) might appear as "talossa" (in the house), "talosta" (from the house), "taloon" (into the house), and many other variants. Each inflection represented a distinct vocabulary item in word-level models, fragmenting the available training data across many related forms. Since each form appeared less frequently, the embeddings learned for these variants were less reliable. More fundamentally, word-level embeddings could not capture the systematic relationships between these morphologically related forms, missing the linguistic insight that they shared a common root.

Even in morphologically simpler languages like English, rare words posed challenges. Domain-specific terminology appeared infrequently in general-purpose training corpora. Medical terms, scientific concepts, technical jargon, and proper nouns often had rich semantic content but sparse occurrence patterns. A text classification system trained on news articles might encounter specialized vocabulary when processing scientific papers, patient records, or legal documents. Without representations for these terms, the system would struggle to leverage the semantic information they conveyed.

Newly coined words and evolving vocabulary presented another limitation. Language changes constantly, with new words entering common usage through technological change, social media, cultural shifts, and domain-specific developments. A word embedding model trained on a static corpus could not represent words that emerged after training. This limitation particularly affected applications processing user-generated content, where creative spelling, slang, abbreviations, and neologisms were common. Social media text, with its informal language and rapid vocabulary evolution, exposed the brittleness of word-level approaches.

The computational implications of large vocabularies also created practical problems. Word-level models required storing and updating embeddings for every unique word in the vocabulary. For large-scale systems processing multiple languages or domains, vocabularies could contain millions of unique words. This vocabulary explosion increased memory requirements and computational costs during training and inference. The softmax normalization over large vocabularies, even with negative sampling approximations, remained computationally expensive. Large vocabularies also increased the risk of overfitting, where models memorized word-specific patterns rather than learning generalizable linguistic relationships.

Languages with rich morphological systems compounded these vocabulary problems. Agglutinative languages, where words can have many morphemes concatenated together, generated enormous vocabularies where most words appeared only once or twice. This data sparsity made it difficult to learn reliable embeddings. Additionally, the atomic treatment of words missed important linguistic generalizations. Morphologically related words should share similar embeddings, reflecting their shared roots and systematic morphological processes. Word-level embeddings failed to capture these relationships explicitly, relying instead on co-occurrence patterns that might be sparse for related but infrequent word forms.

The Solution

FastText addressed these limitations by learning embeddings for character n-grams in addition to word-level embeddings. Instead of treating words as atomic units, FastText represented each word as the sum of embeddings for its character n-grams. This approach allowed the model to construct meaningful representations for unseen words by combining embeddings of their subword components, even if the complete word had never appeared during training.

Character N-gram Embeddings

FastText represented words using a fixed-size set of character n-grams. For a word like "where", with n=3n=3, the method would extract character sequences of length 3: "<wh", "whe", "her", "ere", "re>", where "<" and ">" represented word boundaries. The embedding for "where" would be the sum of embeddings for these n-grams, plus optionally a special embedding for the complete word if it appeared in the vocabulary. This representation meant that words sharing character sequences would have related embeddings, even if the complete words were different.

The character n-gram approach captured several types of linguistic information. Prefixes and suffixes, common in morphological systems, appeared as repeated n-grams across words. Words sharing morphological affixes would develop similar embeddings in the relevant components. Root morphemes, appearing in multiple word forms, contributed consistent embedding components. Character-level patterns that indicated semantic or syntactic categories could also emerge, where certain n-gram sequences were associated with specific linguistic functions.

The method supported variable n-gram sizes, typically using n-grams from 3 to 6 characters in length. Longer n-grams captured more word-specific information, while shorter n-grams captured more general morphological patterns. The combination of multiple n-gram sizes allowed the model to balance specificity and generalizability. Very short n-grams could appear across many words, learning general patterns, while longer n-grams provided word-specific information when available.

Training Architecture

FastText used the same Skip-Gram architecture as word2vec, but with a crucial modification: the embedding for a word was computed as the sum of its n-gram embeddings. During training, the model learned both word-level embeddings (for frequent words) and n-gram embeddings (for character sequences). The prediction task remained the same: given a target word, predict its context words. However, when computing the embedding for the target word, FastText summed the embeddings of all its character n-grams.

For example, to compute the embedding for "running", FastText would extract n-grams like "<ru", "run", "unn", "nni", "nin", "ing", "ng>", and potentially others depending on the n-gram size range. The word embedding would be the sum of embeddings for these n-grams, possibly plus a word-specific embedding if "running" appeared frequently enough to warrant its own representation. This summed representation could then be used in the Skip-Gram prediction task, where the model learned to predict context words given the summed n-gram embeddings.

The training process used the same negative sampling approach as word2vec, maintaining computational efficiency while learning from large corpora. However, the parameters being learned included not just word embeddings but also n-gram embeddings that could be shared across many words. This parameter sharing meant that frequent n-grams, appearing in many words, received more training signal and developed more reliable embeddings. Rare words benefited from these well-trained n-gram embeddings, even if the words themselves appeared infrequently.

Handling Out-of-Vocabulary Words

The key advantage of FastText emerged when processing words not seen during training. For an unseen word, FastText could still construct an embedding by extracting its character n-grams and summing their embeddings. If the n-grams had been seen in other words during training, their embeddings would provide meaningful information about the unseen word's likely meaning. For example, if "unhappiness" was unseen but "unhappy" and "happiness" had appeared during training, the n-grams "<un", "hap", "piness", "ess>" might have learned embeddings that could combine to represent "unhappiness" reasonably well.

This capability was particularly valuable for morphologically rich languages, where unseen words often shared significant subword structure with seen words. A new inflected form of a known root word could be represented through its shared morphological components. Even completely novel words could benefit if their character n-grams matched patterns learned from similar words. The method gracefully degraded: words with completely novel character patterns would still receive embeddings, but these embeddings might be less informative until the model encountered similar patterns in training.

Applications and Impact

FastText quickly found applications across diverse NLP tasks where handling rare words and domain-specific vocabulary was important. In text classification, FastText embeddings improved performance on tasks involving technical domains, morphologically rich languages, and social media text. The method's ability to represent unseen words helped classifiers maintain performance when processing text from domains or genres not well-represented in training data.

Named entity recognition systems benefited from FastText's handling of proper nouns and technical terms. Many named entities appear infrequently in training corpora, making word-level embeddings unreliable. FastText could represent these entities through their character n-grams, allowing the model to leverage morphological patterns even for rare proper nouns. Systems processing multilingual text found FastText particularly valuable, as it could handle words from languages not explicitly in the training vocabulary by leveraging shared character patterns.

Information retrieval applications used FastText embeddings to improve matching between queries and documents containing rare or technical vocabulary. The subword representations helped capture semantic similarity even when exact word matches were absent. A query containing "cardiovascular" could match documents mentioning "cardiac" or "vascular" through shared character n-grams, even if "cardiovascular" itself was rare.

FastText also demonstrated effectiveness on morphologically rich languages. In languages like Finnish, Czech, or Arabic, where words have many inflected forms, FastText embeddings captured systematic relationships between morphologically related words. The shared n-gram components created embedding spaces where related word forms clustered together, reflecting their morphological relationships. This capability made FastText particularly valuable for multilingual NLP applications where handling multiple languages with diverse morphological systems was required.

The method's computational efficiency, similar to word2vec, made it practical for large-scale applications. FastText could train on corpora with billions of words using standard hardware, and inference remained fast even with n-gram extraction and summation. Pre-trained FastText embeddings for many languages became widely available, lowering barriers to using robust word representations in applications.

Social media and user-generated content applications found FastText valuable for handling informal language, creative spelling, and evolving vocabulary. The character n-gram approach could represent misspellings, abbreviations, and neologisms through their subword components, even when these forms were completely novel. This robustness made FastText embeddings useful for sentiment analysis, spam detection, and content moderation tasks processing diverse and evolving text.

Limitations

Despite its advances, FastText retained limitations from the word-level embedding paradigm while introducing new challenges. The method still produced static embeddings: each word (or its n-gram composition) received a single representation regardless of context. FastText could not capture polysemy or context-dependent meaning variations. The word "bank" would have a fixed representation whether it appeared in financial or geographical contexts, though the character n-grams might provide some morphological consistency.

The character n-gram approach, while helpful for handling rare words, introduced ambiguity when n-grams were shared across unrelated words. Words with similar character sequences but different meanings might develop overly similar embeddings due to shared n-grams. The method relied on the assumption that morphological similarity correlated with semantic similarity, which held for many cases but failed for others. False morphological relationships could emerge from shared character patterns that weren't actually meaningful.

Computational overhead increased compared to word2vec, as FastText needed to extract n-grams, sum embeddings, and potentially handle larger parameter spaces for n-gram embeddings. While still efficient, the additional computation made FastText somewhat slower than pure word-level approaches. The n-gram vocabulary could also be large, requiring significant memory for storing n-gram embeddings, though this was typically smaller than the word vocabulary explosion it helped mitigate.

The method's effectiveness depended on the quality and diversity of training data. Rare n-grams that appeared only in specific domains might not develop meaningful embeddings if those domains were underrepresented in training corpora. FastText worked best when character patterns in unseen words matched patterns learned from similar words, but completely novel morphological structures might still struggle.

FastText embeddings also captured the same statistical associations as word2vec, rather than true semantic understanding. Words that co-occurred frequently developed similar embeddings, even when this co-occurrence reflected topical rather than semantic relationships. The subword approach helped with rare words but didn't fundamentally address the distributional semantics limitations of word embedding methods.

The fixed n-gram size range meant FastText might miss important morphological boundaries. In some languages, morpheme boundaries don't align cleanly with character boundaries, and fixed-length n-grams might not capture these linguistic structures optimally. Languages with complex morphological systems might require morphological analysis to properly segment words, which FastText didn't explicitly perform.

Legacy

FastText demonstrated that incorporating subword information into word embeddings could significantly improve robustness and generalization. This insight would prove influential for later developments in tokenization and representation learning. The success of FastText showed that treating words as atomic units was not necessary, and that richer representations could emerge from modeling word structure.

The character n-gram approach influenced the development of subword tokenization schemes that would become standard in transformer-based language models. Byte Pair Encoding (BPE), introduced for neural machine translation, learned to segment words into subword units based on frequency patterns in training data. SentencePiece extended this approach with a unified framework for subword tokenization. These methods shared FastText's fundamental insight: representing words through subword components improved handling of rare words and out-of-vocabulary terms.

Modern transformer language models like BERT, GPT, and their successors use subword tokenization as a standard preprocessing step. These models tokenize text into subword units (often using BPE or SentencePiece) before learning contextualized embeddings through transformer architectures. FastText's demonstration that subword information was valuable paved the way for this now-standard approach, though modern methods learn tokenization and embeddings jointly rather than using fixed n-gram extraction.

The success of FastText also reinforced the value of morphological information for NLP applications, particularly for morphologically rich languages. Research into morphological analysis and processing continued to develop, with methods that explicitly model morphological structure building on the insights that FastText had demonstrated through character n-grams. Languages with rich morphology, which had previously been challenging for neural NLP methods, became more tractable through subword approaches.

FastText's handling of out-of-vocabulary words also influenced later approaches to robust NLP. The method showed that graceful degradation for unseen words was possible, and that models could maintain reasonable performance even when encountering vocabulary not present during training. This robustness became increasingly important as NLP systems were deployed in diverse domains and languages, where training data could not cover all possible vocabulary.

The method remains widely used in applications where fast, efficient word representations are needed and where handling rare words is important. FastText embeddings continue to be valuable for resource-constrained applications, multilingual settings, and domains with specialized vocabulary. While modern transformer models have largely superseded static word embeddings for many tasks, FastText's efficiency and robustness make it a practical choice for applications where computational resources or inference speed are constraints.

FastText's integration of subword information into the word2vec framework demonstrated how innovations could build incrementally on previous methods while addressing specific limitations. This pattern of incremental improvement, where new methods extend rather than completely replace earlier approaches, characterized much of the progress in neural NLP during the 2010s. FastText showed that sometimes the key to solving a problem was not a completely new architecture, but a thoughtful modification to existing methods that addressed specific failure modes.

Quiz

Ready to test your understanding of subword tokenization and FastText? Challenge yourself with these questions about how character n-grams transformed word embeddings and see how well you've grasped the key concepts.

Loading component...

Reference

BIBTEXAcademic
@misc{subwordtokenizationandfasttextcharacterngramembeddingsforrobustwordrepresentations, author = {Michael Brenndoerfer}, title = {Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations}, year = {2025}, url = {https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations}, organization = {mbrenndoerfer.com}, note = {Accessed: 2025-11-02} }
APAAcademic
Michael Brenndoerfer (2025). Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations. Retrieved from https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations
MLAAcademic
Michael Brenndoerfer. "Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations." 2025. Web. 11/2/2025. <https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations>.
CHICAGOAcademic
Michael Brenndoerfer. "Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations." Accessed 11/2/2025. https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations.
HARVARDAcademic
Michael Brenndoerfer (2025) 'Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations'. Available at: https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations (Accessed: 11/2/2025).
SimpleBasic
Michael Brenndoerfer (2025). Subword Tokenization and FastText: Character N-gram Embeddings for Robust Word Representations. https://mbrenndoerfer.com/writing/subword-tokenization-fasttext-character-ngram-embeddings-robust-word-representations
Michael Brenndoerfer

About the author: Michael Brenndoerfer

All opinions expressed here are my own and do not reflect the views of my employer.

Michael currently works as an Associate Director of Data Science at EQT Partners in Singapore, where he drives AI and data initiatives across private capital investments.

With over a decade of experience spanning private equity, management consulting, and software engineering, he specializes in building and scaling analytics capabilities from the ground up. He has published research in leading AI conferences and holds expertise in machine learning, natural language processing, and value creation through data.

Stay updated

Get notified when I publish new articles on data and AI, private equity, technology, and more.