Improving in-context learning with a better scoring function

Omar Naim, Swarnadeep Bhar, Jérôme Bolte, Nicholas Asher · DOI

Abstract

In-context learning (ICL) is a cornerstone of modern Transformer models, yet these architectures often struggle to generalize on logical or mathematical tasks when test distributions shift. This research identifies the Softmax scoring function as a primary cause of these failures, citing its tendency toward "attention collapse." We propose Scaled Signed Averaging (SSA), a trainable polynomial-based scoring function designed to replace the exponential Softmax. SSA prevents models from prematurely focusing on single tokens, resulting in a 12.6% perplexity improvement in GPT-2 and significant performance boosts on reasoning-heavy benchmarks like SuperGLUE.

Introduction: The Softmax Bottleneck

Despite the success of large language models, they frequently fail at basic semantic tasks—such as distinguishing "every" from "some"—and mathematical functions when presented with out-of-distribution data. This "generalization gap" is largely attributed to the attention mechanism's reliance on the Softmax operation.

Softmax uses an exponential function that is inherently aggressive. If one token receives a slightly higher score, Softmax pushes its weight toward 1 while suppressing others toward 0. This "concentration effect" forces the model to ignore broader context, focusing only on the "loudest" token. While effective for simple retrieval, this behavior is detrimental to tasks requiring global information integration.

Attention collapse in a logical task where the model focuses on a single outlier token, leading to an incorrect output.

Methodology: Scaled Signed Averaging (SSA)

To address these limitations, we introduce Scaled Signed Averaging (SSA) as a drop-in replacement for Softmax. SSA employs a parameterized polynomial form:

$$x \to (1 + b|x|)^{\text{sgn}(x)n}$$

where $b$ and $n$ are trainable parameters. This approach offers several key advantages:

  1. Polynomial Growth: Unlike exponentials, polynomials grow slowly, preventing the "winner-take-all" dynamics that lead to attention collapse.
  2. Self-Regularizing Gradients: The mathematical structure of SSA naturally suppresses gradients for extreme inputs, enhancing numerical stability.
  3. Provable Non-Collapse: Theoretical analysis confirms that SSA cannot collapse into a "hardmax" for finite parameter values, ensuring the model maintains sensitivity to the entire sequence.

Experimental Evaluation

We evaluated SSA across synthetic ICL tasks, large-scale pre-training (GPT-2 on 10B tokens), and linguistic probing.

Synthetic and Logic Tasks

In tasks requiring relational inference, SSA showed significant improvements. For example, in "Every/Some" logic tasks, the model must verify every token in a sequence. SSA's slower decision-making allows for better integration of these distributed cues.

Generalization in Linear Regression

SSA demonstrated superior robustness to distribution shifts. In synthetic linear regression tasks, SSA maintained low error rates even when input values were an order of magnitude larger than those seen during training. In contrast, Softmax-based models failed immediately under such shifts.

SSA performance on linear regression tasks, showing the model's ability to maintain the underlying function under distribution shift.

Large-Scale Benchmarks

When applied to a 124M parameter GPT-2 model, SSA achieved a perplexity of 27.7 on OpenWebText, a 12.6% improvement over the Softmax baseline (31.7). On the SuperGLUE benchmark, SSA delivered dramatic jumps in zero-shot accuracy:

  • CommitmentBank (CB): 22.5% (Softmax) to 58.5% (SSA).
  • Winograd Schema Challenge (WSC): 31.8% (Softmax) to 41.3% (SSA).

Discussion and Conclusion

The "Softmax bottleneck" represents a fundamental architectural constraint on model reasoning. By replacing it with the more flexible SSA, we enable Transformers to better integrate contextual information and generalize to novel distributions. SSA adds negligible parameter overhead (only 288 parameters for a 12-layer model) and maintains training efficiency. Future work will explore the impact of SSA on long-context models and its potential to reduce hallucinations by preventing overconfidence in specific tokens.

Summary updated

BibTeX
@inproceedings{naim2026improving,
  author = {Omar Naim and Swarnadeep Bhar and Jérôme Bolte and Nicholas Asher},
  title = {{Improving in-context learning with a better scoring function}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2026},
  doi = {10.18653/v1/2026.acl-long.1385},
}
Figure