[Paper Review] Efficient Nearest Neighbor Language Models
This paper proposes a suite of techniques to accelerate k-nearest neighbors language models (kNN-LM) by enabling adaptive retrieval, datastore pruning, and dimensionality reduction via PCA. By combining these methods, the approach achieves up to 6.6x speedup on WikiText-103 and 5.4x on Law-MT while maintaining or slightly improving perplexity compared to the original kNN-LM, making non-parametric language modeling more practical for real-world deployment.
Non-parametric neural language models (NLMs) learn predictive distributions of text utilizing an external datastore, which allows them to learn through explicitly memorizing the training datapoints. While effective, these models often require retrieval from a large datastore at test time, significantly increasing the inference overhead and thus limiting the deployment of non-parametric NLMs in practical applications. In this paper, we take the recently proposed $k$-nearest neighbors language model (Khandelwal et al., 2020) as an example, exploring methods to improve its efficiency along various dimensions. Experiments on the standard WikiText-103 benchmark and domain-adaptation datasets show that our methods are able to achieve up to a 6x speed-up in inference speed while retaining comparable performance. The empirical analysis we present may provide guidelines for future research seeking to develop or deploy more efficient non-parametric NLMs.
Motivation & Objective
- Address the high inference cost of non-parametric language models due to expensive retrieval from large external datastores.
- Improve the efficiency of kNN-LM without sacrificing performance, enabling broader deployment in practical NLP applications.
- Investigate whether retrieval can be selectively skipped, redundant datastore entries removed, or vector dimensions reduced to enhance speed.
- Provide empirical guidelines for balancing speed and performance in non-parametric language modeling.
Proposed method
- Introduce an adaptive retrieval mechanism using a lightweight neural network to predict whether retrieval is necessary for each token, reducing retrieval calls by up to 50%.
- Apply greedy merging and importance-guided filtering to prune up to 40% of the datastore entries while maintaining model performance.
- Use PCA-based dimensionality reduction to compress the vector representations in the datastore, improving both speed and perplexity.
- Combine adaptive retrieval, datastore pruning, and dimensionality reduction into a unified optimization pipeline for maximum efficiency.
- Train the retrieval adapter on a held-out validation set to avoid overfitting and ensure generalization.
- Leverage FAISS’s PCA implementation with random rotation to improve quantization efficiency and performance in vector search.
Experimental results
Research questions
- RQ1Can we reduce inference overhead by intelligently skipping retrieval for certain tokens without degrading performance?
- RQ2To what extent can we compress the datastore by removing redundant or less important entries without harming model accuracy?
- RQ3Does reducing the dimensionality of datastore vectors improve both speed and performance, and if so, why?
- RQ4What is the optimal combination of efficiency techniques that maximizes speedup while preserving perplexity?
Key findings
- Adaptive retrieval achieves up to 1.9x speedup on WikiText-103 with only a 0.02 perplexity increase, reducing retrieval calls by 50%.
- Greedy merging pruning reduces the datastore by 40% with a 0.2 perplexity increase, demonstrating effective redundancy removal.
- PCA dimensionality reduction to 512 dimensions improves perplexity by 0.25 points (16.65 → 16.40) and enables 3.6x speedup on WikiText-103.
- The combination of all three techniques yields 6.6x speedup on WikiText-103 with nearly identical perplexity (16.67 vs. 16.65) to the baseline kNN-LM.
- On the Law-MT domain adaptation dataset, the combined method achieves 5.4x speedup and a 0.35-point perplexity improvement over the baseline kNN-LM.
- PCA not only accelerates inference but also improves performance on Law-MT (12.64 → 11.59), suggesting a more suitable vector space for L2-based kNN search.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.