---
title: Unigram Language Model Overview
url: https://www.emergentmind.com/topics/unigram-language-model-ulm
type: topic
---

# Unigram Language Model Overview

A unigram language model (ULM) is a statistical language model that assigns probabilities to words (or subword pieces) in a corpus under the assumption that each token is generated independently of its context. The central mathematical property is the factorization of the joint probability of a sequence into a product of individual word probabilities, resulting in a “zeroth-order” model that captures only the frequency distribution of units in the training data. ULMs serve as fundamental baselines for language modeling, lexical analysis, subword tokenization, and bias initialization in neural networks, and are also critical reference points in evaluating context-dependent models and more advanced estimators.

## 1. Formal Definition and Mathematical Principles

Let $w_1,\ldots,w_n$ be a sequence of tokens from a vocabulary $V$. The unigram model assumes:

$$
P(w_1,\ldots,w_n) = \prod_{i=1}^n P(w_i)
$$

where $P(w_i)$ is the marginal (context-free) probability of token $w_i$ [1602.07803][2212.09686]. Estimation proceeds via empirical counts:

$$
P(w) = \frac{C(w)}{N}
$$

where $C(w)$ denotes the count of $w$ in a training corpus $C$, and $N$ is the total number of tokens. This estimator is maximally efficient but assigns $P(w) = 0$ for any out-of-vocabulary (OOV) item, leading to negative bias for rare or unseen forms, and positive bias for frequently observed words due to mass reallocation [2106.02289].

In subword models, the probability of a segmentation $s = (x_1,\ldots,x_k)$ into subunits $x_i \in V$ is:

$$
P(s|V) = \prod_{i=1}^k p(x_i)
$$

and the probability of the original text $X$ is the sum over all valid segmentations:

$$
P(X|V) = \sum_{s \in S_X} P(s|V)
$$

where $S_X$ denotes all lexicon-conforming segmentations of $X$ [2512.12641][2004.03720].

## 2. Variants and Contexts of Use

### A. Word-Level ULMs
Classical applications include sequence probability estimation, language identification, and next-word prediction. For example, in Bangla word prediction, the unigram model provides accuracy of approximately 21% for next-word selection using a 0.25M token corpus (14,872 word types), significantly underperforming compared to bigram or trigram models [1602.07803].

### B. Subword ULMs and Tokenization
Unigram LM tokenization, as introduced by Kudo (2018) and commonly implemented in the SentencePiece package, is a probabilistic global approach to subword segmentation [2512.12641][2004.03720]. The method begins with a large lexicon of substrings, then applies an expectation-maximization (EM) procedure where candidate pieces are pruned based on their contribution to the corpus likelihood. This global likelihood approach contrasts with greedy procedures such as Byte-Pair Encoding (BPE).

In subword tokenization:

- The EM algorithm alternates between (i) inferring expected counts of pieces over all possible segmentations (E-step, typically using forward–backward or Viterbi algorithms), and (ii) updating piece probabilities (M-step).
- Vocabulary pruning is guided by estimating the loss in data likelihood (often perplexity) upon removing each piece.
- Final segmentations for inference are produced by Viterbi decoding, maximizing $\sum \log p(x_i)$ over all decompositions [2512.12641][2004.03720].

### C. ULM as Prior in Neural Architectures
NMT and language generation models can initialize the bias vector in the output layer with the log-unigram distribution:

$$
b_w^{(0)} = \log \hat p_{\rm unigram}(w)
$$

where $\hat p_{\rm unigram}(w)$ is the estimated unigram frequency. This factorizes the model’s next-token distribution as a product-of-experts, with one expert carrying the frequency prior and another the context-sensitive component, improving learning efficiency and helping to decorrelate neural features from lexical frequency [2212.09686].

### D. Proper Modeling of Unigram Distribution
Hierarchical (“two-stage”) neural models have been proposed to address OOV and tail probability biases:

- Word forms are drawn from a generator (e.g., character-level LSTM), while allocation of probability mass over observed tokens is smoothed using a Pitman–Yor process adaptor.
- Such models avoid assigning zero probability to unseen types and improve generalization to rare and OOV forms [2106.02289].

## 3. Algorithms, Implementation, and Evaluation

### A. Subword Vocabulary Induction

The ULM tokenization algorithm, used in tools such as SentencePiece, executes:

1. **Seed Initialization**: Collect all substrings in the corpus above a frequency threshold as candidates.
2. **EM + Pruning Loop**: Iteratively estimate piece probabilities and prune the least informative tokens based on their contribution to held-out likelihood.
3. **Final Pruning**: Once the vocabulary is slightly bigger than the target, remove the lowest-probability pieces to reach the desired size [2512.12641].

A simplified “Final-Style Pruning” variant omits per-piece loss computation in the final stage, accepting a minor likelihood increase for reduced complexity.

### B. Evaluation Metrics

