IP Library › Granted Patent US 12,572,750
Granted Patent B2
US 12,572,750 · App. 18/114,702 · Granted Mar 10, 2026

Large language model evaluation with enhanced interpretability by k-nearest neighbor search

Inventors: Masayasu Muraoka (Tokyo, JP); Yang Zhao (Tokyo, JP)
Assignee: International Business Machines Corporation
G06F40/40G06F16/35G06F40/20G06F40/284G06F40/30G06N3/08G06N3/09G06N20/00G06F16/3344G06N3/045
View Patent ↗
Loading inventors, assignments & file history…
Monitor This Case
Get email alerts when status or documents change.
Order Certified Copies
Most orders are placed with the USPTO same day — all within 24 business hours.
Order via The Patent Place →
Pre-filled with this patent's details
Quick Facts
Patent No.
US 12,572,750
App. No.
18/114,702
Granted
Mar 10, 2026
Kind
B2
Abstract

Techniques for fine-tuning free evaluation of large language models with enhanced interpretability using a debiased output probability distribution of a large language model and a probability distribution of a k-Nearest Neighbor search result are provided. In one aspect, a method for performing a downstream task with a language model includes: constructing a datastore by applying the language model to a training set; applying the language model to a prompt-applied sentence from a testing set to obtain a language model feature vector; performing a k-Nearest Neighbor search of the datastore using the language model feature vector as a query vector; and interpolating a probability distribution of results from the k-Nearest Neighbor search and an output probability distribution of the language model to obtain a prediction for the downstream task.

Claims (203)

1 . A method for performing a downstream task with a language model, the method comprising:

obtaining a dataset for the downstream task, the dataset comprising at least a training set and a testing set;

constructing a datastore by applying the language model to the training set, the datastore comprising a set of triplets with each triplet including an instance x train from the training set, a label y′, and a feature vector h train , and wherein the feature vector h train corresponds to a masked token in the sentence x train ;

applying the language model to a prompt-applied sentence prompt(x) from an instance x in the testing set to predict a label y and a large language model feature vector h LLM (prompt(x));

computing an output probability distribution P LM of the language model;

debiasing the output probability distribution P LM of the language model to obtain a debiased output probability distribution {circumflex over (p)} debiasedLM ;

performing a k-Nearest Neighbor search of the datastore using the feature vector h LLM prompt(x)) as a query vector to find k-Nearest Neighbors N;

computing a probability distribution {circumflex over (p)} kNN of results from the k-Nearest Neighbor search, wherein {circumflex over (p)} kNN is computed as:

p

^

kNN

=

1

❘

"\[LeftBracketingBar]"

𝒩

❘

"\[RightBracketingBar]"

⁢

∑

(

_

,

y

′

,

h

train

)

∈

𝒩

y

=

y

′

exp

⁡

(

-

h

train

-

h

LM

(

prompt

⁢

(

x

)

)

T

)

⁢

using

⁢

T

as a scaling hyperparameter;

interpolating the debiased output probability distribution {circumflex over (p)} debiasedLM and the probability distribution {circumflex over (p)} kNN to obtain a final prediction {circumflex over (p)}(y|prompt(x)) for the downstream task; and

outputting the results from the k-Nearest Neighbor search to explain the final prediction of the language model.

2 . The method of claim 1 , wherein parameters of the language model are frozen.

3 . The method of claim 1 , further comprising:

extracting an instance x from the testing set; and

applying a prompt to the instance x to obtain the prompt-applied sentence prompt(x).

4 . The method of claim 1 , wherein the label y is predicted from a pre-defined label set Y.

5 . The method of claim 4 , wherein the output probability distribution P LM is computed over a vocabulary V as P LM (y∈V|prompt(x)).

6 . The method of claim 1 , wherein {circumflex over (p)} debiasedLM =W debias P LM (y∈V|prompt(x)), wherein W debias =diag({circumflex over (p)} cf ) −1 in which diag(v) is a function that returns a diagonal matrix of v, and wherein {circumflex over (p)} cf is computed from {circumflex over (p)} cf =1/C Σc=1 C P LM (y|prompt(context c )) by giving different input texts prompt(context c )) to the language model where context c is context-free input.

