NeurIPS 2026Coming to NeurIPS?Explore papers, orals & directions

Analyzing Context Contributions in LLM-based Machine Translation

Emmanouil Zaranis, Nuno M. Guerreiro, André F. T. Martins

TL;DR

This paper investigates how Large Language Models (LLMs) allocate attention across different parts of their prompt during machine translation. Using a token-attribution method, the authors uncover a striking positional bias where early few-shot examples dominate the generation process, and demonstrate that tracking anomalous context contributions can accurately flag translation hallucinations.

What Problem Does This Paper Address?

While Large Language Models (LLMs) have become state-of-the-art tools for machine translation (MT) via in-context learning (ICL), they largely operate as black boxes. Traditional encoder-decoder translation models have well-studied interpretability mechanisms, but decoder-only LLMs process the entire history—few-shot examples, instructions, source text, and previously generated tokens—in a single causal sequence.

We currently lack a fine-grained understanding of how LLMs weigh these different context components. Do they care more about the source or target side of a few-shot example? Does the order of examples matter systematically? How does fine-tuning on parallel data alter how a model navigates its prompt? This paper addresses these questions by peering inside the transformer layers to map information flow during translation.

Methods

The authors employ ALTI (Aggregation of Layer-Wise Token-to-Token Interactions), an input attribution method. Rather than relying on raw attention weights—which can be misleading due to residual connections and layer normalization—ALTI models the transformer as a directed acyclic graph to calculate how much information actually flows from an input token to an output token across all layers.

To make these insights interpretable at a macro level, the authors aggregate token-to-token attributions into part-level contributions. This allows them to isolate and measure the total influence of specific prompt segments: the source and target text of each individual few-shot example, the actual test source sentence, and the target prefix (previously generated tokens).

Datasets

The study evaluates models using the publicly available WMT22 test sets across four language pairs:

  • German to English (de-en)
  • English to German (en-de)
  • Russian to English (ru-en)
  • English to Russian (en-ru)

Key Insights and Ideas

  • Few-Shot Source > Target: Across all language pairs and models, the source side of a few-shot example contributes significantly more to the final translation than its corresponding target translation.
  • The "Staircase" Positional Bias: The authors observed a strict, monotonic positional bias. The very first few-shot example provided in the prompt consistently exerts the highest influence, with subsequent examples showing a steady, step-down decline in contribution.
  • Content Type Matters, Not Just Position: To test if the positional bias was purely mechanical, the authors placed a task description (e.g., "Translate the following text...") at the absolute beginning of the prompt. Interestingly, the task description received minimal contribution, proving that the bias is sensitive to the structural nature of the content (examples vs. instructions).
  • Fine-Tuning Flattens the Bias: Base models (like LLaMA-2 7B) rely heavily on early few-shot examples to figure out the task on the fly. Conversely, models continuously pretrained or fine-tuned on parallel translation data (like TOWER) rely much less on few-shot demonstrations, significantly flattening the positional staircase.
  • Catching Hallucinations Early: When a model experiences a "fully-detached hallucination"—such as completely ignoring the test source text and instead copying a few-shot example—its internal attribution profile flips dramatically, showing near-zero contribution from the test source.

Key Results

The paper clearly visualizes the part-level contributions and the staircase effect across LLaMA-2, TOWER-Mono, TOWER, and TOWERInstruct models:

Figure 2: Illustration of context’s part-level contributions to the translated sequence, for all the examined models.

By tracking instances where the test source-text attribution drops anomalously low, the authors evaluated its predictive power for catching hallucinations. Using the Area Under the ROC Curve (AUROC) metric, this approach achieved an impressive 97.3 for TOWER on German-to-English and 88.7 on English-to-Russian translation. However, for the base LLaMA-2 model, the AUROC was only 52.3, because its hallucinations typically manifest as random text rather than clean copies of prompt examples.

Limitations and Future Work

  • Compute Constraints: Due to the high GPU memory requirements of calculating layer-wise token attributions, the study was restricted to 7B parameter models and filtered out samples with total context lengths exceeding 400 tokens. It remains an open question whether these dynamics scale identically to 70B+ models.
  • Model Homogeneity: The analysis focused entirely on LLaMA-based architectures (LLaMA-2 and TOWER). Exploring whether these context utilization patterns and positional biases generalize to other model families (such as Mistral, Gemma, or proprietary models) is a crucial next step for the field.

Summary updated

BibTeX
@inproceedings{zaranis2024analyzing,
  author = {Emmanouil Zaranis and Nuno M. Guerreiro and André F. T. Martins},
  title = {{Analyzing Context Contributions in LLM-based Machine Translation}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2024},
  doi = {10.18653/v1/2024.findings-emnlp.876},
}
Figure