Neural Machine Translation › Data, Preprocessing, and Subword Vocabulary
Language AI HandbookAll chapters Before changing model size, audit the bitext for language, domain, and alignment quality. Compare corpus and architecture changes separately if you want to attribute the result to one of them.
Hold the architecture fixed while testing corpus size or filtering. Hold the corpus fixed while testing architecture. Report the training and evaluation domains in both comparisons.
Parallel corpora
Examples of parallel data sources include:
- Curated documents: Europarl contains European Parliament proceedings. The UN Parallel Corpus collects official United Nations documents.
- Mined bitext: ParaCrawl, CCMatrix, and WikiMatrix extract candidate sentence pairs from existing text. Screening can remove mismatched pairs and other noise.
- Human-translated seed data: NLLB-Seed pairs Wikipedia-domain sentences with professional translations.
- Domain corpora: The OPUS catalogue lists parallel corpora in multiple domains. Select material that matches the task and measure performance on a held-out sample from that setting.
- Synthetic bitext: Back-translate target-side text when suitable parallel examples are limited. The next section shows how.
Cleaning
Audit the candidate pairs and choose filters based on the errors you observe.
- Language identification on both sides. If the English side is French, the pair is mislabeled. See Language Identification.
- Length ratio filtering. An example flag is outside after tokenization, with a positive source length. Pilot the threshold in a specific direction and inspect flagged examples for valid but asymmetric translations.
- Exact and near deduplication. Repeated pairs appear repeatedly in a per-example sum. If they are unintended, inspect and deduplicate them. See Deduplication and MinHash.
- Source–target similarity heuristics. Compare character overlap on sample pairs you have verified before making it a rejection criterion. A translation written in a different script can have little overlap.
- Model-based filtering. Score both sides with a bilingual model or quality estimator. Inspect how the score separates plausible pairs from known mismatches before setting a threshold.
We go deeper on mining and quality control in the next chapter, Parallel Data Mining and Quality Control.
Back-translation
Sennrich, Haddow, and Birch (2016) generated synthetic source text from target-language monolingual data. In this setup:
- Train a reverse model on the available parallel data.
- Select monolingual target-side sentences in a domain you want the forward model to handle.
- Translate it into the source language with the reverse model, producing synthetic pairs .
- Add the synthetic pairs to the training data for the forward model and retrain.
The target side is the original monolingual text. The source is the reverse model's output. Edunov et al. (2018) compared ways of generating that synthetic source, including sampling and beam search. Caswell et al. (2019) tested adding a tag to distinguish synthetic pairs during forward training.
Inspect the synthetic source for missing content and mistranslated names. Keep trustworthy parallel data in the mixture and compare results on real source inputs when testing whether the added data helps.
Subword tokenization
A closed word vocabulary needs an unknown-token rule for words it does not contain. A subword tokenizer can represent many unseen words as sequences of pieces. SentencePiece can train and tokenize from raw text without a separate word pretokenizer. Kudo and Richardson (2018).
Three decisions dominate subword setup for MT:
- Shared vs. separate vocabularies. A shared vocabulary allows matching subwords to share representations if the weights are tied. Compare it with separate vocabularies by measuring held-out translation quality, fragmentation, and coverage for each language.
- Vocabulary size. Compare candidate sizes at a fixed training and evaluation budget. If common spans split into many pieces, record the extra tokens. If you add rare pieces, inspect how often the training data contains them.
- Fertility. Here this means the number of subword tokens per word under a specified tokenizer and word segmentation. If two versions of comparable text use different token counts, the longer version consumes more of a fixed token budget. Report the tokenizer and the per-language distributions. See Multilingual Tokenization and Vocabulary Allocation.
Batching and masking
Two details that cause real bugs if you get them wrong:
- Batch by token count when sequence length varies. For example, a batch of 32 eight-token sentences has 256 tokens before adding padding or special tokens. Sort or bucket similar lengths and use a fixed token budget when you need to control batch size.
- Padding. If PAD is a batching symbol, exclude its source positions from attention keys and its target labels from the loss. In the implementation below, a key padding mask and
ignore_index=PAD_IDapply those two rules.
The example's closed vocabulary contains 13 ordinary word types on each side. Four reserved symbols bring each vocabulary to 17 entries. Word-level tokenization is sufficient for that fixture.
Comments
Add to the conversation
A question, a correction, or an example from your own work.
No comments yet. Be the first to share your thoughts!