7 . The method of claim 1 , wherein k is a number of instances, and wherein k∈{0,1,4,8}.

8 . The method of claim 1 , wherein {circumflex over (p)}(y|prompt(x))=λ*{circumflex over (p)} debiasedLM + (1−λ)*{circumflex over (p)} kNN , and wherein λ∈[0,1].

9 . A computer program product for performing a downstream task with a language model, the computer program product comprising a computer readable storage medium having program instructions embodied therewith, the program instructions executable by a computer to cause the computer to perform:

obtaining a dataset for the downstream task, the dataset comprising at least a training set and a testing set;

constructing a datastore by applying the language model to the training set, the datastore comprising a set of triplets with each triplet including an instance x train from the training set, a label y′, and a feature vector h train , and wherein the feature vector h train corresponds to a masked token in the sentence x train ;

applying the language model to a prompt-applied sentence prompt(x) from an instance x in the testing set to predict a label y and a large language model feature vector h LLM (prompt(x));

computing an output probability distribution P LM of the language model;

debiasing the output probability distribution P LM of the language model to obtain a debiased output probability distribution {circumflex over (p)} debiasedLM ;

performing a k-Nearest Neighbor search of the datastore using the feature vector h LLM (prompt(x)) as a query vector to find k-Nearest Neighbors N;

computing a probability distribution {circumflex over (p)} kNN of results from the k-Nearest Neighbor search, wherein {circumflex over (p)} kNN is computed as:

p

^

kNN

=

1

❘

"\[LeftBracketingBar]"

N

❘

"\[RightBracketingBar]"

⁢

∑

(

_

,

y

′

,

h

train

)

∈

N

y

=

y

′

exp

⁡

(

-

h

train

-

h

LM

(

prompt

(

x

)

)

T

)

using T as a scaling hyperparameter;

interpolating the debiased output probability distribution {circumflex over (p)} debiasedLM and the probability distribution {circumflex over (p)} kNN to obtain a final prediction {circumflex over (p)}(y|prompt(x)) for the downstream task; and

outputting the results from the k-Nearest Neighbor search to explain the final prediction of the language model.

10 . The computer program product of claim 9 , wherein parameters of the language model are frozen.

11 . A system for performing a downstream task with a language model comprising a processor, connected to a memory, operable to perform:

obtaining a dataset for the downstream task, the dataset comprising at least a training set and a testing set;

constructing a datastore by applying the language model to the training set, the datastore comprising a set of triplets with each triplet including an instance x train from the training set, a label y′, and a feature vector h train , and wherein the feature vector h train corresponds to a masked token in the sentence x train ;

applying the language model to a prompt-applied sentence prompt(x) from an instance x in the testing set to predict a label y and a large language model feature vector h LLM (prompt(x));

computing an output probability distribution P LM of the language model;

debiasing the output probability distribution P LM of the language model to obtain a debiased output probability distribution {circumflex over (p)} debiasedLM ;

performing a k-Nearest Neighbor search of the datastore using the feature vector h LLM (prompt(x)) as a query vector to find k-Nearest Neighbors N;

computing a probability distribution {circumflex over (p)} kNN of results from the k-Nearest Neighbor search, wherein {circumflex over (p)} kNN is computed as:

p

^

kNN

=

1

❘

"\[LeftBracketingBar]"

N

❘

"\[RightBracketingBar]"

⁢

∑

(

_

,

y

′

,

h

train

)

∈

N

y

=

y

′

exp

⁡

(

-

h

train

-

h

LM

(

prompt

(

x

)

)

T

)

using T as a scaling hyperparameter;

interpolating the debiased output probability distribution {circumflex over (p)} debiasedLM and the probability distribution {circumflex over (p)} kNN to obtain a final prediction {circumflex over (p)}(y|prompt(x)) for the downstream task; and

