Skip to main content
QUICK REVIEW

[Paper Review] DNN or k-NN: That is the Generalize vs. Memorize Question

Guy Cohen, Guillermo Sapiro|arXiv (Cornell University)|May 17, 2018
Neural Networks and ApplicationsComputer Science27 references13 citations
TL;DR

This paper investigates how deep neural networks (DNNs) simultaneously generalize and memorize by comparing their predictions to k-NN, SVM, and logistic regression classifiers applied to learned feature representations. It finds that DNNs approximate k-NN decisions in the embedding space when they generalize, but diverge from k-NN behavior upon memorization—indicating that memorization and generalization coexist and are complementary, not contradictory.

ABSTRACT

This paper studies the relationship between the classification performed by deep neural networks (DNNs) and the decision of various classical classifiers, namely k-nearest neighbours (k-NN), support vector machines (SVM) and logistic regression (LR), at various layers of the network. This comparison provides us with new insights as to the ability of neural networks to both memorize the training data and generalize to new data at the same time, where k-NN serves as the ideal estimator that perfectly memorizes the data. We show that memorization of non-generalizing networks happens only at the last layers. Moreover, the behavior of DNNs compared to the linear classifiers SVM and LR is quite the same on the training and test data regardless of whether the network generalizes. On the other hand, the similarity to k-NN holds only at the absence of overfitting. Our results suggests that k-NN behavior of the network on new data is a sign of generalization. Moreover, it shows that memorization and generalization, which are traditionally considered to be contradicting to each other, are compatible and complementary.

Motivation & Objective

  • To investigate the coexistence of memorization and generalization in deep neural networks, traditionally viewed as conflicting properties.
  • To analyze how DNNs' decision boundaries compare to classical classifiers (k-NN, SVM, LR) across network layers to understand the mechanisms of generalization and memorization.
  • To determine whether k-NN behavior in the feature space serves as a signature of generalization versus memorization in DNNs.
  • To identify when and where memorization occurs in the network architecture, particularly in relation to training dynamics and overfitting.
  • To explore whether the alignment between DNN predictions and k-NN decisions can serve as an indicator of generalization performance.

Proposed method

  • Train standard DNNs (Wide-ResNet, LeNet, MLP) on CIFAR-10/100 and MNIST with and without data augmentation and regularization to control overfitting.
  • Extract feature representations from each hidden layer and apply k-NN, SVM, and logistic regression classifiers to these embeddings.
  • Compare the DNN’s softmax output distribution to the predictions of the classical classifiers using Kullback-Leibler (KL) divergence as a metric.
  • Track the KL divergence between the DNN’s prediction and each classical classifier’s prediction (k-NN, SVM, LR) on both training and test sets throughout training.
  • Define memorization as the point where training accuracy first reaches 100%, and analyze the divergence of KL divergence trends between training and test sets at this point.
  • Use the probability of agreement (P_SAME) between DNN and k-NN predictions to quantify the degree of k-NN-like behavior during training.

Experimental results

Research questions

  • RQ1Does the behavior of a DNN’s predictions align with k-NN decisions in the learned feature space, and under what conditions?
  • RQ2How does the similarity between DNN predictions and classical classifiers (k-NN, SVM, LR) evolve during training, especially in relation to generalization and memorization?
  • RQ3At which layers of the network does memorization primarily occur, and how does this relate to the network’s generalization performance?
  • RQ4Can the divergence of KL divergence trends between training and test sets for k-NN vs. DNN serve as an indicator of overfitting or memorization?
  • RQ5Is k-NN behavior in the DNN’s feature space a sign of generalization, and does it disappear upon memorization of random labels or overfitting?

Key findings

  • DNNs exhibit k-NN-like behavior in their feature space only when they generalize well; this alignment breaks down upon memorization.
  • The KL divergence between DNN and k-NN predictions maintains consistent trends on training and test sets during generalization, but diverges after memorization, especially in the test set.
  • For deep networks trained on real data, the probability of DNN and k-NN making the same prediction approaches 100% at the end of training, indicating strong k-NN approximation.
  • Memorization occurs primarily at the final layers of the network, as evidenced by the sudden rise in training accuracy to 100% and the divergence of KL divergence trends.
  • When training on randomized labels, the KL divergence between DNN and k-NN predictions diverges on training and test sets immediately after memorization, confirming overfitting.
  • The consistency of KL divergence trends between training and test sets for k-NN vs. DNN serves as a reliable indicator of generalization, with divergence signaling overfitting.

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.