On Provable Length and Compositional Generalization

Kartik Ahuja, Amin Mansouri · OpenReview

TL;DR

This paper provides the first theoretical guarantees for length and compositional generalization in common sequence-to-sequence models like Transformers and RNNs. It shows that limited-capacity versions of these models can achieve these crucial out-of-distribution generalization abilities, provided the training data is sufficiently diverse. This work offers a foundational understanding of why and when these models succeed or fail at generalizing beyond their training data.

What Problem Does This Paper Address?

Modern sequence-to-sequence models, especially large language models, have shown remarkable capabilities. However, their failures, particularly in reasoning and planning, have raised questions about whether they truly learn general algorithms or merely memorize patterns. Two critical aspects of out-of-distribution (OOD) generalization are:

  1. Length Generalization: The ability to handle sequences longer than those seen during training.
  2. Compositional Generalization: The ability to combine known components (tokens) in novel ways not encountered during training.

While there's extensive empirical work on OOD generalization, a theoretical understanding of these phenomena in sequence-to-sequence models has been lacking. This paper aims to bridge this gap by providing provable guarantees for these generalization capabilities across various popular architectures.

Methods

The authors tackle this problem by first defining a formal framework for length and compositional generalization. They then analyze several common sequence-to-sequence architectures: deep sets, transformers, state-space models (SSMs), and recurrent neural networks (RNNs). The core of their approach involves:

  • Provable Guarantees: Deriving theoretical conditions under which these models achieve generalization.
  • Limited Capacity Analysis: Focusing on simplified, limited-capacity versions of these architectures to make theoretical analysis tractable. This often involves assumptions about the structure of the hypothesis class (e.g., single-layer perceptrons for certain components).
  • Linear Identification: A key finding is that for generalization to occur, the learned hidden representations must be linearly related to the true hidden representations of the labeling function.
  • Chain-of-Thought (CoT) Supervision: Investigating how providing intermediate computations as privileged information during training can enable generalization, especially for higher-capacity models.
  • Structured vs. General Hypothesis Classes: The analysis is divided into two parts: one with strong structural assumptions on the architectures and another with weaker assumptions, requiring more data diversity.

Datasets

The paper does not introduce new datasets. Instead, it focuses on theoretical analysis and uses synthetic data generated according to specific distributions to test the models. The experiments described in Appendix B use synthetic datasets designed to evaluate length and compositional generalization.

Key Insights and Ideas

  • Provable Generalization for Core Architectures: The paper provides the first theoretical guarantees for length and compositional generalization for deep sets, transformers, SSMs, and RNNs. This is a significant step towards understanding their OOD capabilities.
  • Linear Identification is Key: A recurring theme is that for generalization to occur, the learned internal representations must be a linear transformation of the true representations used by the underlying labeling function. This suggests that models that learn to "linearly identify" the true data-generating process are more likely to generalize.
  • Limited Capacity is Sufficient (with Diversity): For simplified versions of these architectures, achieving both length and compositional generalization is possible, provided the training data distribution exhibits sufficient diversity. This implies that even relatively simple models can generalize if trained appropriately.
  • CoT Supervision as a Powerful Tool: Chain-of-thought supervision acts as a form of privileged information that can help even high-capacity models overcome limitations and achieve length generalization. This aligns with the intuition that providing intermediate reasoning steps can guide learning.
  • High Capacity Models Can Fail: The paper highlights that for highly expressive models (high capacity), there's a risk of learning "incorrect" solutions that fit the training data but fail to generalize. This is because the hypothesis class can contain both the correct generalizing solution and incorrect, non-generalizing solutions.

Key Results

  • Theoretical Guarantees: The paper presents several theorems (e.g., Theorem 4, 6, 8, 9) that establish conditions for length and compositional generalization for different architectures under specific assumptions (e.g., limited capacity, realizability, data diversity).
  • Linear Relationship: Empirically (Table 1, Table 2), the learned hidden representations are shown to have a strong linear relationship with the true hidden representations, supporting the theoretical findings on linear identification.
  • Small Test Loss: Experiments show that models trained on sequences up to length T=10 achieve very small test losses even on much longer sequences, demonstrating length generalization (Figure 2).
  • Transformer Success: A transformer model trained on sequences up to length T=10 generalizes well to sequences of length up to 100 (Figure 3).
  • Failure Cases Illustrated: The paper demonstrates failure cases for highly expressive models where training on shorter sequences leads to poor generalization on longer ones, especially when the generative function introduces an offset (Figure 4, Table 3).

Limitations and Future Work

  • Realizability Assumption: Many of the theoretical results rely on the realizability assumption (i.e., the true labeling function is within the hypothesis class). Adapting these to non-realizable cases is a significant future direction.
  • Optimization Bias: The analysis often considers all possible solutions to risk minimization. In practice, optimization algorithms (like gradient descent) might be biased towards a subset of solutions. Understanding how this bias impacts generalization is an open question.
  • Softmax Attention: While the paper discusses transformers, the theoretical results for them do not directly incorporate softmax attention, which is common in practice. Adapting the framework to handle softmax attention is suggested.
  • High Capacity Models: The paper shows that high-capacity models can fail, but a more nuanced argument about whether gradient descent reaches these failing solutions is left for future work.
  • Discrete Tokens: While some extensions are made, the primary theoretical framework often assumes continuous token supports. Extending the results to more general discrete token settings is an area for further research.
  • General Framework for Non-Realizable Cases: Developing a more general framework that captures non-realizable length and compositional generalization guarantees is a promising avenue.

Summary updated

BibTeX
@inproceedings{ahuja2024provable,
  author = {Kartik Ahuja and Amin Mansouri},
  title = {{On Provable Length and Compositional Generalization}},
  booktitle = {TF2M @ ICML},
  year = {2024},
  url = {https://openreview.net/forum?id=xuwtmXiHMT},
}
Figure