Document-Level and Context-Aware Translation › Architectures for Context-Aware Translation

Michael BrenndoerferNovember 25, 20265 min read
Language AI HandbookAll chapters
Part 27 of 67Machine Translation and Speech Translation
Chapter 195Document-Level and Context-Aware Translation › Architectures for Context-Aware Translation
Reading section 5 of 13 · Architectures for Context-Aware Translation · 5 minSection 5 of 13 · 5 min

Section 5 of 13 · 5 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

We now turn from phenomena to mechanisms. How do you condition an NMT model on document context? The answer depends on what kind of context you need and what kind of model you have. The mechanisms below are not mutually exclusive, and a production system may combine several of them.

Context concatenation

Prepend up to a fixed number of preceding source sentences to the current one. Here jj is the current sentence index and kk is the number of preceding sentences available within that limit:

x′=[xj−k;…;xj−1;xj],\mathbf{x}' = [\mathbf{x}_{j-k}; \ldots; \mathbf{x}_{j-1}; \mathbf{x}_j],

and translate x′\mathbf{x}' as a single input. In the concatenate-both-sides design, the model emits target segment boundaries. When the expected boundaries appear in the right places, the segment after the last boundary translates the current sentence. Missing or misplaced boundaries can mix contextual and current text.

Decide which of the concatenated segments you want to translate. If you want only the current sentence, check that the output excludes the earlier ones. Concatenation lengthens the input. Its token count is the sum of the sentence token counts, plus any separator tokens. With equal-length sentences and no separators, the input has k+1k+1 times as many positions as the current sentence alone. Extra context can help or hurt depending on which sentences you include.

A separator gives a model trained on concatenated input a cue about where the context ends and the current sentence starts. Ordinary positional embeddings encode token positions across that combined input. Attention can still cross the boundary, and the separator increases the input length by its own token count.

Multi-encoder models

A more principled architecture uses separate encoders:

Hcur=Enccur(xj),Hctx=Encctx(C<j),\mathbf{H}^{\text{cur}} = \text{Enc}_{\text{cur}}(\mathbf{x}_j), \qquad \mathbf{H}^{\text{ctx}} = \text{Enc}_{\text{ctx}}(C_{<j}),

Here C<jC_{<j} is the auxiliary input, such as preceding sentences or retrieved examples. One design concatenates [Hctx;Hcur][\mathbf{H}^{\text{ctx}}; \mathbf{H}^{\text{cur}}] along the position axis for decoder cross-attention. The two sequences need a shared feature width, so project them to a common width if necessary. A different design can calculate a context representation separately and learn how to mix it with the current-sentence representation.

The two encoders can have different capacities. When the current-sentence encoder matches an existing sentence-level encoder’s architecture, you can initialize it with those weights. To train a context encoder on aligned neighboring segments, you need examples that preserve those neighborhoods. Other approaches have different data requirements. DocRepair, for example, trains a second-pass repair model using target-language monolingual documents.

Hierarchical and cache models

A hierarchical model can give the decoder both a current sentence encoding and context summarized at the sentence level. Miculicich et al. (2018) attend over words within contextual sentences, then over the sentence representations. With a recurrent or pooled sentence-level summary, the document layer can skip attention across all pairs of original document tokens. The cost depends on the word-level encoder and the design of the document layer.

A related idea is a cache or memory that persists across segments. Early work on context-aware NMT used a cache of recent target-side hidden states, so the model could use information from recently generated output. This resembles the mechanisms in Recurrent Memory. A decoder can read a bounded cache without attending to the full document. What it learns about a recent term depends on what those retained states encode.

A cache with a fixed capacity can evict older evidence. It might still contain the recent translation of "cloud storage" and supply a cue for the next mention. If it has evicted the only evidence for an earlier antecedent, the decoder cannot retrieve that evidence from the cache.

LLM-scale context

When the whole document fits within a model’s context window, you can include it in a prompt with the glossary, prior decisions, and instructions that identify the segment to translate. Leave enough room for the model’s output. Check the translation against the glossary and style sheet.

The tradeoffs are different but not absent:

  • Cost and latency. Compare measured time to first token, total completion time, and input-token charges for the same documents under the serving configurations you plan to use. For interactive translation, test whether a shorter window meets the quality target.
  • Position in long prompts. Liu et al. (2024) found that position affected how well models used relevant information in multi-document question answering and key-value retrieval. For translation, test whether moving a relevant sentence or a glossary entry changes the output in your setup.
  • Copying and segment boundaries. Compare the output with the current input. Flag wording copied from a previous translation if it refers to a different source segment.
  • Segment boundaries. Compare translating the whole document with translating one segment at a time using a running glossary and a summary of prior choices. The segment-based layout gives you one output per requested segment to check.

A practical pattern is a hybrid: a long-context LLM translates a window of segments, with an explicit glossary block and a short "style sheet" built from earlier segments. The window limits how much text the model sees at once. The style sheet carries earlier decisions forward as guidance for later segments. The style sheet might record the chosen rendering of key terms, the address form, and a few examples of the desired tone. It is updated as the translation progresses, so it accumulates document-level knowledge without requiring the model to attend over the full document.

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