Document-Level and Context-Aware Translation › Terminology Consistency

Michael BrenndoerferNovember 25, 202611 min read
Language AI HandbookAll chapters
Part 27 of 67Machine Translation and Speech Translation
Chapter 195Document-Level and Context-Aware Translation › Terminology Consistency
Reading section 3 of 13 · Terminology Consistency · 11 minSection 3 of 13 · 11 min

Section 3 of 13 · 11 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

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 DD contains sentences s1,…,sns_1, \ldots, s_n, and a glossary G\mathcal{G} maps each source term tt to a required target τ(t)\tau(t). For each glossary term that appears in the document, count how often each target variant is used in the output. Then define

Cons(D)=1∣GD∣∑t∈GDmax⁡({0}∪{nt,v:v∈Vt})Nt,\text{Cons}(D) = \frac{1}{|\mathcal{G}_D|} \sum_{t \in \mathcal{G}_D} \frac{\max\bigl(\{0\} \cup \{n_{t,v} : v \in \mathcal{V}_t\}\bigr)}{N_t},

Here GD\mathcal{G}_D contains the glossary terms that occur in DD, and NtN_t counts the source occurrences of tt. The set Vt\mathcal{V}_t contains the observed target variants, and nt,vn_{t,v} counts source occurrences aligned to variant vv. 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, τ(t)\tau(t). 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

y⋆∈arg⁡max⁡y∈Y  log⁡Pθ(y∣x,C)subject to∀ t∈dom⁡(G)∩terms(x):  τ(t)∈y.\mathbf{y}^{\star} \in \arg\max_{\mathbf{y} \in \mathcal{Y}} \; \log P_\theta(\mathbf{y} \mid \mathbf{x}, C) \quad \text{subject to} \quad \forall\, t \in \operatorname{dom}(\mathcal{G}) \cap \text{terms}(\mathbf{x}): \; \tau(t) \in \mathbf{y}.

Here Y\mathcal{Y} is the set of completed target token sequences, x\mathbf{x} is the source, and CC is optional document context. PθP_\theta is the model distribution with parameters θ\theta, and dom⁡(G)\operatorname{dom}(\mathcal{G}) is the set of source terms in the glossary. The notation τ(t)∈y\tau(t) \in \mathbf{y} means that the tokens of the required target term occur contiguously in y\mathbf{y}. 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 BB 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 MM model tokens in total, there are up to M+1M+1 coverage levels, including zero. At output step jj, a hypothesis at coverage level cc has consumed exactly cc 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 cc by one. The search chooses the best-scoring retained hypothesis that ends with EOS and has covered all MM 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 LL, there are at most L(M+1)L(M+1) beams to update, each holding up to BB 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:

  1. Detect glossary terms in the source sentence.
  2. Replace each occurrence with a unique placeholder token.
  3. Translate the protected sentence with an ordinary NMT model.
  4. 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]
CollapseExpand
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]
CollapseExpand
Heatmap of the joint probability of detection and marker survival for one occurrence.
Probability that one glossary occurrence is detected and its marker survives. Each cell multiplies detection recall by marker survival conditional on insertion. The chart stops before the segment-level restoration checks.

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 kjk_j of the source and a reference target prefix with the next reference token vjv_j. At inference, the current decoder representation st\mathbf{s}_t retrieves neighboring keys:

PkNN(yt∣st)∝∑(kj,vj)∈N(st)1[vj=yt] exp⁡(−β∥st−kj∥2),P_{\text{kNN}}(y_t \mid \mathbf{s}_t) \propto \sum_{(k_j, v_j) \in \mathcal{N}(\mathbf{s}_t)} \mathbb{1}[v_j = y_t] \, \exp(-\beta \lVert \mathbf{s}_t - k_j \rVert^2),

where N(st)\mathcal{N}(\mathbf{s}_t) lists the retrieved key-token pairs and 1[vj=yt]\mathbb{1}[v_j=y_t] is one when the tokens match and zero otherwise. The inverse temperature is β=1/T\beta=1/T for T>0T>0. 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:

P(yt)=λ PkNN(yt∣st)+(1−λ) Pθ(yt∣y<t,x).P(y_t) = \lambda \, P_{\text{kNN}}(y_t \mid \mathbf{s}_t) + (1 - \lambda) \, P_\theta(y_t \mid y_{<t}, \mathbf{x}).

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 λ∈[0,1]\lambda\in[0,1] sets the share of probability mass from retrieval. Within the retrieval distribution, a larger inverse temperature β\beta 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!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy