Formula

k-NN LM Interpolation Formula

The final probability distribution in a kk-nearest neighbors (kk-NN) language model is computed using a linear function that interpolates between the retrieval-based distribution, Prknn(hi)\mathrm{Pr}_{k\mathrm{nn}}(\cdot|\mathbf{h}_i), and the base large language model (LLM) output distribution, Prlm(hi)\mathrm{Pr}_{\mathrm{lm}}(\cdot|\mathbf{h}_i). This interpolation uses a coefficient λ\lambda to balance the two components, represented by the formula: Pr(hi)=λPrknn(hi)+(1λ)Prlm(hi)\mathrm{Pr}(\cdot|\mathbf{h}_i) = \lambda \cdot \mathrm{Pr}_{k\mathrm{nn}}(\cdot|\mathbf{h}_i) + (1 - \lambda) \cdot \mathrm{Pr}_{\mathrm{lm}}(\cdot|\mathbf{h}_i), where hi\mathbf{h}_i is the query's hidden state.

Image 0

0

1

Updated 2026-04-23

Contributors are:

Who are from:

Tags

Ch.2 Generative Models - Foundations of Large Language Models

Foundations of Large Language Models

Foundations of Large Language Models Course

Computing Sciences