Abstract
k-Nearest Neighbor Machine Translation (kNN-MT) has emerged as a powerful semi-parametric method for domain adaptation, allowing models to leverage external datastores without retraining. However, the computational overhead of performing a vector search for every generated token makes vanilla kNN-MT significantly slower than standard neural machine translation (NMT). This paper presents a chunk-based approach that retrieves sequences of tokens and utilizes a local cache to minimize global datastore lookups. Our method achieves up to a 4x speedup over vanilla kNN-MT while maintaining high translation quality, bridging the gap between performance and practical efficiency.
Introduction: The Bottleneck of Semi-Parametric NMT
Standard Neural Machine Translation models are fully-parametric, with their knowledge entirely contained within fixed weights. While effective, these models often struggle with domain shift—such as a general-purpose model translating specialized medical or legal texts. To address this, kNN-MT was introduced as a semi-parametric alternative that augments the base NMT model with a "cheat sheet" or datastore of previously translated examples.
Despite its benefits in translation quality, vanilla kNN-MT suffers from a severe efficiency bottleneck. Because it performs a complex k-nearest neighbor search for every single token produced, it is typically eight times slower than a standard NMT model. This research proposes a "chunk-based" strategy to alleviate this bottleneck, making semi-parametric adaptation viable for real-world applications.
Methodology: Chunking and Caching
The core innovation of this work is the transition from token-by-token retrieval to a chunk-based retrieval strategy. This approach is built on three primary components:
- Chunk-based Datastore: Unlike standard datastores that map hidden states to individual tokens, this datastore maps states to sequences, or "chunks," of tokens (e.g., 16 tokens at a time).
- Neighbors’ Cache: During a retrieval step, the model stores the entire retrieved chunks in a local, fast-access cache. In subsequent non-retrieval steps, the model searches this small cache instead of the massive global datastore.
- Retrieval Scheduling: The model employs a Geometric Progression (GP) schedule for lookups. Recognizing that retrieval is most critical at the beginning of a sentence to establish context, the GP schedule performs frequent lookups initially and gradually increases the interval between them as generation progresses.
As shown in Figure 1, the model alternates between Retrieval (R) steps, which populate the cache from the global datastore, and Non-retrieval (NR) steps, which leverage the cache to maintain speed. The final output is an interpolation of the base NMT model's distribution and the distribution derived from the retrieved chunks.
Experimental Results
The researchers evaluated the chunk-based model across several benchmarks, including multi-domain datasets (Medical, Law, IT, and Koran) and various language pairs.
Efficiency and Decoding Speed
The primary success of the chunk-based approach is its efficiency. The model is up to 4x faster than vanilla kNN-MT, reducing the decoding speed gap relative to the base MT model from a factor of 8x down to approximately 2x. This improvement is consistent across different domains and batch sizes.
Translation Quality
While the chunk-based model introduces a slight trade-off in translation quality compared to vanilla kNN-MT (an average dip of 1.5 BLEU points), it remains significantly superior to the base MT model. In multi-domain tasks, it achieved an average improvement of +9.1 BLEU points over the base model, demonstrating that the efficiency gains do not come at the cost of the model's primary adaptive benefits.
Conclusion
Chunk-based kNN-MT offers a practical path forward for semi-parametric domain adaptation. By optimizing the retrieval process through chunking, caching, and strategic scheduling, the method provides a "plug-and-play" enhancement that requires zero retraining of the underlying NMT model. Future work will focus on further compressing datastores and refining retrieval schedules to scale these benefits to even larger datasets.
Summary updated