Introduction
Large Language Models (LLMs) have redefined the state-of-the-art in machine translation through In-Context Learning (ICL). By providing a few examples within a prompt, these models can perform high-quality translations even for languages they were not explicitly optimized for. However, the internal mechanics of how LLMs prioritize different parts of a prompt—such as the source text versus the few-shot examples—have remained largely opaque. This research investigates the "information flow" within LLMs to understand how context influences translation and how these internal signals can predict model failure.
Methodology: Beyond Raw Attention
To move beyond the limitations of raw attention weights, which can often be noisy or misleading, the authors utilize ALTI (Aggregation of Layer-Wise Token-to-Token Interactions). ALTI treats the transformer model as a directed acyclic graph, tracking how information is mixed across all layers. This allows for a precise quantification of how much each input token contributes to the generation of each output token.
For clarity, the researchers aggregate these token-level scores into distinct functional "parts":
- Few-shot Examples: Divided into their respective source and target components.
- Source Text: The actual text currently being translated.
- Target Prefix: The tokens generated so far in the current translation.
The study evaluates the general-purpose LLaMA-2 7B and the TOWER family, which consists of models specifically fine-tuned for translation tasks. Experiments were conducted using the WMT22 test sets for English $\leftrightarrow$ German and English $\leftrightarrow$ Russian.
Key Findings on Contextual Influence
The Positional Bias of Examples
A primary discovery of this research is a distinct "stair-like" positional bias. In LLaMA-2, the first few-shot example provided in a prompt consistently exerts the highest influence on the output, with subsequent examples contributing progressively less. In fact, in over 95% of LLaMA-2 samples, the first example was the dominant contributor. Interestingly, this bias is specific to the demonstrations themselves; adding a task description at the beginning of the prompt does not diminish the influence of the first example, suggesting the model prioritizes the initial task demonstration above all else.
Source vs. Target Contribution
When analyzing the few-shot examples, the model relies more heavily on the source side of the example than the target side. This indicates that the model uses these examples primarily to understand the domain, style, and linguistic context of the input, rather than simply treating them as templates for the output format.
The Impact of Fine-Tuning
The research highlights a significant difference between base models and fine-tuned models. TOWER models, which have undergone continued pre-training and fine-tuning on parallel translation data, rely significantly less on the few-shot examples than LLaMA-2. Because these models have already "learned" the translation task during training, they require less "on-the-fly" instruction from the prompt.
Detecting Hallucinations via Attribution
One of the most practical applications of this research is in the detection of hallucinations. The authors found that when a model produces a translation unrelated to the source text, it is almost always accompanied by a specific internal signature: a sudden drop in attribution to the source text and a corresponding spike in attribution to a specific few-shot example. In these cases, the model essentially stops translating and begins copying the prompt.
Using "low source contribution" as a metric for hallucination detection proved remarkably effective. For the TOWER model on German-to-English translation, this method achieved an AUROC of 97.3, suggesting that internal attribution scores can serve as a highly reliable "smoke alarm" for quality estimation without requiring a reference translation.
Conclusion and Future Directions
This study provides a new lens through which to view in-context learning in LLMs. By revealing the positional bias of examples and the relationship between attribution and translation quality, it opens several avenues for future work:
- Prompt Engineering: Given the dominance of the first example, researchers can investigate if placing the most semantically relevant example in the first slot improves performance.
- Scaling: Future studies should determine if this positional bias persists or diminishes in larger models like Llama-3 70B.
- Architectural Universality: It remains to be seen if these patterns are unique to LLaMA-based models or are a fundamental characteristic of the transformer architecture across different model families.
Summary updated