Skip to main content
QUICK REVIEW

[Paper Review] $k$-Nearest Neighbor Augmented Neural Networks for Text Classification

Zhiguo Wang, Wael Hamza|arXiv (Cornell University)|Aug 25, 2017
Topic ModelingComputer Science21 references12 citations
TL;DR

This paper proposes kNN-augmented neural networks for text classification by integrating instance-level information from k-nearest neighbors (kNN) of input texts as an external memory. The model combines neural network embeddings with attention-weighted kNN features—improving accuracy over strong baselines, especially under data scarcity and class imbalance, and outperforming a 29-layer deep network on several benchmarks.

ABSTRACT

In recent years, many deep-learning based models are proposed for text classification. This kind of models well fits the training set from the statistical point of view. However, it lacks the capacity of utilizing instance-level information from individual instances in the training set. In this work, we propose to enhance neural network models by allowing them to leverage information from $k$-nearest neighbor (kNN) of the input text. Our model employs a neural network that encodes texts into text embeddings. Moreover, we also utilize $k$-nearest neighbor of the input text as an external memory, and utilize it to capture instance-level information from the training set. The final prediction is made based on features from both the neural network encoder and the kNN memory. Experimental results on several standard benchmark datasets show that our model outperforms the baseline model on all the datasets, and it even beats a very deep neural network model (with 29 layers) in several datasets. Our model also shows superior performance when training instances are scarce, and when the training set is severely unbalanced. Our model also leverages techniques such as semi-supervised training and transfer learning quite well.

Motivation & Objective

  • Address the limitation of standard neural networks in capturing instance-level information from individual training examples, despite strong statistical generalization.
  • Overcome the failure of deep neural networks to correct misclassifications caused by spurious word-level signals (e.g., 'IBM' strongly associated with 'Sci/Tech' in training data).
  • Integrate non-parametric kNN-based instance-level knowledge with parametric neural network learning to improve prediction robustness.
  • Demonstrate effectiveness in low-data regimes, class-imbalanced settings, and transfer/semi-supervised learning scenarios.

Proposed method

  • Use a neural network encoder to embed input texts and their k-nearest neighbors (kNN) from the training set into a shared embedding space.
  • Treat the kNN of each input as an external memory, applying a multi-perspective attention mechanism to weigh each neighbor based on relevance to the input.
  • Compute an attentive kNN label distribution and an attentive kNN text embedding using attention weights over the kNN neighbors.
  • Combine three features for final prediction: input text embedding, attentive kNN label distribution, and attentive kNN text embedding.
  • Enable semi-supervised and transfer learning by using kNN from a different dataset (e.g., DBPedia) as external memory for a target task (e.g., AG’s News).
  • Train end-to-end with cross-entropy loss, allowing the model to learn both the encoder and attention weights jointly.

Experimental results

Research questions

  • RQ1Can integrating kNN-based instance-level information improve the performance of neural network models in text classification, especially when standard models fail due to spurious word associations?
  • RQ2How does the proposed kNN-augmented model perform compared to strong baselines and deep networks (e.g., 29-layer networks) under standard, low-data, and imbalanced training conditions?
  • RQ3To what extent can the kNN-augmented model benefit from semi-supervised and transfer learning setups using external kNN memory from different datasets?
  • RQ4Does the attention mechanism over kNN neighbors effectively retrieve relevant training instances that correct model errors caused by statistical bias?

Key findings

  • The proposed model outperforms the BiLSTM baseline on all standard benchmark datasets tested, including AG’s News, DBPedia, and 20 Newsgroups.
  • On several datasets, the kNN-augmented model surpasses a very deep 29-layer neural network, demonstrating the value of instance-level memory over depth alone.
  • The model shows superior performance under data scarcity, maintaining high accuracy even when training instances are limited.
  • The model achieves significant gains in imbalanced datasets, correcting misclassifications caused by dominant class bias.
  • In semi-supervised learning, using kNN from the DBPedia dataset as external memory improved performance over the BiLSTM baseline.
  • In transfer learning, leveraging kNN from a different task (DBPedia) with distinct label definitions still improved performance on AG’s News, showing robustness and generalization.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.