IP Library › Granted Patent US 12,265,909
Granted Patent B2
US 12,265,909 · App. 17/090,553 · Granted Apr 1, 2025

Systems and methods for a k-nearest neighbor based mechanism of natural language processing models

Inventors: Nazneen Rajani (Mountain View, CA); Tong Niu (Sunnyvale, CA); Wenpeng Yin (Palo Alto, CA)
Assignee: Salesforce, Inc.
G06N3/08G06F18/10G06F18/214G06F18/24147G06F18/2415G06N3/063
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,265,909
App. No.
17/090,553
Granted
Apr 1, 2025
Kind
B2
Abstract

Embodiments described herein adopts a k nearest neighbor (kNN) mechanism over a model's hidden representations to identify training examples closest to a given test example. Specifically, a training set of sequences and a test sequence are received, each of which is mapped to a respective hidden representation vector using a base model. A set of indices for each sequence index that minimizes a distance between the respective hidden state vector and a test hidden state vector is then determined A weighted k-nearest neighbor probability score can then be computed from the set of indices to generate a probability distribution over labels for the test sequence.

Claims (59)

1. A method of identifying inaccurate labels in training data, the method comprising:

receiving, at a data interface, a training set of sequences, wherein each sequence from the training set is paired with a target label from a plurality of labels;

mapping, by a neural network, each training sequence to a respective normalized hidden representation vector, including:

computing the respective normalized hidden representation vector based on a dataset-wise batch normalization of hidden representation vectors with a mean and a standard deviation over hidden states of the neural network responsive to the training set of sequences,

wherein the mean and the standard deviation of hidden states are obtained over the training set of sequences, and

wherein the computing further comprises dividing a difference between a first hidden representation vector and the mean by a sum of the standard deviation and a numerical stability parameter;

receiving a testing sequence at inference stage;

after receiving the testing sequence at inference stage, mapping, by the neural network, the test sequence to a normalized test hidden representation vector;

determining, among the training set of sequences, a set of sequence indices that lead to a set of smallest distances between respective normalized respective hidden state vectors and the normalized test hidden state vector;

computing, for each training sequence in the set of sequence indices, a weighted probability score based on a set of distances corresponding to the set of sequence indices;

generate a probability distribution over the plurality of labels for the test sequence based on computed weighted probability scores and one-hot encodings of each target label in the plurality of labels; and

identifying a mislabeled training sequence from the training set of sequences when a direct prediction by the neural network is different from a prediction based on the generated probability distribution.

2. The method of claim 1 , further comprising:

caching the mapped respective normalized hidden representation vectors at a memory;

and querying the cached mapped respective normalized hidden representation vectors for determining the set of sequence indices and comparing with the normalized test hidden state vector.

3. The method of claim 1 , further comprising generating a classifier prediction for the test sequence based on the generated probability distribution.

4. The method of claim 1 , wherein the respective normalized hidden representation vector is a representation corresponding to a specific token that is added at a beginning of the respective sequence in a last layer of the neural network.

5. The method of claim 1 , further comprising:

generating, by the neural network, a prediction in response to the testing sequence and a confidence score associated with the predicted distribution; and

in response to determining that the confidence score is lower than a threshold, computing the weighted probability score for fine-tuning the prediction of the testing sequence.

6. The method of claim 1 , wherein the weighted probability score for each training sequence in the set of sequence indices is computed using a softmax operation over negatives of the set of smallest distances.

7. A system for identifying inaccurate labels in training data, the system comprising:

a data interface that receives a training set of sequences, wherein each sequence from the training set is paired with a target label from a plurality of labels;

a memory that stores a neural model; and

one or more hardware processors that:

map, by the neural model, each training sequence to a respective normalized hidden representation vector, including:

computing the respective normalized hidden representation vector based on a dataset-wise batch normalization of hidden representation vectors with a mean and a standard deviation over hidden states of the neural network responsive to the training set of sequences,

wherein the mean and the standard deviation of hidden states are obtained over the training set of sequences, and

