Skip to main content
QUICK REVIEW

[Paper Review] The Dual Form of Neural Networks Revisited: Connecting Test Time Predictions to Training Patterns via Spotlights of Attention

Kazuki Irie, Róbert Csordás|arXiv (Cornell University)|Feb 11, 2022
Adversarial Robustness in Machine LearningComputer Science5 citations
TL;DR

This paper revisits the dual form of linear layers in neural networks, expressing them as unnormalized dot attention over all training data points and initial weights. By computing attention weights at test time, it enables direct visualization of which training patterns influence predictions, revealing interpretable, context-sensitive connections between inputs and outputs in both vision and language tasks, despite computational constraints on scale.

ABSTRACT

Linear layers in neural networks (NNs) trained by gradient descent can be expressed as a key-value memory system which stores all training datapoints and the initial weights, and produces outputs using unnormalised dot attention over the entire training experience. While this has been technically known since the 1960s, no prior work has effectively studied the operations of NNs in such a form, presumably due to prohibitive time and space complexities and impractical model sizes, all of them growing linearly with the number of training patterns which may get very large. However, this dual formulation offers a possibility of directly visualising how an NN makes use of training patterns at test time, by examining the corresponding attention weights. We conduct experiments on small scale supervised image classification tasks in single-task, multi-task, and continual learning settings, as well as language modelling, and discuss potentials and limits of this view for better understanding and interpreting how NNs exploit training patterns. Our code is public.

Motivation & Objective

  • To reinterpret trained neural network linear layers as attention mechanisms over the entire training dataset, enabling direct traceability of test-time predictions to training patterns.
  • To explore whether attention weights in this dual formulation can reveal meaningful, human-interpretable relationships between test inputs and specific training examples.
  • To evaluate the feasibility and interpretability of this approach in small-scale image classification and language modeling tasks.
  • To investigate how attention patterns reflect semantic and structural similarity between test queries and training data, especially in few-shot or out-of-distribution generalization.
  • To assess the limitations of this method in terms of memory, computation, and applicability to already-trained models.

Proposed method

  • Expresses the forward pass of a linear layer in a deep neural network as unnormalized dot attention over all training input-output pairs, treating them as keys and values.
  • Uses the test input as a query to compute attention scores across all training patterns, with attention weights indicating relevance.
  • Records inputs to linear layers during training and computes attention weights at inference time to link test predictions to training data.
  • Applies the method to feedforward networks on MNIST and Fashion-MNIST, and to LSTMs on text datasets like WikiText-2 and Aesop’s Fables.
  • Visualizes top-attending training tokens or image patches to assess whether attention aligns with semantic or structural similarity.
  • Employs a key-value mechanism where keys are training inputs, values are training targets, and queries are derived from test inputs.

Experimental results

Research questions

  • RQ1Can attention weights in the dual form of a neural network's linear layer reveal which specific training examples contribute most to a test prediction?
  • RQ2Do the most attended training patterns exhibit semantic or structural similarity to the test input, indicating contextual reasoning?
  • RQ3How does the dual-form attention mechanism behave across different learning scenarios, such as single-task, multi-task, and continual learning?
  • RQ4Can this approach explain generalization in large models, such as zero-shot translation or few-shot reasoning, by identifying source training examples?
  • RQ5What are the practical limitations of this method in terms of memory, computation, and applicability to real-world models?

Key findings

  • In image classification, the model's attention at test time consistently focused on training examples with similar class labels and visual patterns, even in multi-task and continual learning settings.
  • For language modeling, the top-attending training passages were semantically and structurally similar to the test query, such as warship-related texts when querying about an ironclad.
  • Negative examples with similar sentence structure but unrelated content received low attention, indicating that attention is context-aware and not merely syntactic.
  • The method successfully visualized attention over entire training experiences, revealing interpretable connections between test inputs and training data in both vision and language tasks.
  • Despite high memory and computational costs, the approach demonstrated feasibility on small-scale datasets, suggesting potential for larger models as hardware improves.
  • The analysis is not applicable to already-trained models, as it requires logging inputs to linear layers during training, limiting retrospective analysis.

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.