Skip to main content
QUICK REVIEW

[Paper Review] Fast Nearest Neighbor Machine Translation

Yuxian Meng, Xiaoya Li|arXiv (Cornell University)|May 30, 2021
Natural Language Processing TechniquesComputer Science14 citations
TL;DR

This paper proposes Fast k-NN-MT, a highly efficient variant of k-Nearest Neighbor Machine Translation that accelerates inference by restricting the search space to only target tokens associated with previously selected reference source tokens. By limiting nearest neighbor search to same-type token neighbors and dynamically shrinking the datastore per decoding step, Fast k-NN-MT achieves two orders of magnitude speedup over vanilla k-NN-MT while maintaining near-identical performance, running only twice as slow as standard NMT models.

ABSTRACT

Though nearest neighbor Machine Translation ($k$NN-MT) \citep{khandelwal2020nearest} has proved to introduce significant performance boosts over standard neural MT systems, it is prohibitively slow since it uses the entire reference corpus as the datastore for the nearest neighbor search. This means each step for each beam in the beam search has to search over the entire reference corpus. $k$NN-MT is thus two-orders slower than vanilla MT models, making it hard to be applied to real-world applications, especially online services. In this work, we propose Fast $k$NN-MT to address this issue. Fast $k$NN-MT constructs a significantly smaller datastore for the nearest neighbor search: for each word in a source sentence, Fast $k$NN-MT first selects its nearest token-level neighbors, which is limited to tokens that are the same as the query token. Then at each decoding step, in contrast to using the entire corpus as the datastore, the search space is limited to target tokens corresponding to the previously selected reference source tokens. This strategy avoids search through the whole datastore for nearest neighbors and drastically improves decoding efficiency. Without loss of performance, Fast $k$NN-MT is two-orders faster than $k$NN-MT, and is only two times slower than the standard NMT model. Fast $k$NN-MT enables the practical use of $k$NN-MT systems in real-world MT applications. The code is available at \url{https://github.com/ShannonAI/fast-knn-nmt}

Motivation & Objective

  • To address the prohibitive inference latency of k-NN-MT, which is two orders of magnitude slower than standard NMT due to full-corpus nearest neighbor searches at each decoding step.
  • To enable practical deployment of k-NN-MT in real-world online MT services by drastically improving decoding efficiency without sacrificing translation quality.
  • To design a scalable and efficient retrieval mechanism that limits the datastore to only relevant reference tokens based on source-side context.
  • To investigate the trade-offs between search space size, neighbor count, and model performance in a constrained retrieval setting.

Proposed method

  • Construct a smaller datastore by selecting only token-level neighbors that match the query token type (e.g., same word form) for each source token.
  • At each decoding step, restrict the nearest neighbor search to target tokens corresponding to previously selected reference source tokens, forming a chain of mappings from source to target via reference examples.
  • Use FastAlign to establish cross-lingual alignments between source and target tokens for efficient retrieval of reference examples.
  • Limit the search space during k-NN inference to only those target tokens linked to previously retrieved source reference tokens, reducing the number of candidates per step.
  • Apply quantization to high-dimensional token representations to reduce memory usage, with minimal impact on performance.
  • Use cosine similarity as the distance metric for nearest neighbor retrieval due to its superior performance over L2 and inner product.

Experimental results

Research questions

  • RQ1Can we significantly reduce the inference latency of k-NN-MT without degrading translation quality?
  • RQ2How does restricting the search space to only relevant reference source tokens affect model performance and speed?
  • RQ3What is the optimal number of neighbors to retrieve per source token (c) for balancing accuracy and efficiency?
  • RQ4How does neighbor count on the target side (k) influence performance, and is there a point of diminishing returns?
  • RQ5To what extent does quantization of vector representations affect model performance in the retrieval pipeline?

Key findings

  • Fast k-NN-MT achieves a 100x speedup over vanilla k-NN-MT, reducing inference time to only two times slower than standard NMT models.
  • On WMT’19 De-En, Fast k-NN-MT achieves a SacreBLEU score of 39.3, matching the performance of vanilla k-NN-MT.
  • On WMT’14 En-Fr, Fast k-NN-MT attains a SacreBLEU score of 41.7, comparable to the original k-NN-MT model.
  • In domain adaptation tasks, Fast k-NN-MT achieves an average SacreBLEU score of 41.4, demonstrating strong generalization across domains.
  • Quantization of token representations causes only a 0.1 BLEU point drop in average score, indicating it is a viable trade-off for memory efficiency.
  • The optimal number of source-side neighbors (c) is 512, beyond which performance gains plateau, while target-side neighbor count (k) shows a clear peak around optimal values.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.