wherein the computing further comprises dividing a difference between a first hidden representation vector and the mean by a sum of the standard deviation and a numerical stability parameter;

in response to receiving a testing sequence at inference stage, map, by the neural model, the test sequence to a normalized test hidden representation vector;

determine, among the training set of sequences, a set of sequence indices that lead to a set of smallest distances between respective normalized respective hidden state vectors and the normalized test hidden state vector;

compute, for each training sequence in the set of sequence indices, a weighted probability score based on a set of distances corresponding to the set of sequence indices;

generate a probability distribution over the plurality of labels for the test sequence based on the weighted probability score and one-hot encodings of each target label in the plurality of labels; and

identifying a mislabeled training sequence from the training set of sequences when a direct prediction by the neural model is different from a prediction based on the generated probability distribution.

8. The system of claim 7 , wherein the one or more hardware processors further:

cache the mapped respective normalized hidden representation vectors at a memory; and

query the cached mapped respective normalized hidden representation vectors for determining the set of sequence indices and comparing with the normalized test hidden state vector.

9. The system of claim 7 , wherein the one or more hardware processors further generate a classifier prediction for the test sequence based on the generated probability distribution.

10. The system of claim 7 , wherein the respective normalized hidden representation vector is a representation corresponding to a specific token that is added at a beginning of the respective sequence in a last layer of the neural network.

11. The system of claim 7 , wherein the one or more hardware processors further:

generate, by the neural network, a prediction in response to the testing sequence and a confidence score associated with the predicted distribution; and

in response to determining that the confidence score is lower than a threshold, compute the weighted probability score for fine-tuning the prediction of the testing sequence.

12. A non-transitory processor-readable medium storing a plurality of instructions for identifying inaccurate labels in training data, the instructions being processor-executed by one or more hardware processors to perform operations comprising:

receiving, at a data interface, a training set of sequences, wherein each sequence from the training set is paired with a target label from a plurality of labels;

mapping, by a neural network, each training sequence to a respective normalized hidden representation vector, including:

computing the respective normalized hidden representation vector based on a dataset-wise batch normalization of hidden representation vectors with a mean and a standard deviation over hidden states of the neural network responsive to the training set of sequences,

wherein the mean and the standard deviation of hidden states are obtained over the training set of sequences, and

wherein the computing further comprises dividing a difference between a first hidden representation vector and the mean by a sum of the standard deviation and a numerical stability parameter;

in response to receiving a testing sequence at inference stage, mapping, by the neural network, the test sequence to a normalized test hidden representation vector;

determining, among the training set of sequences, a set of sequence indices that lead to a set of smallest distances between respective normalized respective hidden state vectors and the normalized test hidden state vector;

computing, for each training sequence in the set of sequence indices, a weighted probability score based on a set of distances corresponding to the set of sequence indices;

generate a probability distribution over the plurality of labels for the test sequence based on the weighted probability score and one-hot encodings of each target label in the plurality of labels; and

identifying a mislabeled training sequence from the training set of sequences when a direct prediction by the neural network is different from a prediction based on the generated probability distribution.

13. The medium of claim 12 , wherein the operations further comprise:

caching the mapped respective normalized hidden representation vectors at a memory;

and querying the cached mapped respective normalized hidden representation vectors for determining the set of sequence indices and comparing with the normalized test hidden state vector.

14. The medium of claim 12 , wherein the operations further comprise:

generating, by the neural network, a prediction in response to the testing sequence and a confidence score associated with the predicted distribution; and

in response to determining that the confidence score is lower than a threshold, computing the weighted probability score for fine-tuning the prediction of the testing sequence.

