Source-linked AI summary

Transformers generalize differently from information stored in context vs in weights

Stephanie C. Y. Chan, Ishita Dasgupta, Junkyung Kim, Dharshan Kumaran, Andrew K. Lampinen, Felix Hill

arXiv:2210.05675v2cs.CLcs.AIcs.LG

TL;DR

The paper asks whether transformers generalize differently from information in their weights and information supplied in context. It tests rule-based and exemplar-based generalization with controlled classification tasks and pretrained language models. Generalization from synthetic-data weights is rule-based, synthetic-data in-context generalization is largely exemplar-based, and pretrained language models show increasingly rule-based in-context generalization with scale.

  • Problem

    Transformers use information stored in weights and information supplied in context, but their inductive biases across these sources need to be understood to assess how they use each.

    Source: §1 · p. 1
  • Method

    The paper uses held-out classification tasks to distinguish sparse rule-based generalization from similarity-based exemplar generalization across synthetic-data and pretrained language models.

    Source: §1 · p. 1, §3.3 · p. 4
  • Results

    Synthetic-data transformers generalize rule-wise from weights and largely by exemplars from context, while pretrained language models show increasingly rule-based in-context generalization with scale.

    Source: §4 · pp. 4–5
  • Takeaways & Limitations

    The findings suggest that natural language’s combinatorial structure may provide learning pressure for rule-like generalization, and that controlled rule-based pretraining can induce it in context.

    Source: §3.3 · p. 4, §4 · p. 5

    Increasing synthetic-model depth, attention heads, or classes did not produce the scale effect; the authors could not determine whether this reflected insufficient scale or an interaction with training data.

    Source: §3.3 · p. 4

Abstract

from arXiv · show

Transformer models can use two fundamentally different kinds of information: information stored in weights during training, and information provided ``in-context'' at inference time. In this work, we show that transformers exhibit different inductive biases in how they represent and generalize from the information in these two sources. In particular, we characterize whether they generalize via parsimonious rules (rule-based generalization) or via direct comparison with observed examples (exemplar-based generalization). This is of important practical consequence, as it informs whether to encode information in weights or in context, depending on how we want models to use that information. In transformers trained on controlled stimuli, we find that generalization from weights is more rule-based whereas generalization from context is largely exemplar-based. In contrast, we find that in transformers pre-trained on natural language, in-context learning is significantly rule-based, with larger models showing more rule-basedness. We hypothesise that rule-based generalization from in-context information might be an emergent consequence of large-scale training on language, which has sparse rule-like structure. Using controlled stimuli, we verify that transformers pretrained on data containing sparse rule-like structure exhibit more rule-based generalization.

1 Introduction

The paper examines how transformers generalize from information in their weights versus information provided in context, distinguishing rule-based from exemplar-based behavior. It reports stronger rule-based generalization from in-context information in large language-pretrained transformers.

1 Introduction

  • The paper asks how transformers’ inductive biases differ between information stored in weights and information supplied in context.Understanding this difference matters for how information is represented and used.Source: §1 · p. 1
  • Rule-based generalization uses minimal features supporting a category boundary, whereas exemplar-based generalization relies on similarity to observed examples.The paper adapts a held-out-data classification paradigm to distinguish these behaviors.Source: §1 · p. 1
  • Large language-pretrained transformers show stronger rule-based generalization from in-context information.The authors suggest natural language’s rule-compatible structure may provide learning pressure that overcomes transformers’ contextual exemplar bias.Source: §1 · p. 2

2 Experimental Design

The experiments use partial exposure classification to distinguish generalization by a sparse rule from generalization by similarity to examples. They compare models trained on controlled synthetic data with pretrained language models using in-context information.

2 Experimental Design

  • The partial exposure task presents three two-feature combinations and tests generalization on a held-out combination.The stimuli are AX, AW, and BW, with BX held out; the task can be presented in training or in context.Source: Figure 1 · p. 2, §2 · p. 2
  • A rule-based model classifies the held-out item using a parsimonious boundary based on Feature 1, while an exemplar model compares similarity across features.For BX, equal similarity to AX and BW makes the exemplar model equally likely to choose either label.Source: Figure 1 · p. 2
  • The study tests transformers trained on controlled synthetic data and pretrained language models, then compares their generalization patterns and possible explanatory factors.The controlled experiments examine both in-weights and in-context generalization; the pretrained-model experiments characterize in-context generalization.Source: §2 · p. 2

3 Results

Transformers trained from scratch generalize by rules from weights but by exemplars from context, while pretrained language models show rule-based in-context generalization; explicit rule-requiring pretraining also yields rule-based generalization.

3.1 Trained-from-scratch transformers

  • From scratch, transformers generalized by a sparse rule from weights but compared directly with all-feature examples when using in-context information.The held-out combination elicited fully rule-based generalization from weights and fully exemplar-based generalization from context.Source: §3.1 · p. 3, Figure 2 · p. 3

3.2 Pretrained language models

  • Pretrained language models showed rule-based in-context generalization along either predictive feature, compared with the corresponding control condition.The control provides a baseline for exemplar-based generalization.Source: Figure 3 · p. 4, §3.2 · p. 4
  • Smaller language models were less rule-based; the 1B model effectively used exact exemplar-based generalization.The reported comparisons included 1B and 7B models.Source: §3.2 · p. 4, Figure 3 · p. 4

