Beyond Transformers for Function Learning

Simon Segert, Jonathan D. CohenCogSci 2023

TL;DR

This paper introduces two cognitive science-inspired inductive biases – a "Relational Bottleneck" and an "Adaptive Attention Window" – to enhance transformer models' ability to extrapolate simple scalar functions. The proposed "Relational Transformer" significantly improves performance over standard transformers, demonstrating that incorporating human-like reasoning mechanisms can boost AI's generalization capabilities.

What Problem Does This Paper Address?

Humans excel at learning simple functions from a few examples and then extrapolating them to new, unseen domains. This ability, known as function learning and extrapolation, has been a long-standing challenge for artificial intelligence, particularly for neural networks that often require vast amounts of data to achieve similar performance. While recent transformer architectures have shown promise in interpolating functions, their ability to extrapolate remains limited, especially when compared to human capabilities. This paper aims to bridge this gap by investigating how to imbue transformer models with inductive biases that mimic human reasoning, specifically focusing on how to improve their extrapolation performance on scalar functions.

Methods

The authors propose augmenting the standard transformer architecture with two key inductive biases:

  • Relational Bottleneck: Inspired by models of abstract reasoning, this bias forces the model to focus on the relationships between function values rather than the raw values themselves. Instead of directly predicting the next function value, the model predicts a "similarity profile" – the relationships between the new point and all previous points. This is achieved by constructing a similarity matrix (using negative Euclidean distance) of the observed function values and feeding this matrix, along with positional information, into the transformer. The model is then trained to predict the next row of this similarity matrix.
  • Adaptive Attention Window: This bias is inspired by cognitive models that assume function values depend only on nearby preceding values. It's implemented by introducing a learnable mask that limits the attention mechanism's scope. Instead of attending to all previous inputs, the model's attention is adaptively weighted based on the distance between inputs, allowing it to learn the most effective interaction length scale.

The paper also highlights a collateral benefit: the Relational Transformer, by predicting similarity profiles, naturally yields uncertainty estimates without additional computational overhead, unlike standard transformer models.

Datasets

The models were trained on a dataset of 320,000 curves, comprising lines, sinusoids, and Radial Basis Function (RBF) curves. These curves were sampled with varying parameters (slopes, periods, amplitudes, phases) and had random uniform noise added. For evaluation, 2,500 new curves were sampled, and extrapolation was performed up to 10 steps autoregressively.

Key Insights and Ideas

  • Cognitive Biases Enhance Extrapolation: The core insight is that incorporating inductive biases inspired by human cognitive processes can significantly improve a transformer's ability to generalize beyond its training data, particularly for function extrapolation.
  • Relational Reasoning is Key: Forcing the model to reason about relationships between data points (via the similarity matrix) rather than just raw values appears crucial for better extrapolation. This mirrors how humans might abstract rules.
  • Adaptive Attention is Beneficial: Learning an appropriate "window" for attention, rather than using a fixed or all-encompassing scope, helps the model focus on relevant information and improves performance.
  • Uncertainty Estimation as a Byproduct: The Relational Transformer's approach to predicting similarity profiles naturally leads to uncertainty estimates, a valuable feature often missing in standard transformer models for this task.
  • Synergy of Biases: Combining both the Relational Bottleneck and the Adaptive Attention Window yielded the best performance, suggesting that these biases are complementary and work best together.

Key Results

  • Both the Relational Bottleneck and the Adaptive Attention Window individually improved extrapolation accuracy (measured by mean square error) compared to a baseline 1d transformer.
  • The combined model, the "Relational Transformer with learned window," achieved the best overall extrapolation performance across all curve types.
  • The Relational Transformer showed improved performance on linear and sine curves compared to a baseline transformer that compensated for poor linear performance with gains on sines and RBFs.
  • The Relational Transformer provided uncertainty estimates, which were found to be reasonably well-calibrated, though with some under/overestimation tendencies for different curve types.

Limitations and Future Work

  • Similarity Function Choice: The paper used negative Euclidean distance as the similarity measure. It's acknowledged that exploring learned similarity functions directly from data, rather than pre-specifying them, would be an interesting future direction.
  • Invertible Similarity Requirement: The current method for recovering raw function values from predicted similarity profiles relies on an invertible similarity function. Relaxing this constraint to accommodate non-invertible functions is a potential area for future research.
  • Comparison with Human Data: While the model's performance is compared to general human abilities, a more direct comparison of the learned window parameter with estimated window lengths from human data would be valuable.

Summary updated

BibTeX
@inproceedings{segert2023beyond,
  author = {Simon Segert and Jonathan D. Cohen},
  title = {{Beyond Transformers for Function Learning}},
  booktitle = {CogSci},
  year = {2023},
  url = {https://openreview.net/forum?id=7Tu8ITO2QCJ},
}
Figure