Efficient k-Nearest-Neighbor Machine Translation with Dynamic Retrieval

Yan Gao, Zhiwei Cao, Zhongjian Miao, Baosong Yang, Shiyu Liu +2 more
6/10/2024
cs.CL

No official code found. Best implementation: XMUDeepLIT/knn-mt-dr (2 stars, MIT, last commit 2024-08-21).

Abstract

To achieve non-parametric NMT domain adaptation, $k$-Nearest-Neighbor Machine Translation ($k$NN-MT) constructs an external datastore to store domain-specific translation knowledge, which derives a $k$NN distribution to interpolate the prediction distribution of the NMT model via a linear interpolation coefficient $λ$. Despite its success, $k$NN retrieval at each timestep leads to substantial time overhead. To address this issue, dominant studies resort to $k$NN-MT with adaptive retrieval ($k$NN-MT-AR), which dynamically estimates $λ$ and skips $k$NN retrieval if $λ$ is less than a fixed threshold. Unfortunately, $k$NN-MT-AR does not yield satisfactory results. In this paper, we first conduct a preliminary study to reveal two key limitations of $k$NN-MT-AR: 1) the optimization gap leads to inaccurate estimation of $λ$ for determining $k$NN retrieval skipping, and 2) using a fixed threshold fails to accommodate the dynamic demands for $k$NN retrieval at different timesteps. To mitigate these limitations, we then propose $k$NN-MT with dynamic retrieval ($k$NN-MT-DR) that significantly extends vanilla $k$NN-MT in two aspects. Firstly, we equip $k$NN-MT with a MLP-based classifier for determining whether to skip $k$NN retrieval at each timestep. Particularly, we explore several carefully-designed scalar features to fully exert the potential of the classifier. Secondly, we propose a timestep-aware threshold adjustment method to dynamically generate the threshold, which further improves the efficiency of our model. Experimental results on the widely-used datasets demonstrate the effectiveness and generality of our model.\footnote{Our code is available at \url{https://github.com/DeepLearnXMU/knn-mt-dr}.

View on arXivView PDF

Code Implementations(1)

MIT

Code for "Efficient k-Nearest-Neighbor Machine Translation with Dynamic Retrieval" (Findings of ACL 2024)

20C++, LuaMay 31, 20242 years agoMIT

Similar Papers

Cite this paper

@article{gao2024efficient,
  title  = {Efficient k-Nearest-Neighbor Machine Translation with Dynamic Retrieval},
  author = {Yan Gao and Zhiwei Cao and Zhongjian Miao and Baosong Yang and Shiyu Liu and Min Zhang and Jinsong Su},
  year   = {2024},
  eprint = {2406.06073},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2406.06073v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2406.06073.svg)](https://codeofpaper.com/paper/2406.06073)

Discussion