In-context Learning as Maintaining Coherency: A Study of On-the-fly Machine Translation Using Large Language Models

Suzanna Sia, Kevin DuharXiv 2023 · OpenReview

Abstract

The phenomena of in-context learning has typically been thought of as "learning from examples". In this work which focuses on Machine Translation, we present a perspective of in-context learning as the desired generation task maintaining coherency with its context, i.e., the prompt examples. We first investigate randomly sampled prompts across 4 domains, and find that translation performance improves when shown in-domain prompts. Next, we investigate coherency for the in-domain setting, which uses prompt examples from a moving window. We study this with respect to other factors that have previously been identified in the literature such as length, surface similarity and sentence embedding similarity. Our results across 3 models (GPTNeo2.7B, Bloom3B, XGLM2.9B), and three translation directions (en→{pt, de, fr}) suggest that the long-term coherency of the prompts and the test sentence is a good indicator of downstream translation performance. In doing so, we demonstrate the efficacy of In-context Machine Translation for on-the-fly adaptation.

Introduction

Large Language Models (LLMs) have demonstrated a remarkable ability to perform Machine Translation (MT) "on-the-fly" through in-context learning (ICL). By providing a few examples within a prompt, these models can adapt to specific domains or styles without explicit fine-tuning. However, the underlying mechanisms of ICL remain a subject of debate. While many researchers focus on similarity-based retrieval—selecting examples that semantically or lexically resemble the target sentence—this study proposes an alternative perspective: ICL as a process of maintaining coherency with the prompt.

Methodology

We reframed ICL as a task of linguistic consistency, where the model performs best when the prompt establishes a coherent context. Our framework evaluates several factors that influence translation quality, including domain matching, local discourse flow, and surface similarity.

Conceptual framework of in-context learning as maintaining coherency.

We compared four primary prompt selection strategies across three autoregressive models (GPTNeo2.7B, Bloom3B, and XGLM2.9B):

  1. Global Coherence (Domain Matching): Evaluating if prompts from the same domain (e.g., Medical vs. Social Media) improve performance.
  2. Local Coherence (Moving Window): Utilizing immediately preceding gold translations from a document as the prompt.
  3. Similarity-based Retrieval: Using baselines such as BM25 (word overlap) and Nearest Neighbor (semantic similarity).
  4. Length Control: Introducing a "Translation Budget" to account for the impact of total word count on performance.

Experimental Setup

The study utilized four distinct datasets to test adaptation across various linguistic styles: WMT19 Biomedical (MED) for formal language, MTNT for noisy social media text, FLORES for Wikipedia-based data, and Multitarget TED Talks for document-level translation.

Key Insights and Results

Coherency vs. Similarity

In document-level translation, the moving window approach—which prioritizes local coherence—consistently outperformed sophisticated similarity-based retrieval methods. Gains of up to 2.6 BLEU points were observed, suggesting that the natural flow of a document provides more effective cues for the LLM than isolated similar sentences. Interestingly, shuffling sentences within a coherent moving window did not significantly degrade performance, indicating that the model benefits from the content of the recent discourse rather than strict sequentiality.

The Perplexity Connection

A critical finding is the relationship between prompt coherency and model perplexity. Matching the domain of the prompt to the test sentence significantly lowers the model's conditional source sentence perplexity. This lower "surprise" factor correlates strongly with improved translation quality.

Correlation between translation quality (BLEU) and source perplexity.

Confounding Factors

The research highlights that length is a significant confounder in ICL studies. Longer prompt examples generally lead to higher BLEU scores. By controlling for word count, we demonstrated that previous studies may have over-attributed success to retrieval algorithms rather than context volume. Furthermore, while prompts usually provide "positive interference," poor prompt selection can lead to "negative interference," degrading the model's inherent translation ability.

Conclusion

Our findings suggest that maintaining coherency—both global (domain) and local (discourse)—is a primary driver of in-context learning performance in MT. While LLMs possess inherent translation capabilities, coherent prompts provide guidance that improves accuracy. Future work will explore these effects in larger "frontier" models and investigate the generalizability of the coherency framework to other natural language tasks.

Summary updated

Abstract

The phenomena of in-context learning has typically been thought of as "learning from examples". In this work which focuses on Machine Translation, we present a perspective of in-context learning as the desired generation task maintaining coherency with its context, i.e., the prompt examples. We first investigate randomly sampled prompts across 4 domains, and find that translation performance improves when shown in-domain prompts. Next, we investigate coherency for the in-domain setting, which uses prompt examples from a moving window. We study this with respect to other factors that have previously been identified in the literature such as length, surface similarity and sentence embedding similarity. Our results across 3 models (GPTNeo2.7B, Bloom3B, XGLM2.9B), and three translation directions (\texttt{en}$\rightarrow$\{\texttt{pt, de, fr}\}) suggest that the long-term coherency of the prompts and the test sentence is a good indicator of downstream translation performance. In doing so, we demonstrate the efficacy of In-context Machine Translation for on-the-fly adaptation.
BibTeX
@misc{sia2023context,
  author = {Suzanna Sia and Kevin Duh},
  title = {{In-context Learning as Maintaining Coherency: A Study of On-the-fly Machine Translation Using Large Language Models}},
  year = {2023},
  eprint = {2305.03573},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2305.03573},
}
Figure