Gradient-based inference of abstract task representations for generalization in neural networks

Ali Hummos, Felipe del Río, Brabeeba Mien Wang, Julio Hurtado, Cristian Buc Calderon, Guangyu Robert Yang · OpenReview

Abstract

Humans and many animals show remarkably adaptive behavior and can respond differently to the same input depending on their internal goals. The brain not only represents the intermediate abstractions needed to perform a computation but also actively maintains a representation of the computation itself (task abstraction). Such separation of the computation and its abstraction is associated with faster learning, flexible decision-making, and broad generalization capacity. We investigate if such benefits might extend to neural networks trained with task abstractions. For such benefits to emerge, one needs a task inference mechanism that possesses two crucial abilities: First, the ability to infer abstract task representations when no longer explicitly provided (task inference), and second, manipulate task representations to adapt to novel problems (task recomposition). To tackle this, we cast task inference as an optimization problem from a variational inference perspective and ground our approach in an expectation-maximization framework. We show that gradients backpropagated through a neural network to a task representation layer are an efficient heuristic to infer current task demands, a process we refer to as gradient-based inference (GBI). Further iterative optimization of the task representation layer allows for recomposing abstractions to adapt to novel situations. Using a toy example, a novel image classifier, and a language model, we demonstrate that GBI provides higher learning efficiency and generalization to novel tasks and limits forgetting. Moreover, we show that GBI has unique advantages such as preserving information for uncertainty estimation and detecting out-of-distribution samples.

Introduction

A fundamental hallmark of biological intelligence is the ability to switch contexts seamlessly. A human can categorize a set of images by color, shape, or semantic function depending on their current goal. In contrast, traditional Artificial Neural Networks (ANNs) typically employ a static computational graph that entangles input processing with the task itself. This entanglement leads to two major hurdles: the difficulty of identifying context from data alone (task inference) and the inability to combine previously learned abstractions to solve novel problems without extensive retraining, often resulting in "catastrophic forgetting."

We propose that these limitations can be overcome by separating the computation from its abstraction. By maintaining an internal representation of the goal—a task abstraction—networks can more flexibly guide how sensory input is processed.

Methods: Gradient-Based Inference (GBI)

The core of our approach is Gradient-Based Inference (GBI). We cast task inference as an optimization problem grounded in a variational inference and Expectation-Maximization (EM) framework.

The architecture introduces a dedicated task representation layer ($Z$). During an initial training phase, the model is provided with explicit task labels to learn these abstractions. At test time, when labels are missing, the model uses the error gradient of its own prediction to update $Z$. Essentially, the model asks: "What task representation would make my current prediction most accurate?"

Graphical model and inference dynamics of GBI.

We demonstrate that a one-step gradient update is an efficient and highly effective heuristic for identifying the task. For more complex, novel problems, iterative optimization allows the model to "recompose" abstractions, adapting to new data without modifying the underlying network weights ($\theta$).

Results and Discussion

We validated GBI across three distinct domains: synthetic sequence prediction, image classification/generation (MNIST, CIFAR-100), and language modeling (BabyLM).

Efficiency and Modularity

In sequence prediction tasks, GBI-LSTM models achieved significantly lower Mean Squared Error (MSE) than standard LSTMs. Furthermore, GBI naturally encourages structural modularity. Analysis of the network revealed that GBI-LSTM separated neurons into task-specific groups, whereas standard LSTMs exhibited high overlap in neuronal activity, making them prone to interference.

Performance efficiency and structural modularity of GBI-LSTM.

Generalization and Robustness

GBI showed remarkable performance in zero-shot and few-shot scenarios. In MNIST experiments, GBI achieved 85.46% accuracy with a single gradient pass, nearly matching a dedicated classifier. Additionally, GBI proved superior at detecting Out-of-Distribution (OOD) samples. When trained on MNIST and tested on FashionMNIST, GBI achieved an AUCROC of 0.89, significantly higher than standard softmax-based methods (0.73).

In language modeling, GBI-LSTM could accurately infer the specific dataset context (e.g., Wikipedia vs. children's stories) after seeing only a few words, leading to improved training and validation efficiency.

Conclusion

GBI provides a principled framework for neural networks to infer and manipulate task abstractions. By using gradients as real-time sensors of environmental demands, models can achieve biological-like flexibility, learning faster and adapting more robustly to novel tasks. Future work will focus on the unsupervised discovery of these task abstractions and scaling the framework to larger architectures.

Summary updated

BibTeX
@misc{hummos2024gradient,
  author = {Ali Hummos and Felipe del Río and Brabeeba Mien Wang and Julio Hurtado and Cristian Buc Calderon and Guangyu Robert Yang},
  title = {{Gradient-based inference of abstract task representations for generalization in neural networks}},
  year = {2024},
  eprint = {2407.17356},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.17356},
}
Figure