outputting the results from the k-Nearest Neighbor search to explain the final prediction of the language model.

12 . The computer program product of claim 9 , further comprising:

extracting an instance x from the testing set; and

applying a prompt to the instance x to obtain the prompt-applied sentence prompt(x).

13 . The computer program product of claim 9 , wherein the label y is predicted from a pre-defined label set Y.

14 . The computer program product of claim 13 , wherein the output probability distribution P LM is computed over a vocabulary V as P LM (y=V prompt(x)).

15 . The computer program product of claim 9 , wherein {circumflex over (p)} debiasedLM =W debias P LM (y∈V|prompt(x)), wherein W debias =diag({circumflex over (p)} cf ) −1 in which diag(v) is a function that returns a diagonal matrix of v, and wherein {circumflex over (p)} cf is computed from {circumflex over (p)} cf =1/C Σc=1 C P LM (y|prompt(context c )) by giving different input texts prompt(context c )) to the language model where context c is context-free input.

16 . The computer program product of claim 9 , wherein k is a number of instances, and wherein k∈{0, 1, 4, 8}.

17 . The computer program product of claim 9 , wherein {circumflex over (p)}(y|prompt(x))=λ*{circumflex over (p)} debiasedLM +(1−λ)*{circumflex over (p)} kNN , and wherein λ∈[0,1].

18 . The system of claim 11 , wherein parameters of the language model are frozen.

19 . The system of claim 11 , further comprising:

extracting an instance x from the testing set; and

applying a prompt to the instance x to obtain the prompt-applied sentence prompt(x).

20 . The system of claim 11 , wherein the label y is predicted from a pre-defined label set Y.

21 . The system of claim 20 , wherein the output probability distribution P LM is computed over a vocabulary V as P LM (y∈V|prompt(x)).

22 . The system of claim 11 , wherein {circumflex over (p)} debiasedLM =W debias P LM (y∈V|prompt(x)), wherein W debias =diag ({circumflex over (p)} cf ) −1 in which diag(v) is a function that returns a diagonal matrix of v, and wherein {circumflex over (p)} cf is computed from {circumflex over (p)} cf =1/C Σc=1 C P LM (y|prompt(context c )) by giving different input texts prompt(context c ) to the language model where context c is context-free input.

23 . The system of claim 11 , wherein k is a number of instances, and wherein k∈{0,1,4,8}.

24 . The system of claim 11 , wherein {circumflex over (p)}(y|prompt(x))=λ*{circumflex over (p)} debiasedLM +(1−λ)*{circumflex over (p)} kNN , and wherein λ∈[0,1].