Assignments (2)
CHANGE OF NAME Recorded Aug 4, 2026
From: SALESFORCE.COM, INC.
To: SALESFORCE, INC.
Reel/Frame 076118/0548 →
ASSIGNMENT OF ASSIGNOR'S INTEREST Recorded Nov 5, 2020
From: RAJANI, NAZNEEN; NIU, TONG; YIN, WENPENG
To: SALESFORCE.COM, INC.
Reel/Frame 054289/0643 →
Continuity (2)
Provisional Application 63033197 · Jun 1, 2020
Related Publication 20210374488A1 · Dec 2, 2021
References Cited (144)
US 10282663B2 · Socher et al. · 2019 [cited by applicant]
US 10346721B2 · Albright et al. · 2019 [cited by applicant]
US 10474709B2 · Paulus · 2019 [cited by applicant]
US 10521465B2 · Paulus · 2019 [cited by applicant]
US 10542270B2 · Zhou et al. · 2020 [cited by applicant]
US 10546217B2 · Albright et al. · 2020 [cited by applicant]
US 10558750B2 · Lu et al. · 2020 [cited by applicant]
US 10565305B2 · Lu et al. · 2020 [cited by applicant]
US 10565306B2 · Lu et al. · 2020 [cited by applicant]
US 10565318B2 · Bradbury · 2020 [cited by applicant]
US 10565493B2 · Merity et al. · 2020 [cited by applicant]
US 10573295B2 · Zhou et al. · 2020 [cited by applicant]
US 10592767B2 · Trott et al. · 2020 [cited by applicant]
US 10699060B2 · Mccann · 2020 [cited by applicant]
US 10747761B2 · Zhong et al. · 2020 [cited by applicant]
US 10776581B2 · Mccann et al. · 2020 [cited by applicant]
US 10783875B2 · Hosseini-Asl et al. · 2020 [cited by applicant]
US 10817650B2 · Mccann et al. · 2020 [cited by applicant]
US 10839284B2 · Hashimoto et al. · 2020 [cited by applicant]
US 10846478B2 · Lu et al. · 2020 [cited by applicant]
US 10902289B2 · Gao et al. · 2021 [cited by applicant]
US 10909157B2 · Paulus et al. · 2021 [cited by applicant]
US 10929607B2 · Zhong et al. · 2021 [cited by applicant]
US 10958925B2 · Zhou et al. · 2021 [cited by applicant]
US 10963652B2 · Hashimoto et al. · 2021 [cited by applicant]
US 10963782B2 · Xiong et al. · 2021 [cited by applicant]
US 10970486B2 · Machado et al. · 2021 [cited by applicant]
US 20160350653A1 · Socher et al. · 2016 [cited by applicant]
US 20170024645A1 · Socher et al. · 2017 [cited by applicant]
US 20170032280A1 · Socher · 2017 [cited by applicant]
US 20170140240A1 · Socher et al. · 2017 [cited by applicant]
US 20180096219A1 · Socher · 2018 [cited by applicant]
US 20180121788A1 · Hashimoto et al. · 2018 [cited by applicant]
US 20180121799A1 · Hashimoto et al. · 2018 [cited by applicant]
US 20180129931A1 · Bradbury et al. · 2018 [cited by applicant]
US 20180129937A1 · Bradbury et al. · 2018 [cited by applicant]
US 20180268287A1 · Johansen et al. · 2018 [cited by applicant]
US 20180268298A1 · Johansen et al. · 2018 [cited by applicant]
US 20180336453A1 · Merity et al. · 2018 [cited by applicant]
US 20180373987A1 · Zhang et al. · 2018 [cited by applicant]
US 20190130248A1 · Zhong et al. · 2019 [cited by applicant]
US 20190130249A1 · Bradbury et al. · 2019 [cited by applicant]
US 20190130273A1 · Keskar et al. · 2019 [cited by applicant]
US 20190130312A1 · Xiong et al. · 2019 [cited by applicant]
US 20190130896A1 · Zhou et al. · 2019 [cited by applicant]
US 20190188568A1 · Keskar et al. · 2019 [cited by applicant]
US 20190213482A1 · Socher et al. · 2019 [cited by applicant]
US 20190220733A1 · Fisher · 2019 [cited by examiner]
US 20190251431A1 · Keskar et al. · 2019 [cited by applicant]
US 20190258939A1 · Min et al. · 2019 [cited by applicant]
US 20190286073A1 · Asl et al. · 2019 [cited by applicant]
US 20190355270A1 · Mccann et al. · 2019 [cited by applicant]
US 20190362246A1 · Lin et al. · 2019 [cited by applicant]
US 20200005765A1 · Zhou et al. · 2020 [cited by applicant]
US 20200065651A1 · Merity et al. · 2020 [cited by applicant]
US 20200090033A1 · Ramachandran et al. · 2020 [cited by applicant]
US 20200090034A1 · Ramachandran et al. · 2020 [cited by applicant]
US 20200103911A1 · Ma et al. · 2020 [cited by applicant]
US 20200104643A1 · Hu et al. · 2020 [cited by applicant]
US 20200104699A1 · Zhou et al. · 2020 [cited by applicant]
US 20200105272A1 · Wu et al. · 2020 [cited by applicant]
US 20200117854A1 · Lu et al. · 2020 [cited by applicant]
US 20200117861A1 · Bradbury · 2020 [cited by applicant]
US 20200142917A1 · Paulus · 2020 [cited by applicant]
US 20200175305A1 · Trott et al. · 2020 [cited by applicant]
US 20200193297A1 · Verhoef · 2020 [cited by examiner]
US 20200234113A1 · Liu · 2020 [cited by applicant]
US 20200272940A1 · Sun et al. · 2020 [cited by applicant]
US 20200285704A1 · Rajani et al. · 2020 [cited by applicant]
US 20200285705A1 · Zheng et al. · 2020 [cited by applicant]
US 20200285706A1 · Singh et al. · 2020 [cited by applicant]
US 20200285993A1 · Liu et al. · 2020 [cited by applicant]
US 20200302178A1 · Gao et al. · 2020 [cited by applicant]
US 20200320382A1 · Burkhart · 2020 [cited by examiner]
US 20200334334A1 · Keskar et al. · 2020 [cited by applicant]
US 20200364299A1 · Niu et al. · 2020 [cited by applicant]
US 20200364542A1 · Sun · 2020 [cited by applicant]
US 20200364580A1 · Shang et al. · 2020 [cited by applicant]
US 20200372116A1 · Gao et al. · 2020 [cited by applicant]
US 20200372319A1 · Sun et al. · 2020 [cited by applicant]
US 20200372339A1 · Che et al. · 2020 [cited by applicant]
US 20200372341A1 · Asai et al. · 2020 [cited by applicant]
US 20200380213A1 · Mccann et al. · 2020 [cited by applicant]
US 20210042604A1 · Hashimoto et al. · 2021 [cited by applicant]
US 20210049236A1 · Nguyen et al. · 2021 [cited by applicant]
US 20210073459A1 · Mccann et al. · 2021 [cited by applicant]
US 20210089588A1 · Le et al. · 2021 [cited by applicant]
US 20210089882A1 · Sun et al. · 2021 [cited by applicant]
US 20210089883A1 · Li et al. · 2021 [cited by applicant]
CA 3067013A1 · 2019 [cited by examiner]
CA 3115898A1 · 2019 [cited by examiner]
CA 3117333A1 · 2020 [cited by examiner]
CN 108228757A · 2018 [cited by examiner]
John T. Hancock etc., “Survey on categorical data for neural networks”, published Apr. 10, 2020 in J Big Data 7, 28 (2020), and available at https://doi.org/10.1186/s40537-020-00305-w, retrieved Jan. 22, 2024. (Year: 20… [cited by examiner]
“Chapter 2 Tokenization” from Supervised Machine Learning for Text Analysis in R, published at https://smltar.com/tokenization.html as of Apr. 10, 2020, retrieved Jan. 22, 2024. (Year: 2020). [cited by examiner]
Technical Fridays, “Scaling vs Normalization”, published May 23, 2018 at https://kharshit.github.io/blog/2018/03/23/scaling-vs-normalization, retrieved Jan. 22, 2024. (Year: 2018). [cited by examiner]
Eric Wallace etc., “Interpreting Neural Networks with Nearest Neighbors”, published via the Proceedings of the 2018 EMNLP Workshop BlackboxNLP: Analyzing and Interpreting Neural Networks for NLP, pp. 136-144, Brussels, … [cited by examiner]
Igor Kononenko, etc., “Machine Learning Basics”, chapter in Machine Learning and Data Mining, published in 2007, retrieved Jul. 26, 2024 from https://www.sciencedirect.com/book/9781904275213/machine-learning-and-data-mi… [cited by examiner]
“Label Errors and Confident Learning”, published on Nov. 4, 2019 to https://dcai.csail.mit.edu/2024/label-errors, retrieved Jul. 26, 2024. (Year: 2019). [cited by examiner]
GitHub, “How does the Softmax activation function work?”, published on Jan. 8, 2020 to https://github.com/christianversloot/machine-learning-articles/blob/main/how-does-the-softmax-activation-function-work.md, retrieved… [cited by examiner]
Alvarez-Melis et al., “A causal framework for explaining the predictions of black-box sequence-to-sequence models,” In Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing, 2017, pp. 41… [cited by applicant]
Bastings et al., “In-terpretable neural predictions with differentiable binary variables,” In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, 2019, pp. 2963-2977. [cited by applicant]
Bowman et al., “A large annotated corpus for learning natural language inference,” In Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing ( EMNLP ). Association for Computational Lingu… [cited by applicant]
Brunner et al., “On identifiability in transformers, In International Conference on Learning Representations,” 2020. [cited by applicant]
Chang et al., “A game theoretic approach to classwise selective rationalization,” In Advances in Neural In formation Processing Systems, 2019, pp. 10055-10065. [cited by applicant]
Dagan et al., “The pascal recognising textual entailment challenge,” In Machine Learning Challenges Workshop, 2005, pp. 177-190. [cited by applicant]
Der Maaten et al., “Visualizing data using t-sne,” Journal of machine learning research, 2008, pp. 2579-2605. [cited by applicant]
Devlin et al., “Bert: Pre-training of deep bidirectional transformers for language understanding,” arXiv preprint arXiv:1810.04805, 2018. [cited by applicant]
Frenay et al., “Classification in the presence of label noise: a survey,” IEEE transactions on neural networks and learning systems, vol. 25, No. 5, 2013, pp. 845-869. [cited by applicant]
Grave et al., “Improving neural language models with a continuous cache,” JCLR, 2017b. [cited by applicant]
Grave et al., “Unbounded cache model for online language modeling with open vocabulary,” In Advances in Neural Information Processing Systems, 2017a, pp. 6042-6052. [cited by applicant]
Gu et al., “Search engine guided neural machine translation,” In Thirty-Second AAAI Conference on Artificial Intelligence, 2018. [cited by applicant]
Gururangan et al., “Annotation artifacts in natural language inference data,” arXiv preprint arXiv:1803.02324, 2018. [cited by applicant]
Han et al., “Explaining black box predictions and unveiling data artifacts through influence functions,” arXiv preprint arXiv:2005.06676, 2020. [cited by applicant]
Ioffe et al., “Batch normalization: Accelerating deep network training by reducing internal covariate shift,” arXiv preprint arXiv: 1502.03167, 2015. [cited by applicant]
Jain et al., “Attention is not Explanation,” In Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics: Human Language Technologies, vol. 1 (Long and Short Pape… [cited by applicant]
Jia et al., “Adversarial examples for evaluating reading comprehension systems,” arXiv preprint arXiv:1707.07328, 2017. [cited by applicant]
Johnson et al., “Billion-scale similarity search with gpus,” IEEE Transactions on Big Data, 2019. [cited by applicant]
Kaushik et al., “Learning the difference that makes a difference with counterfactually-augmented data,” In International Conference on Learning Representations, 2020. [cited by applicant]
Khandelwal et al., “Generalization through memorization: Nearest neighbor language models,” ICLR, 2020. [cited by applicant]
Koh et al., “Understanding black-box predictions via influence functions,” In Proceedings of the 34th International Conference on Machine Learning, vol. 70, 2017. pp. 1885-1894. [cited by applicant]
Kurita et al., “Weight poisoning attacks on pre-trained models,” arXiv preprint arXiv:2004.06660, 2020. [cited by applicant]
Lei et al., “Rationalizing neural predictions,” In Proceedings of the 2016 Conference on Empirical Methods in Natural Language Processing, 2016, pp. 107-117. [cited by applicant]
Li et al., “One sentence one model for neural machine translation,” In Proceedings of the Eleventh International Conference on Language Resources and Evaluation (LREC-2018), Miyazaki, Japan. European Languages Resources… [cited by applicant]
Liu et al., “Roberta: A robustly optimized bert pretraining approach,” arXiv preprint arXiv: 1907.11692, 2019. [cited by applicant]
Maas et al., “Learning word vectors for sentiment analysis,” In Proceedings of the 49th Annual Meeting of the Association for Computational Linguistics: Human Language Technologies, 2011, pp. 142-150. [cited by applicant]
McCoy et al., “Right for the wrong reasons: Diagnosing syntactic heuristics in natural language inference,” arXiv preprint arXiv:1902.01007, 2019. [cited by applicant]
Nie et al., “Adversarial nli: A new benchmark for natural language understanding,” arXiv preprint arXiv:1910.14599, 2019. [cited by applicant]
Papernot et al., “Deep k-nearest neighbors: Towards confident,” interpretable and robust deep learning, 2018. [cited by applicant]
Poliak et al., “Hypothesis only baselines in natural language inference,” arXiv preprint arXiv:1805.01042, 2018. [cited by applicant]
Pruthi et al., “Learning to deceive with attention-based explanations,” In Annual Conference of the Association for Computational Linguistics (ACL), 2020. [cited by applicant]
Reimers et al., “Sentencebert: Sentence embeddings using siamese bertnetworks,” arXiv preprint arXiv:1908.10084, 2019. [cited by applicant]
Ribeiro et al., “Anchors: High-precision modelagnostic explanations,” In Thirty-Second AAAI Conference on Artificial Intelligence, 2018. [cited by applicant]
Ribeiro et al., “why should i trust you?” explaining the predictions of any classifier, In Proceedings of the 22nd ACM SIGKDD international conference on knowledge discovery and data mining, 2016, pp. 1135-1144. [cited by applicant]
Sato et al., “Interpretable adversarial perturbation in input embedding space for text,” arXiv preprint arXiv:1805.02917, 2018. [cited by applicant]
Serrano et al., “Is attention interpretable?,” In Proceedings of the 57th Annual Meeting of the Association for Computational Linguistics, 2019, pp. 2931-2951. [cited by applicant]
Singh et al., “Exs: Explainable search using local model agnostic interpretability,” arXiv preprint arXiv:1809.03857, 2018. [cited by applicant]
Wallace et al., “Universal Adversarial Triggers for Attacking and Analyzing NLP,” arXiv preprint arXiv:1908.07125, 2019. [cited by applicant]
Weston et al., “Retrieve and refine: Improved sequence generation models for dialogue,” arXiv preprint arXiv:1808.04776, 2018. [cited by applicant]
Wiegreffe et al., “Attention is not not explanation,” In Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing and the 9th International Joint Conference on Natural Language Processing (… [cited by applicant]
Williams et al., “A broad-coverage challenge corpus for sentence understanding through inference,” In Proceedings of the 2018 Conference of the North American Chapter of the Association for Computational Linguistics: Hu… [cited by applicant]
Zhang et al., “Bertscore: Evaluating text generation with bert,” arXiv preprint arXiv:1904.09675, 2019. [cited by applicant]
Zhao et al., “Reinforced curriculum learning on pretrained neural machine translation models,” arXiv preprint arXiv:2004.05757, 2020. [cited by applicant]
Zhong et al., “Fine-grained sentiment analysis with faithful attention,” arXiv preprint arXiv:1908.06870, 2019. [cited by applicant]