Abstract
Nearest neighbor machine translation ($k$NN-MT), which interpolates target token probabilities with estimates derived from additional examples, has achieved significant improvements and attracted extensive interest in recent years. However, existing research does not explicitly consider the source context when retrieving similar examples, potentially leading to suboptimal performance. To address this, we comprehensively revisit the role of source context and propose a simple and effective method for improving neural machine translation via source context enhancement, demonstrating its crucial role in both retrieving superior examples and determining more suitable interpolation coefficients. Furthermore, we reveal that the probability estimation can be further optimized by incorporating a source-aware distance calibration module. Comprehensive experiments show that our proposed approach can be seamlessly integrated with representative $k$NN-MT baselines, resulting in substantial improvements over these strong baselines across a number of settings and domains. Remarkably, these improvements can reach up to 1.6 BLEU points.
Introduction
Neural Machine Translation (NMT) has been significantly boosted by $k$NN-MT, a retrieval-augmented approach. At each step of generating a translation, $k$NN-MT searches a massive "datastore" of previously seen examples for the most similar decoder states to help predict the next token. However, standard $k$NN-MT relies almost entirely on target-side representations. This paper observes that if the source sentence of a retrieved neighbor is semantically distant from the current input, that neighbor is much less likely to provide the correct token—even if the decoder states appear similar. Essentially, ignoring the source context introduces significant noise into the retrieval process.
Methodology: Source-Aware $k$NN-MT
We propose three key enhancements to make the $k$NN-MT pipeline "source-aware":
- Source-Enhanced Retrieval: Instead of searching only the global datastore, the model identifies a small set of source sentences in the training data similar to the current input to build a dynamic auxiliary datastore. Neighbors are then retrieved from both the global and auxiliary stores.
- Source-Aware Calibration: When calculating the proximity of a neighbor, the model uses a calibrated distance metric that combines target-side decoder state distance with the distance between the input sentence and the neighbor's source sentence.
- Source-Augmented Interpolation: We utilize a lightweight "Meta-$k$ Network" to adaptively calculate the interpolation weight ($\lambda$) between the base NMT model and the $k$NN suggestions, based on source distances, target distances, and neighborhood density.
Experimental Setup
The approach was evaluated across several diverse settings:
- Domain Adaptation: IT, Medical, Koran, and Law datasets (German $\rightarrow$ English).
- In-Domain Translation: The JRC-Acquis dataset (English, German, Spanish).
- Large-Scale: The Subtitles dataset, containing 14 million parallel sentence pairs.
- Generalization: Dialogue Generation (DG) and Question Generation (QG) tasks.
Key Results and Insights
Our method consistently outperformed strong baselines, achieving improvements of up to 1.60 BLEU points in the Medical domain and 1.57 points in the IT domain.
Robustness and Efficiency
A significant advantage of this approach is its robustness to the number of neighbors ($k$). While standard $k$NN-MT performance often degrades as $k$ increases due to noise, our source-aware calibration filters irrelevant neighbors, allowing the model to maintain high performance even at $k=64$. Furthermore, because the auxiliary datastore is 4-5 orders of magnitude smaller than the main one, the added computational latency is negligible, ensuring the method remains practical for real-world deployment.
Conclusion
By explicitly incorporating source context into retrieval, calibration, and interpolation, we significantly enhance the performance and robustness of $k$NN-MT. Our findings suggest that source-side signals are vital "hidden gems" that standard target-based retrievers miss. Future work will explore applying these source-aware principles to other retrieval-augmented generation tasks, such as code generation and document summarization.
Summary updated