Assignments (1)
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Feb 27, 2023
From: MURAOKA, MASAYASU; ZHAO, YANG
To: INTERNATIONAL BUSINESS MACHINES CORPORATION
Reel/Frame 062813/0963 →
Continuity (1)
Related Publication 20240289558A1 · Aug 29, 2024
References Cited (27)
US 20160300154A1 · Bufe · 2016 [cited by examiner]
US 20200312301A1 · Polovets · 2020 [cited by examiner]
US 20210374488A1 · Rajani · 2021 [cited by examiner]
US 20240185518A1 · Kopp · 2024 [cited by examiner]
US 20240202458A1 · Zha · 2024 [cited by examiner]
US 20240289558A1 · Muraoka · 2024 [cited by examiner]
US 20250168368A1 · Dupont · 2025 [cited by examiner]
Tony Z. Zhao, Eric Wallace, Shi Feng , Dan Klein, Sameer Singh; Calibrate Before Use: Improving Few-Shot Performance of Language Models; Dec. 5, 2022; URL: https://arxiv.org/pdf/2212.02216 (Year: 2022). [cited by examiner]
Feng Nie, Meixi Chen, Zhirui Zhang, Xu Cheng; Improving Few-Shot Performance of Language Models via Nearest Neighbor Calibration; Jun. 10, 2021; URL: https://arxiv.org/pdf/2102.09690 (Year: 2021). [cited by examiner]
Nazneen Fatema Rajani, Ben Krause, Wengpeng Yin, Tong Niu, Richard Socher, Caiming Xiong; Explaining and Improving Model Behavior with k Nearest Neighbor Representations; Oct. 18, 2020; URL: https://arxiv.org/pdf/2010.0… [cited by examiner]
Frank F. Xu Uri Alon Graham Neubig; Why do Nearest Neighbor Language Models Work ?; Aug. 17, 2023; URL: https://arxiv.org/pdf/2301.02828 (Year: 2023). [cited by examiner]
Weijia Shi, Julian Michael, Suchin Gururangan, Luke Zettlemoyer;kNN-Prompt: Nearest Neighbor Zero-Shot Inference; Nov. 1, 2022; URL: https://arxiv.org/pdf/2205.13792 (Year: 2022). [cited by examiner]
Yue Xing, Qifan Song, Guang Cheng; Benefit of Interpolation in Nearest Neighbor Algorithms; Feb. 23, 2022; URL: https://arxiv.org/pdf/2202.11817 (Year: 2022). [cited by examiner]
Hua et al., “Fine-tuning Pre-trained Language Models with Noise Stability Regularization,” arXiv:2206.05658v1 (Jun. 2022) (15 pages). [cited by applicant]
Nazneen Fatema Rajani et al., “Explaining and Improving Model Behavior with k Nearest Neighbor Representations,” arXiv:2010.09030v1 (Oct. 2020) (9 pages). [cited by applicant]
Izacard et al., “Atlas: Few-shot Learning with Retrieval Augmented Language Models,” arXiv:2208.03299v3 (Nov. 2022) (33 pages). [cited by applicant]
Liu et al., “RoBERTa: A Robustly Optimized BERT Pretraining Approach,” arXiv:1907.11692c1 (Jul. 2019) (13 pages). [cited by applicant]
Zhao et al., “Calibrate Before Use: Improving Few-Shot Performance of Language Models,” Proceedings of the 38th International Conference on Machine Learning, PMLR 139, Jul. 2021 (10 pages). [cited by applicant]
Socher et al., “Recursive Deep Models for Semantic Compositionality Over a Sentiment Treebank,” Proceedings of the 2013 Conference on Empirical Methods in Natural Language Processing, pp. 1631-1642 (Oct. 2013). [cited by applicant]
Khandelwal et al., “Nearest Neighbor Machine Translation,” arXiv:2010.00710v2 (Jul. 2021) (14 pages). [cited by applicant]
Wolf et al., “Transformers: State-of-the-Art Natural Language Processing,” Proceedings of the 2020 EMNLP (Systems Demonstrations), pp. 38-45 (Nov. 2020). [cited by applicant]
Devlin et al., “BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding”, Proceedings of NAACL-HLT 2019, pp. 4171-4186 (Jun. 2019). [cited by applicant]
Lample et al., “Cross-lingual Language Model Pretraining,” arXic:1901.07291v1 (Jan. 2019) (10 pages). [cited by applicant]
Brian Lester, Blog, “Guiding Frozen Language Models with Learned Soft Prompts,” Feb. 10, 2022 (5 pages). [cited by applicant]
Weyssow et al., “Recommending metamodel concepts during modeling activities with pre-trained language models,” Software and Systems Modeling (Jun. 2022) (21 pages). [cited by applicant]
“Utilizing kNN Instances to Improve Accuracy and Interpretability in Zero/Few-shot Text Classification,” Masayasu Muraoka and Yang Zhao, submitted to the 29th Annual Meeting of the Natural Language Processing Society (N… [cited by applicant]
“Utilizing kNN Instances to Improve Accuracy and Interpretability in Few-shot Text Classification Evaluation,” Masayasu Muraoka, submitted to the 61st Annual Meeting of the Association for Computational Linguistics (ACL… [cited by applicant]