Abstract
Current machine translation (MT) systems perform well in the domains on which they were trained, but adaptation to unseen domains remains a challenge. Rather than fine-tuning on domain data or modifying the architecture for training, an alternative approach exploits large language models (LLMs), which are performant across NLP tasks especially when presented with in-context examples. We focus on adapting a pre-trained LLM to a domain at inference through in-context example selection. For MT, examples are usually randomly selected from a development set. Some more recent methods though select using the more intuitive basis of test source similarity. We employ topic models to select examples based on abstract semantic relationships below the level of a domain. We test the relevance of these statistical models and use them to select informative examples even for out-of-domain inputs, experimenting on 7 diverse domains and 11 language pairs of differing resourcedness. Our method outperforms baselines on challenging multilingual out-of-domain tests, though it does not match performance with strong baselines for the in-language setting. We find that adding few-shot examples and related keywords consistently improves translation quality, that example diversity must be balanced with source similarity, and that our pipeline is overly restrictive for example selection when a targeted development set is available.
Introduction
Neural Machine Translation (NMT) has seen significant progress, yet domain adaptation remains a persistent hurdle. Models trained on general corpora often struggle with the specialized terminology and stylistic nuances of domains like medicine, law, or technical documentation. While Large Language Models (LLMs) demonstrate remarkable zero-shot and few-shot translation capabilities, their performance is highly sensitive to the choice of in-context examples. Traditional selection methods—such as random sampling or simple n-gram similarity (BM25)—often fail to capture the deeper semantic context required for high-quality domain-specific translation.
Methodology: Topic-Guided Prompting
This research proposes a novel pipeline using BERTopic to guide the selection of in-context examples for Llama-2-13B. By identifying abstract semantic relationships that exist below the broad "domain" level but above surface-level word overlap, the system can provide the LLM with more relevant context.
The prompting strategy consists of three layers:
- Domain Labels: Explicitly stating the text's domain (e.g., "EU biomedical texts").
- Related Keywords (Keywords-10): Including the top 10 keywords from the predicted topic. These serve as a "stochastic proxy for a bilingual lexicon," helping the model narrow down terminology.
- Topic-Guided Few-shot: Providing the $n$ most representative sentence pairs from the identified topic as examples.
Experimental Results
The method was evaluated across 7 diverse domains (EMEA, JRC, KDE4, OpenSubtitles, QED, Tanzil, and TED) and 11 language pairs. The results demonstrate that topic-guided selection consistently improves translation quality over zero-shot baselines.
Key findings include:
- Significant Quality Gains: Using 3-shot topic-guided examples improved COMET scores by up to 6 points compared to the zero-shot "Base" prompt.
- The Power of Keywords: Simply adding 10 topic-related keywords provided a 2-4 point boost, suggesting that even lightweight lexical hints can significantly aid the LLM.
- Out-of-Domain Robustness: In scenarios where the test domain was "unseen" during the topic model's training, the topic-guided approach outperformed standard retrieval baselines like BM25 and embedding similarity.
Discussion and Limitations
A critical insight from the study is the diversity-similarity trade-off. While selecting examples highly similar to the source is intuitive, being overly restrictive can be counterproductive. If examples are too similar, the model may fail to grasp the broader translation patterns needed for the task.
Despite these improvements, a performance gap remains between few-shot LLMs and specialized state-of-the-art models like NLLB-1.3B. Furthermore, the study's focus on English-centric pairs and the Llama-2 architecture leaves room for future exploration into low-resource language pairs and other model families.
Conclusion
Topic-guided example selection offers a powerful, inference-time method for adapting LLMs to specialized domains without the need for costly fine-tuning. By leveraging abstract semantic relationships, this approach provides the model with the necessary lexical and contextual cues to produce higher-quality translations in challenging, domain-specific environments.
Summary updated