Heterogenous Memory Augmented Neural Networks

Zihan Qiu, Zhen Liu, Shuicheng Yan, Shanghang Zhang, Jie FuarXiv 2023

Abstract

Semi-parametric methods, which combine standard neural networks with non-parametric components such as external memory modules and data retrieval, have shown significant promise in data-scarce and out-of-distribution (OOD) scenarios. However, existing methods often rely on independent raw data points, a strategy that is difficult to scale due to high computational costs and the limitations of current attention mechanisms with large token counts. In this paper, we introduce Heterogeneous Memory Augmentation (HMA), a novel approach that introduces learnable memory tokens with an attention mechanism to boost performance without substantial overhead. Our general-purpose method is architecture-agnostic and can be seamlessly integrated into MLP, CNN, GNN, and Transformer backbones. We evaluate HMA across various image and graph-based tasks, demonstrating competitive performance against state-of-the-art methods in both in-distribution and OOD conditions.

Introduction

Standard neural networks are primarily parametric, meaning their knowledge is stored within fixed weights optimized during training. While effective, these models often struggle when training data is limited or when the test distribution shifts significantly from the training set. Semi-parametric approaches attempt to mitigate these issues by incorporating an external "non-parametric" memory of raw data points.

Despite their potential, current semi-parametric models face a scalability wall. Maintaining and querying a massive external database is computationally expensive, and standard attention mechanisms scale quadratically with the number of tokens. Furthermore, many of these models require extremely large batch sizes to identify meaningful relationships between data points. HMA addresses these challenges by capturing complex data dependencies efficiently across diverse neural architectures.

The Heterogeneous Memory Augmentation (HMA) Framework

The HMA module is a "plug-and-play" framework designed to operate directly on the feature space of a backbone network. It consists of three primary components that work sequentially to enrich the model's representation:

  1. Real Memory Augmentation (RMA): Drawing inspiration from momentum-based contrastive learning, RMA maintains a queue of features from previous data batches. A momentum encoder ensures these features remain stable, while a cross-attention mechanism allows the current input to "read" from this historical buffer.
  2. Synthetic Memory Augmentation (SMA): This stage introduces a set of learnable memory slots. Unlike RMA, these are not raw data points but parameters optimized via gradient descent to capture dataset-wide abstractions.
  3. Attention Between Datapoints (ABD): Within the SMA, the model performs attention not only between the input and memory but also between individual samples in the current batch. This allows the model to leverage the context of other concurrent samples for its predictions.
The HMA framework architecture, illustrating the flow from inputs to outputs through Real and Synthetic Memory modules.

Experimental Results

HMA was evaluated across a diverse set of benchmarks, including image classification (CIFAR, VTAB), graph learning (OGB molecular property prediction), and OOD generalization tasks (Colored MNIST, shifted graph datasets).

  • Image Classification: HMA consistently improved baseline performance. For instance, it boosted a ResNet-18 on CIFAR-10 from 93.9% to 95.54%. On the VTAB benchmark, HMA outperformed state-of-the-art prompt tuning methods for Vision Transformers (ViT), achieving an average accuracy of 89.44%.
  • Graph Learning: On the OGB molecular property benchmark, HMA improved Graph Convolutional Networks (GCN) and Graph Isomorphism Networks (GIN) in 10 out of 12 tested scenarios.
  • OOD Robustness: In challenging OOD graph tasks, such as the Twitter dataset, HMA achieved a 54.58% average accuracy, significantly outperforming specialized OOD algorithms like IRM (53.60%) and CIGA (52.68%).

Insights and Interpretability

A key finding of this research is the power of heterogeneity. Combining real and synthetic memory provides a stable anchor to past data while maintaining the flexibility of task-specific abstractions.

Furthermore, T-SNE visualizations of the learnable synthetic memory slots reveal that they naturally cluster by class. These slots essentially act as "prototypes" that the model references during inference. In OOD scenarios, this memory acts as a support set, allowing the model to use relationships between new inputs and stored prototypes to "re-center" its predictions against distribution shifts.

T-SNE visualization showing that learnable synthetic memory slots (left) naturally cluster by class, mirroring the distribution of data features (right).

Conclusion

HMA provides a scalable and efficient path for semi-parametric learning by replacing massive raw databases with a compact set of learnable tokens. While the method shows the most significant gains on smaller datasets, it offers a robust, architecture-agnostic solution for improving model generalization. Future work will explore more sophisticated initializations for synthetic memory, such as dataset distillation, and the integration of contrastive losses to further enhance feature interpretability.

Summary updated

BibTeX
@misc{qiu2023heterogenous,
  author = {Zihan Qiu and Zhen Liu and Shuicheng Yan and Shanghang Zhang and Jie Fu},
  title = {{Heterogenous Memory Augmented Neural Networks}},
  year = {2023},
  eprint = {2310.10909},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.10909},
}
Figure