- Word-level ULMs: next-word prediction accuracy (fraction of test instances where the model's top unigram matches the gold next word), typically with no smoothing. For Bangla, average next-word accuracy is 21.24%; bigram and trigram models achieve 45.84% and 63.04%, respectively [1602.07803].
- Subword ULMs: tokenization quality is assessed via data likelihood (bits/byte), number of tokens produced, and morphological boundary recall. Baseline Unigram achieves 1.337 bits/byte with a 32k vocabulary, outperforming BPE in morphological alignment and matching BPE on raw compression with “Final-Style” pruning [2512.12641].
- Neural LM initialization: early learning efficiency is measured as area under the validation-BLEU learning curve, and performance as BLEU/chrF on translation test sets. Unigram-initialized bias improves both by a small but significant margin [2212.09686].
- Unigram distribution estimation: cross-entropy on held-out data is the primary metric. Two-stage neural estimators achieve lower cross-entropy than frequency or type-level LSTM baselines across seven morphologically diverse languages [2106.02289].

### C. Handling of Rare and OOV Forms

Sample-frequency ULMs assign zero probability to OOV forms. Neuralized two-stage models give OOV forms nonzero mass by backing off to character-level generators, improving tail estimates and overall average surprisal [2106.02289].

## 4. Comparative Analysis: ULM, BPE, and Other Models

| Aspect             | ULM (tokenization)                              | BPE                                       | Two-Stage ULM [2106.02289]           |
|--------------------|------------------------------------------------|-------------------------------------------|--------------------------------------|
| Segmentation       | Probabilistic (EM + pruning, global likelihood) | Greedy (merge frequent pairs, local opt.) | Probabilistic, with generator        |
| OOV Handling       | With smoothing, nonzero (subword regularization)| Fixed vocabulary, OOV mapping to <unk>    | Nonzero via char-LSTM generator      |
| Morphological Fit  | Recovers stems, affixes; high morph recall      | Tends to merge away morphemes             | State-of-the-art for rare OOV forms  |
| Model Objective    | Marginal likelihood over all segmentations      | Token count compression                   | Marginal likelihood + PYP smoothing  |
| Practicality       | Complex EM, simplified FSP available            | Widely implemented, fast                  | Requires MC-EM, more complex         |

ULM tokenization is favored where linguistic compositionality and subword variation are important. BPE is still competitive for pure compression and speed, but loses on morph boundary alignment. “Final-Style Pruning” bridges the implementation gap [2512.12641][2004.03720].

## 5. Empirical Results and Application Domains

- **Bangla Word Prediction**: ULM achieves average 21.24% next-word accuracy across sentences of varying length, with substantially higher scores for models incorporating context [1602.07803].
- **LM Pretraining Tokenization**: English and Japanese masked language models pretrained with ULM segmentation outperform those with BPE by 0.5–12.3 absolute F1 or accuracy points on downstream tasks, with larger gains in morphologically complex languages [2004.03720].
- **Neural Generation Priors**: Bias initialization with log-unigram frequencies accelerates early training and yields consistent BLEU/chrF improvements across several machine translation datasets [2212.09686].
- **Unigram Estimation**: Two-stage neural ULMs yield lower cross-entropy (e.g., 8.34 nats English, 11.85 nats Finnish) than token-based or type-based character LSTMs, particularly spiking ahead for OOV items [2106.02289].

## 6. Limitations, Extensions, and Open Issues

### Limitations

- Word-level ULMs without smoothing fail to handle OOVs and perform poorly in predictive contexts [1602.07803][2106.02289].
- Sample-frequency estimates systematically underrepresent the probability of rare or unseen forms, particularly in typologically rich or low-resource languages [2106.02289].
- Subword ULM training is computationally demanding (highest for full EM + pruning), though implementation simplifications (FSP) have reduced this barrier [2512.12641].

### Extensions

- Smoothing and hierarchical adaptation (e.g., Pitman–Yor process) provide nonzero estimates for unseen types and allow ULMs to interpolate between observed frequencies and generative form models [2106.02289].
- Bias initialization via higher-order n-gram distributions, adaptive priors, or non-subword token granularities remains an open line of inquiry [2212.09686].
- Theoretical and empirical study continues on optimum trade-offs between morphological faithfulness and token count compression [2512.12641][2004.03720].

### Open Questions

- The interaction of ULM priors with large-scale pretrained transformer models and other generative objectives (contrastive, RL fine-tuning) has yet to be fully mapped [2212.09686].
- The optimal balance between segmentation-driven regularization and pure compression in various NLP domains remains under active investigation [2512.12641].

## 7. Significance and Contemporary Role

The unigram language model, whether at the word or subword level, serves several foundational functions in modern NLP: a baseline for context-dependent models, a probabilistic engine for multilingual and morphologically rich tokenization, a low-cost initialization prior for neural networks, and a domain for advanced probabilistic estimation to address OOV and heavy-tailed phenomena. Empirical evidence consistently shows that, while ULMs are limited as standalone predictors, their probabilistic structure and simplicity enable critical advances in language modeling, tokenization, and neural architecture efficiency [1602.07803][2004.03720][2512.12641][2106.02289][2212.09686].

Source: https://www.emergentmind.com/topics/unigram-language-model-ulm