{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/efficient-cluster-based-k-nearest-neighbor","title":"Efficient Cluster-Based k-Nearest-Neighbor Machine Translation","arxiv_id":"2204.06175","date":"2022-04-13","proceeding":"ACL 2022 5","authors":["Dexin Wang","Kai Fan","Boxing Chen","Deyi Xiong"],"abstract":"k-Nearest-Neighbor Machine Translation (kNN-MT) has been recently proposed as a non-parametric solution for domain adaptation in neural machine translation (NMT). It aims to alleviate the performance degradation of advanced MT systems in translating out-of-domain sentences by coordinating with an additional token-level feature-based retrieval module constructed from in-domain data. Previous studies have already demonstrated that non-parametric NMT is even superior to models fine-tuned on out-of-domain data. In spite of this success, kNN retrieval is at the expense of high latency, in particular for large datastores. To make it practical, in this paper, we explore a more efficient kNN-MT and propose to use clustering to improve the retrieval efficiency. Concretely, we first propose a cluster-based Compact Network for feature reduction in a contrastive learning manner to compress context features into 90+% lower dimensional vectors. We then suggest a cluster-based pruning solution to filter out 10%-40% redundant nodes in large datastores while retaining translation quality. Our proposed methods achieve better or comparable performance while reducing up to 57% inference latency against the advanced non-parametric MT model on several machine translation benchmarks. Experimental results indicate that the proposed methods maintain the most useful information of the original datastore and the Compact Network shows good generalization on unseen domains.","url_abs":"https://arxiv.org/abs/2204.06175v2","url_pdf":"https://arxiv.org/pdf/2204.06175v2.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"efficient-cluster-based-k-nearest-neighbor","repo_url":"https://github.com/tjunlp-lab/pckmt","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":1,"framework":"none","reach":{"status":"ok","spdx":"MIT"}},{"paper_slug":"efficient-cluster-based-k-nearest-neighbor","repo_url":"https://github.com/cordercorder/knn-models","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":0,"framework":"pytorch","reach":{"status":"ok","spdx":"Apache-2.0"}}],"tasks":[{"task_slug":"contrastive-learning","task_name":"Contrastive Learning"},{"task_slug":"domain-adaptation","task_name":"Domain Adaptation"},{"task_slug":"machine-translation","task_name":"Machine Translation"},{"task_slug":"nmt","task_name":"NMT"},{"task_slug":"retrieval","task_name":"Retrieval"},{"task_slug":"translation","task_name":"Translation"}],"methods":[{"method_slug":"contrastive-learning","method_name":"Contrastive Learning"},{"method_slug":"pruning","method_name":"Pruning"}],"datasets_introduced":[],"methods_introduced":[],"results":[],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2204.06175","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2204.06175"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/cordercorder/knn-models","reach":{"status":"ok","spdx":"Apache-2.0"}},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/tjunlp-lab/pckmt","reach":{"status":"ok","spdx":"MIT"}},{"provenance":"deterministic:regex_extraction","url":"https://github.com/tjunlp-lab/PCKMT","reach":{"status":"ok","spdx":"MIT"}}],"summary":{"unverified":6},"by_repo_kind":{"listed":{"samples":6,"ran":0,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"a3b087d2f3431832","entry":"build_flatl2_index","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models_cli/build_faiss_index.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models_cli/build_faiss_index.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"a3b087d2f3431832"}},{"code_sha256_prefix":"72cd21cbd7c41fad","entry":"build_ivfpq_index","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models_cli/build_faiss_index.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models_cli/build_faiss_index.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"72cd21cbd7c41fad"}},{"code_sha256_prefix":"e86685036268a1d5","entry":"convert_retrieved_text_to_tensor","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models/es_knn_utils.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models/es_knn_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"e86685036268a1d5"}},{"code_sha256_prefix":"c9f0e2e7c0c48ee3","entry":"edit_distance","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models/es_knn_utils.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models/es_knn_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"c9f0e2e7c0c48ee3"}},{"code_sha256_prefix":"69d1f014163532b4","entry":"get_captured_module","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models/knn_utils.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models/knn_utils.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"69d1f014163532b4"}},{"code_sha256_prefix":"8ed29d811d387a63","entry":"get_gpu_resource","repo":"cordercorder/knn-models","repo_kind":"listed","path":"knn_models_cli/build_faiss_index.py","file_url":"https://github.com/cordercorder/knn-models/blob/HEAD/knn_models_cli/build_faiss_index.py","link_basis":"harvester_set","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"Apache-2.0","inline_ok":true,"mcp_get_code":{"code_sha256":"8ed29d811d387a63"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}