DL0128 Subword Regularization

What is subword regularization, and why can it help machine translation quality?

Answer

Subword regularization is the practice of training a translation model on multiple stochastically sampled segmentations of the same sentence instead of the one deterministic segmentation a tokenizer normally emits. Any subword vocabulary is ambiguous: the word “smaller” can be a single piece, or small plus er, or sm plus all plus er, and a standard tokenizer always returns the same choice, so the model never sees the alternatives. Two mechanisms implement the sampling: unigram-LM sampling (Kudo 2018, shipped in SentencePiece), which draws a path from the segmentation lattice with probability proportional to P(\mathbf{x})^{\alpha}, and BPE-dropout (Provilkov 2020), which keeps the ordinary BPE merge table but skips each merge with probability p during application. The quality gain has three sources: it is free data augmentation over the same parallel corpus, it trains the embeddings of rare pieces that a deterministic segmenter almost never produces, and it makes the encoder robust to the segmentation shifts caused by typos, morphology, and domain change. Reported gains are roughly 1 BLEU on average, shrinking toward noise on large in-domain high-resource benchmarks and reaching 2 BLEU or more on low-resource pairs and out-of-domain test sets. Sampling is a training-time-only device: decoding uses the deterministic segmentation, or optionally averages scores over k sampled segmentations of the source.

(1) Segmentation Is Ambiguous: a fixed vocabulary admits exponentially many segmentations per sentence, and deterministic tokenization silently commits to one of them in every epoch.
(2) Unigram-LM Sampling: SentencePiece samples from the l-best lattice paths with a temperature \alpha, typically l = 64 and \alpha near 0.1 to 0.2, where small \alpha is near-uniform and \alpha \to \infty recovers the Viterbi segmentation.
(3) BPE-Dropout: drop each merge operation independently with p = 0.1 on both source and target; the vocabulary and merge table are unchanged, so it is a drop-in change to the tokenizer call.
(4) Approximate Marginalization: the model is pushed to score a sentence pair well under any plausible segmentation, which is closer to the true marginal P(Y \mid X) than a single-path proxy.
(5) Robustness Beats In-Domain Accuracy: the largest wins appear on low-resource, morphologically rich, noisy, and out-of-domain data, exactly where the test-time segmentation drifts from the training-time one.
(6) Costs Are Real: average sequence length grows, tokenization moves into the data loader and cannot be cached, and convergence is slower in wall-clock terms for the same number of updates.

Segmentation lattice for the word smaller: boundary nodes under the characters, with three bracketed paths drawn above them, one spanning the whole word as a single piece, one splitting into small plus er, and one splitting into sm plus all plus er, each annotated with its unigram probability and the sampling weight at alpha equal to 0.2

Figure 1: One word, three legal paths through the segmentation lattice. Deterministic tokenization always returns the top path, so the -er morpheme boundary is never shown to the encoder; sampling at \alpha = 0.2 returns the top path only about half the time and spends the rest of the probability mass on the finer decompositions.

The reason the same trick helps two different segmenters is that both are inverting a latent variable the corpus never labels. A unigram language model gives an explicit probability to each path, so its lattice can be sampled cleanly and the temperature \alpha gives a continuous dial from “uniform over the lattice” to “deterministic”. BPE has no probability model at all, only an ordered merge list, so BPE-dropout injects randomness procedurally instead: skipping a merge with probability p produces a shorter piece and therefore a longer, more character-like segmentation, and stacking many independent skips over a long word yields a wide distribution of segmentations. Both settings need a knob that is gentle: too much randomness pushes segmentation toward characters, inflating sequence length, wasting attention on re-learning spelling, and destroying the frequency statistics that made the vocabulary useful in the first place.

Mathematical Formulation:
P(\mathbf{x}) = \prod_{i=1}^{M} p(x_i)
P_{\alpha}(\mathbf{x} \mid X) \propto P(\mathbf{x})^{\alpha}
\mathcal{L}(\theta) = \mathbb{E}_{\mathbf{x}, \mathbf{y}}\left[\log P(\mathbf{y} \mid \mathbf{x}; \theta)\right]
P(Y \mid X) = \sum_{\mathbf{x}} P(\mathbf{x} \mid X)\, P(Y \mid \mathbf{x})
\hat{Y} = \arg\max_{Y} \frac{1}{k} \sum_{j=1}^{k} \log P(Y \mid \mathbf{x}_j)

Where:

  • X and Y are the raw source and target sentences, while \mathbf{x} = (x_1, \ldots, x_M) and \mathbf{y} are particular segmentations of them into vocabulary pieces.
  • p(x_i) is the unigram probability of piece x_i, estimated by EM when the SentencePiece unigram vocabulary is built, and M is the number of pieces on that path.
  • \alpha is the smoothing exponent of the sampling distribution: \alpha \to 0 gives a near-uniform draw over the l-best lattice paths and \alpha \to \infty collapses to the single Viterbi path, so deterministic tokenization is the limiting case.
  • The expectation in \mathcal{L}(\theta) is taken over \mathbf{x} \sim P_{\alpha}(\cdot \mid X) and \mathbf{y} \sim P_{\alpha}(\cdot \mid Y), approximated by one fresh sample per example per epoch rather than by an inner loop.
  • P(Y \mid X) is the true segmentation-marginalized translation probability that the training objective approximates; the sum over \mathbf{x} is intractable, which is exactly why sampling is used.
  • k is the number of source segmentations used in optional n-best decoding, where k = 1 with the Viterbi path is the standard, cheapest inference setting.
Two-panel line chart: left panel shows the entropy in bits of the segmentation sampling distribution decreasing from near-maximum to near zero as alpha grows from 0.02 to 3 for a three-path and a four-path lattice; right panel shows the expected number of pieces per word falling toward one over the same alpha range, both panels marking the default alpha near 0.2

Figure 2: The temperature \alpha controls exactly two things that matter. Left: the entropy of the sampling distribution, which is how much augmentation diversity the model receives per epoch. Right: the expected pieces per word, which is the sequence-length tax you pay for that diversity. Beyond roughly \alpha = 1.5 both collapse to the deterministic Viterbi behaviour and the method does nothing.

PropertyDeterministic BPE / unigramUnigram-LM samplingBPE-dropout
Randomness sourceNone; one path per sentence foreverDraw from the l-best lattice paths of a unigram LMIndependently skip each merge while applying the merge table
Knob and typical valueVocabulary size onlyl = 64, alpha near 0.1 to 0.2p = 0.1 on both sides, lower for high-resource pairs
Segmenter changesn/aNeeds a probabilistic unigram vocabulary, not a merge listNone; reuses an existing BPE model unchanged
Main costRare pieces stay under-trainedLattice sampling per example; longer average sequencesRe-merging per example; length inflation grows fast with p
InferenceSame path as trainingViterbi path, or average log-scores over k sampled sourcesStandard BPE with dropout disabled

Login to view more content


Log in to track your progress

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *