Document-Level and Context-Aware Translation › Terminology Consistency
Language AI HandbookAll chapters A pharmaceutical leaflet, a product help page, and a contract each give translators reasons to preserve specific wording. A project glossary lets reviewers check a drug name, a UI label, or a defined term against the requested rendering.
Two resources serve different purposes in a translation workflow:
- A translation memory (TM) stores previously translated source and target segments. A translation tool can retrieve those segments and offer their earlier wording as suggestions. memoQ 12.6 classifies 100% as exact, 95–99% as nearly exact, and 50–94% as fuzzy. It also distinguishes higher-scoring context matches. These thresholds belong to the tool’s scoring convention. Review a retrieved segment before reusing its wording.
- A glossary, or termbase, records term-level equivalents. A project glossary can require almacenamiento en la nube for “cloud storage” wherever the product feature appears. The entry records a term choice without prescribing the rest of the sentence.
CAT tools can offer both resources. memoQ, for example, supports term bases that record preferred renderings. A translation memory can suggest phrasing in context, while a termbase can specify which equivalent a project requires.
The consistency metric
Before fixing anything, we need to measure it. Suppose a document contains sentences , and a glossary maps each source term to a required target . For each glossary term that appears in the document, count how often each target variant is used in the output. Then define
Here contains the glossary terms that occur in , and counts the source occurrences of . The set contains the observed target variants, and counts source occurrences aligned to variant . Each source occurrence contributes at most one rendering. The toy scorer treats distinct surface strings as distinct variants. If your protocol pools spellings or inflections, define the classes before scoring. Check that each form is allowed in its local context before awarding term accuracy, or report contextual grammar separately if the score measures term identity alone. If all occurrences of a term are missing, its numerator is zero. When the document has no glossary occurrences, report the document score as unavailable. A score of 1 means every occurrence of each term falls into the same scored variant.
In plain terms, the inner fraction asks: for this term, what share of its occurrences use the most popular variant? If a term appears four times and three of those use the same rendering, the inner fraction is 0.75. The outer average then combines these shares across all glossary terms in the document. Terms that do not occur in the document are excluded, because including them would dilute the score with terms the translator never had a chance to get wrong. The metric is intentionally forgiving about which variant is chosen: it rewards internal consistency, not correctness. That is why it needs siblings.
This metric has two useful siblings:
- Term accuracy measures whether the chosen variant is the required one, . Consistency can be high while accuracy is low if the system consistently picks the wrong term.
- Term coverage measures whether the system produced any translation for the term at all, or dropped it. An entirely omitted term scores zero on all three metrics. Coverage shows that there were no aligned renderings to evaluate.
Report all three. A system that translates "cloud storage" as almacenamiento en la nube in every sentence has consistency 1.0 and accuracy 1.0. A system that always says nube has consistency 1.0 and accuracy 0.0. If half the source occurrences are translated correctly and half are missing, all three scores are 0.5 for that term. Each pattern points to a different bug in the pipeline, and a single aggregate score would hide the difference.
How constraints enter decoding
The most direct approach is to force the target to contain the required term. In its cleanest form, constrained decoding solves
Here is the set of completed target token sequences, is the source, and is optional document context. is the model distribution with parameters , and is the set of source terms in the glossary. The notation means that the tokens of the required target term occur contiguously in . If the model assigns positive probability to at least one feasible output, choose any feasible output with the highest probability. A limited beam can prune viable prefixes and miss the optimum.
The term can appear anywhere in the output. A hypothesis that has yet to start a term can still include it later, so the search needs to retain different paths through the requirements.
Ordinary Beam Search keeps up to hypotheses at each step. Grid beam search (Hokamp and Liu, 2017) keeps a separate beam for each number of constraint tokens already covered. If the required phrases contain model tokens in total, there are up to coverage levels, including zero. At output step , a hypothesis at coverage level has consumed exactly constraint tokens. A hypothesis can generate an ordinary token or start an unused phrase. Once it starts a phrase, it must continue emitting that phrase's tokens until it finishes. Starting or continuing a phrase increases by one. The search chooses the best-scoring retained hypothesis that ends with EOS and has covered all constraint tokens. If none survives, the search has found no valid output. A system with a fallback should report when it uses it.
This allocation can keep a lower-scoring prefix alive because it has made more progress on the required terms. With maximum output length , there are at most beams to update, each holding up to hypotheses. Runtime also depends on model scoring and how many candidate expansions the search considers. For a large glossary, constrain the terms that are mandatory for the current segment.
A fixed phrase may be a poor fit where the sentence calls for a different word form. Jon et al. (2021) give examples of this failure in morphologically rich languages. Check the required form in the completed sentence and send awkward cases for review.
The placeholder trick
An alternative that avoids modifying the decoder is the placeholder pipeline:
- Detect glossary terms in the source sentence.
- Replace each occurrence with a unique placeholder token.
- Translate the protected sentence with an ordinary NMT model.
- Replace each placeholder in the output with the required target term.
Use this pipeline with a text-only translation engine when its output preserves recognizable markers. Check the engine’s behavior with the markers you use.
- Tokenization. A tokenizer that emits one token per UTF-8 byte represents
⟦T0⟧with eight tokens. Match the decoded string during restoration and measure whether the engine preserves the markers you use. - Reordering. In step 4, restoring a term puts it wherever the placeholder landed. If the model moved the placeholder to the wrong position, the sentence can be ungrammatical even though the glossary form is correct.
- Morphology. A literal replacement cannot adjust the stored term to its surroundings. If the target text contains consultó dos followed by a marker, restoring the singular informe técnico gives consultó dos informe técnico. The context calls for the plural informes técnicos.
- Over-matching. A naive substring replacement for “cloud” will also match “cloudy”. Use word boundaries and try the longest alternative first when multiple terms match at the same position.
- Copy failures. Check the identity and count of every marker before restoration. Equal totals can hide a missing marker if the model duplicates another. The toy implementation below checks for exactly one copy of every expected marker and rejects unrecognized marker IDs in the reserved marker format. The toy implementation rejects literal source text in that format before inserting markers, so a source literal cannot pass for a marker lost in translation.
Run the pipeline sentence by sentence with the same glossary. Exact-form consistency from this mechanism requires detecting every occurrence, preserving its marker, and restoring the intended form. Detection recall and marker survival help locate failures. An engine can produce the desired term without the glossary: Dinu et al. (2019) observed this in their unconstrained baseline. When detection misses an occurrence, the wrapper has no marker to restore.
For one source occurrence, the chance of detection and marker survival is detection recall times the chance that an inserted marker survives. The second probability is conditional on detection and insertion. The product measures those two stages. The toy restorer also checks the rest of the segment, so it can reject a segment even if this occurrence’s marker survived.
PythonIn [3]Expand
import numpy as np
detection_recall = np.linspace(0.70, 1.00, 7)
placeholder_survival = np.linspace(0.80, 1.00, 7)
protection_success = np.outer(detection_recall, placeholder_survival)
survival_step = placeholder_survival[1] - placeholder_survival[0]
recall_step = detection_recall[1] - detection_recall[0]
protection_extent = (
placeholder_survival[0] - survival_step / 2,
placeholder_survival[-1] + survival_step / 2,
detection_recall[0] - recall_step / 2,
detection_recall[-1] + recall_step / 2,
)VisualizationOut [4]Expand

Retrieval-augmented translation
A third family retrieves examples from a datastore. kNN-MT (Khandelwal et al., 2021) builds a token-level store from paired source and target examples. An isolated pair can supply a short translation example. To represent its use in a longer sentence, the datastore needs the paired sentence and target prefix. An entry pairs the decoder representation of the source and a reference target prefix with the next reference token . At inference, the current decoder representation retrieves neighboring keys:
where lists the retrieved key-token pairs and is one when the tokens match and zero otherwise. The inverse temperature is for . With at least one neighbor, divide by the sum of their exponential weights to make the probabilities sum to one. If retrieval returns no usable neighbors, use the base model alone for that step. Otherwise, mix the two distributions:
You can update the datastore without retraining. With a positive retrieval weight, a token in a client-approved term becomes more likely when the retrieval distribution assigns it more probability than the base model does. Search adds inference latency. The weight sets the share of probability mass from retrieval. Within the retrieval distribution, a larger inverse temperature concentrates more weight on closer neighbors when their distances differ.
In Gu et al. (2018), a translation model conditions on bilingual examples retrieved by source-side similarity. The retrieved targets provide wording the model can reuse when it fits the current source.
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!