[Paper Review] Explaining and Improving Model Behavior with k Nearest Neighbor Representations
This paper proposes using k nearest neighbors (kNN) over deep neural network hidden representations to interpret and improve NLP model behavior, particularly in Natural Language Inference (NLI). By retrieving training examples most similar to a test input, kNN explains predictions, uncovers spurious correlations, identifies mislabeled data, and boosts model robustness—achieving state-of-the-art performance on adversarial and augmented NLI datasets without updating model parameters.
Interpretability techniques in NLP have mainly focused on understanding individual predictions using attention visualization or gradient-based saliency maps over tokens. We propose using k nearest neighbor (kNN) representations to identify training examples responsible for a model's predictions and obtain a corpus-level understanding of the model's behavior. Apart from interpretability, we show that kNN representations are effective at uncovering learned spurious associations, identifying mislabeled examples, and improving the fine-tuned model's performance. We focus on Natural Language Inference (NLI) as a case study and experiment with multiple datasets. Our method deploys backoff to kNN for BERT and RoBERTa on examples with low model confidence without any update to the model parameters. Our results indicate that the kNN approach makes the finetuned model more robust to adversarial inputs.
Motivation & Objective
- To develop a model-agnostic method for interpreting NLP model behavior at scale, beyond individual prediction explanations.
- To identify and diagnose spurious correlations and mislabeled examples in NLI datasets using kNN retrieval of training instances.
- To improve model robustness by dynamically backing off to kNN predictions when the fine-tuned model is uncertain.
- To provide corpus-level interpretability by identifying highly influential training examples through kNN neighbor analysis.
- To demonstrate that kNN over representations can yield better decision boundaries than deep models alone, especially on adversarial inputs.
Proposed method
- kNN is applied to the hidden representations of fine-tuned BERT and RoBERTa models to retrieve the k most similar training examples for each test input.
- A confidence threshold is used at inference time to decide whether to use the model’s prediction or back off to the kNN prediction.
- The kNN approach is computationally efficient using FAISS for vector search, enabling scalability to large datasets.
- kNN is used to analyze misclassified examples, revealing patterns of spurious correlations and potential mislabeled training instances.
- The method is applied across multiple NLI datasets, including SNLI, MNLI, ANLI, and HANS, with ablation and fine-grained analysis on syntactic and lexical patterns.
- kNN predictions are interpolated with model predictions to improve generalization and robustness, especially on challenging examples.
Experimental results
Research questions
- RQ1Can kNN over hidden representations provide a scalable, model-agnostic method for interpreting NLP model behavior at the corpus level?
- RQ2How effective is kNN in uncovering spurious correlations and mislabeled examples that lead to model failure?
- RQ3Does backoff to kNN predictions improve model robustness on adversarial and out-of-distribution examples?
- RQ4Can kNN retrieve training examples that explain why a model made a specific prediction, offering more faithful interpretability than attention or saliency maps?
- RQ5To what extent does kNN improve performance on NLI benchmarks, especially on difficult or augmented data?
Key findings
- kNN backoff significantly improves performance on augmented SNLI and ANLI, with BERT achieving 0.95 and 0.96 F1 respectively, outperforming standard fine-tuned models.
- On the HANS benchmark, kNN improves RoBERTa’s F1 on the difficult 'not-entail' class from 52.7% to 54.7%, demonstrating enhanced robustness.
- kNN retrieval of misclassified examples frequently identifies mislabeled training instances, enabling data quality diagnosis.
- The kNN model learns a more fine-grained decision boundary than the base model, making it more robust to small perturbations that flip model predictions.
- kNN achieves approximately 300× faster inference than influence functions on small datasets, with increasing speedup on larger datasets.
- Visualizations show that kNN predictions align better with human-annotated rationales, especially on syntactic and lexical patterns like negation and subsequence matching.
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.