Faster Nearest Neighbor Machine Translation

Shuhe Wang, Jiwei Li, Yuxian Meng, Rongbin Ouyang, Guoyin Wang, Xiaoya Li, Tianwei Zhang, Shi ZongarXiv 2021

Introduction

Nearest Neighbor Machine Translation (kNN-MT) has emerged as a powerful paradigm for retrieval-augmented translation. By querying a massive "datastore" of training examples during decoding, kNN-MT models can adapt to new domains and significantly improve translation accuracy without retraining. However, the computational overhead is substantial: searching through millions of entries at every generation step makes real-time deployment nearly impossible.

While previous iterations like Fast kNN-MT attempted to optimize this by narrowing searches to specific word types, they remained bottlenecked by high-frequency tokens and long sequences. This paper introduces Faster kNN-MT, a method that achieves state-of-the-art accuracy while reducing retrieval overhead to just 1.2x the time of a vanilla neural machine translation (NMT) model.

Methodology: Hierarchical Clustering and Distance Approximation

The core innovation of Faster kNN-MT is a hierarchical clustering strategy designed to approximate distances between queries and datastore points efficiently.

Overview of the Faster kNN-MT architecture compared to vanilla and fast variants.

The process involves four key steps:

  1. Clustering: Tokens of the same type in the training set are grouped into $g$ clusters using k-means.
  2. Distance Decomposition: The distance between a query ($h$) and a datastore point ($z$) is approximated by splitting it into the distance from the query to the cluster centroid ($c$) and the distance from that centroid to the specific point ($z$).
  3. Pre-computation: Distances between centroids and their constituent points are calculated and cached during the datastore construction phase.
  4. Efficient Retrieval: During inference, the model only searches for the nearest cluster centroids—a significantly smaller search space. It then uses cached internal distances to determine the final k-nearest neighbors.

This approach shifts the time complexity from being dependent on word frequency to being proportional to the fixed number of clusters, ensuring consistent performance even for common words.

Experimental Setup

The researchers evaluated Faster kNN-MT across several benchmarks:

  • Bilingual Translation: WMT’14 English-French (35M pairs) and WMT’19 German-English (32M pairs).
  • Domain Adaptation: Specialized datasets in the Medical, IT, Koran, and Subtitles domains. These benchmarks test the model's ability to generalize to niche vocabularies.

Key Results and Discussion

Faster kNN-MT demonstrates that exact distance calculations are not strictly necessary for high-quality translation. By approximating distances via centroids, the model preserves nearly all the BLEU score gains of vanilla kNN-MT while dramatically increasing throughput.

Decoding speed comparison across different kNN-MT variants as the number of neighbors increases.

Speed and Efficiency

Faster kNN-MT is only 1.2x slower than a standard NMT model, a significant improvement over "Fast kNN-MT" (approx. 2x slower) and orders of magnitude faster than the original vanilla kNN-MT. As shown in the performance analysis, Faster kNN-MT maintains a stable decoding speed regardless of the number of neighbors queried, effectively solving the "high-frequency" bottleneck.

Translation Accuracy

On the WMT’19 German-English task, Faster kNN-MT achieved a BLEU score of 39.3, matching Fast kNN-MT and outperforming the Base MT model (37.6). In domain adaptation tasks, the results were even more pronounced; for instance, in the Medical domain, the base BLEU score improved from 39.9 to 52.7.

Limitations and Future Work

Despite its success, the method's performance is sensitive to the number of clusters ($g$), which may require tuning for different languages. Additionally, the reliance on FastAlign for mapping source to target clusters means that alignment errors during datastore construction can impact final quality. Future research may explore more sophisticated clustering algorithms or alternative distance metrics to further refine the retrieval process.

Summary updated

BibTeX
@misc{wang2021faster,
  author = {Shuhe Wang and Jiwei Li and Yuxian Meng and Rongbin Ouyang and Guoyin Wang and Xiaoya Li and Tianwei Zhang and Shi Zong},
  title = {{Faster Nearest Neighbor Machine Translation}},
  year = {2021},
  eprint = {2112.08152},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2112.08152},
}
Figure