3.3 In-context generalization can be made more rule-based with pre-training.

  • Synthetic sequences requiring rule-based classification produced rule-based generalization to held-out sequences, supporting the hypothesis that sparse rule-like language structure contributes to larger LMs’ behavior.Scratch-model scale increases did not produce the same effect; the authors suggest insufficient scale or synergy between scale and training-data type as possible explanations.Source: §3.3 · p. 4

4 Conclusions

Transformers show distinct generalization patterns for information stored in weights versus context: synthetic-data models are rule-based from weights but mostly exemplar-based from context. Pretrained language models are increasingly rule-based from context as model size grows, and controlled pretraining on rule-based data can induce that pattern.

4 Conclusions

  • On synthetic data, generalization is rule-based from weights but almost entirely exemplar-based from context.Pretrained language models, by contrast, are rule-based when generalizing from in-context information.Source: §4 · pp. 4–5
  • Larger pretrained language models show more rule-based in-context generalization.The conclusion describes this pattern as increasingly true for larger models.Source: §4 · p. 5
  • Pretraining on an explicitly rule-based classification problem can induce rule-based generalization from in-context information.The authors say these findings support the possibility that natural language’s combinatorial nature supplies learning pressure toward rule-like generalization, in concert with model scale.Source: §4 · p. 5

A Experiment details: Trained-from-scratch transformers

The experiment compares generalization from context with generalization from weights using held-out stimulus combinations. The figure shows how the model is trained and how its choices distinguish rule-based from exemplar-based biases.

A Experiment details: Trained-from-scratch transformers

  • Each sequence contains a context of 12 stimulus-label pairs followed by a query stimulus, and training minimizes loss on the query prediction.The context-learning model is pretrained on few-shot sequences with randomly chosen stimulus classes and labels.Source: Figure 4 · p. 6
  • For context-based evaluation, a held-out BX combination tests whether choices follow the B-associated label or balance the labels associated with A and B.The former indicates a rule-based bias; the latter indicates exemplar-based bias because BX is equally similar to AX and BW.Source: Figure 4 · p. 6
  • For weights-based evaluation, the model is trained directly on partial-exposure data and tested on the held-out combination, with context irrelevant to query prediction.Stimuli comprise two concatenated subvectors, each sampled around a class centroid.Source: Figure 4 · p. 6

A.1 Subvector stimuli

Stimuli are built by concatenating two subvectors, each drawn from a class-specific distribution, to form a 64-dimensional input. The design balances features while varying their classes and sampling parameters.

A.1 Subvector stimuli

  • Each stimulus concatenates two subvectors, with each subvector belonging to a class characterized by its own centroid.A stimulus class is the combination of two subvector classes.Source: §A.1 · pp. 6–7
  • Subvectors are sampled from multivariate normal distributions centered on their class centroids.The design generalizes the 2-D classification example to 64 dimensions and ensures no a priori bias toward either feature.Source: §A.1 · pp. 6–7
  • Each stimulus has 2 features of length 32, with 10 classes per feature and 100 values per class; covariance scaling is 0.1.Source: §A.1 · p. 7

A.2 Pretraining for few-shot learning

Few-shot pretraining uses 4-shot, 3-way sequences with randomly assigned classes and labels. Each context repeats three stimulus classes four times, and the query belongs to one of those classes.

A.2 Pretraining for few-shot learning

  • Pretraining sequences are 4-shot and 3-way, with three stimulus classes each repeated four times in the context.Source: §A.2 · p. 7
  • The query class is one of the three classes shown in the context.Source: §A.2 · p. 7
  • Stimulus classes and labels are randomly assigned for each sequence.Source: §A.2 · p. 7

A.3 Evaluating inductive biases

The evaluation procedures include controls for label-selection bias and a separate pretraining setup designed to favor rule-based generalization.

A.3 Evaluating inductive biases

  • Models were trained and evaluated using the procedures shown in Figures 4b and 4d.Source: §A.3 · p. 7
  • An additional label and examples distinguish similarity-based selection from chance, and the partial-exposure data also included in-weights training.Source: §A.3 · p. 7
  • BW appeared twice as often to avoid label-frequency bias, and omitting its repetition produced the same result pattern.Source: §A.3 · p. 7

A.4 Pretraining for rule-based generalization

  • For rule-based pretraining, BX always received the label associated with BW in context, with stimuli and labels randomly assigned.Source: §A.4 · p. 7

A.5 Architecture, training, and evaluation details

The appendix specifies the model configuration and training resources, along with how evaluation outputs and error bars were computed.

  • Models used 12 layers, 64-dimensional embeddings, Adam, batch size 32, and 16 TPUv3 plus 4 V100 GPU cores per experiment.Each experiment ran for 200,000 training steps.Source: §A.5 · p. 7
  • Evaluation outputs in Figure 2 average the final 100,000 of 200,000 training steps.Source: §A.5 · p. 7
  • Error bars show 1.96 standard errors across 10 training runs, with zero variance for Figures 2a and 2c.Source: §A.5 · p. 7

B Experiment details: Large language model experiments

The large-language-model experiments used text-based shape and color features, tested several stimulus wordings, and reported results across model sizes and feature sets.

Loading 2210.05675v2…