Positional Encoding and Prompt-Order Sensitivity in In-Context Learning

Zhijie Wang, Bo Jiang, Shuai LiNeurIPS 2026

TL;DR

Give a Large Language Model a handful of examples in a prompt, and it learns a new task on the fly—until you shuffle the order of those examples, and its performance suddenly tanks. This paper provides the first mathematical explanation for why this happens, pointing the finger directly at Positional Encodings (PE). By proving a universal $O(k/N)$ scaling law, the authors show that while swapping $k$ examples destabilizes predictions, feeding the model a longer context ($N$) predictably dilutes the chaos.

What Problem Does This Paper Address?

In-context learning (ICL) feels a bit like magic: you drop a few input-output examples into a prompt, and a Transformer figures out the pattern without updating a single weight. Yet, early empirical studies revealed a bizarre quirk: simply shuffling the order of those examples can swing a model's performance from state-of-the-art to near-random guessing.

From first principles, this shouldn't happen. At its core, the self-attention mechanism is permutation equivariant—it treats inputs like an unordered bag of vectors. The culprit that breaks this symmetry is Positional Encoding (PE), the mathematical stamps we add to tokens so the model knows word order. While we need PE for language to make sense, nobody had rigorously derived how different PEs cause prompt-order sensitivity in ICL, or how that sensitivity behaves across tasks where order shouldn't matter versus tasks where it really does.

Methods

To crack open this black box, the authors build a theoretical framework around a simplified, analytically tractable cousin of standard attention: a single Linear Self-Attention (LSA) layer (which drops the non-linear softmax).

What’s novel here is how they frame prompt shuffling using group theory. Given $N$ in-context examples, they measure the size of a prompt shuffle using Cayley distance ($k$)—the minimum number of pairwise swaps needed to turn the original prompt into the shuffled one.

They then derive mathematical upper bounds on how much the model's final query prediction shifts under two classic ways of injecting position:

  1. One-hot PE (Absolute): Concatenating a simple position-indicator vector to each token.
  2. RoPE (Rotary/Relative): Rotating query and key vectors in space by angles proportional to their positions, used in modern workhorses like LLaMA and Qwen. For RoPE, they introduce a novel metric, $\Theta_{\text{RoPE}}(\pi)$, which tracks the accumulated rotational phase shift caused by shuffling examples.

Datasets

To validate their math, the authors test across three setups (no new benchmarks were introduced):

  • Synthetic Linear Regression ($d=10$): An order-invariant task ($y = \mathbf{w}^\top \mathbf{x}$) using Gaussian inputs, where shuffling examples shouldn't change the underlying rule at all.
  • Synthetic Dynamical Systems ($d=2$): An order-sensitive time-series task ($\mathbf{x}_{i+1} = A\mathbf{x}_i + \boldsymbol{\xi}_i$) mimicking next-token prediction, where token sequence carries vital temporal history.
  • Subj Dataset: A real-world sentence-classification benchmark (classifying text as subjective vs. objective), used to test pretrained Qwen2.5-Instruct models (0.5B, 1.5B, and 7B).

Key Insights and Ideas

  • The Universal $k/N$ Dilution Law: Whether a task cares about order (dynamical systems) or not (linear regression), prediction sensitivity scales as $O(k/N)$. More swaps ($k$) linearly increase prediction drift, while adding more context examples ($N$) acts as a buffer, diluting the impact of a fixed number of swaps.
  • RoPE’s High-Dimensional Achilles' Heel: While both PEs obey the $k/N$ trend, their constants tell a surprising story. In linear regression, One-hot PE's error bound scales linearly with input dimension $d$, whereas RoPE scales with $d^{2.5}$ (and $d^{3.5}$ in dynamical systems!). Because RoPE mixes positions by rotating feature pairs, higher-dimensional spaces amplify prompt-order instability.
  • Attention Creates Sensitivity; MLPs Propagate It: Standard Multi-Layer Perceptrons (MLPs) process each token column independently, making them naturally permutation-equivariant. Attention is the sole engine generating cross-example order sensitivity; MLPs just scale that perturbation by their Lipschitz constants as it travels up the network.

Key Results

Theory and practice line up remarkably well. Training single-layer linear transformers for 200,000 steps, the authors plotted expected output change $\mathbb{E}[|\Delta \hat{y}|]$ against $1/N$ and $k$. The empirical points snap cleanly onto linear trendlines, confirming the $O(k/N)$ bounds.

Figure 1: Experimental results on linear regression tasks. Left column: output change dependence on N −1. Right column: output change dependence on k. Top row: one-hot positional encoding. Bottom row: RoPE.

Even when stepping outside their theoretical assumptions to test multi-billion-parameter Qwen2.5 models on the Subj dataset, the qualitative law holds. Fixing $N=10$ and increasing swaps $k$ from 2 to 8 steadily drives up the "prediction-change rate" (how often the model flips its classification label—climbing from ~20% to ~27% on the 0.5B model). Conversely, fixing $k=2$ and growing context $N$ from 4 to 10 drops the flip rate across all model sizes (e.g., from ~20% down to ~5% on the 1.5B model).

Limitations and Future Work

The core mathematical proofs rely on single-layer linear attention, leaving out the non-linear softmax attention and multi-layer depth of production LLMs. As the authors note in their discussion, softmax changes the game when attention isn't diffuse: if a model places heavy attention weight on one specific example, moving just that single token could trigger an $O(1)$ prediction swing, bypassing the $1/N$ dilution effect. Extending these displacement-based proofs to concentrated softmax regimes, multi-layer Lipschitz bounds, and other PE families (like ALiBi) is the natural next step.

Summary updated

Abstract

Transformer models have demonstrated a remarkable ability to perform a wide range of tasks through in-context learning (ICL), where the model infers patterns from a small number of example prompts provided during inference. However, empirical studies have shown that the effectiveness of ICL can be significantly influenced by the order in which these prompts are presented. Despite its significance, this phenomenon has been largely unexplored from a theoretical perspective. In this paper, we theoretically investigate how positional encoding (PE) affects the ICL capabilities of linear attention transformer models, particularly in tasks where prompt order plays a crucial role. We examine two distinct cases: linear regression, which represents an order-invariant task, and dynamical systems, a classic time-series task that is inherently sensitive to the order of input prompts. Theoretically, we evaluated the change in the model output when two types of positional encoding (one-hot and RoPE) is incorporated and the prompt order is altered. In all cases, the leading dependence on the permutation size and context length is $k/N$, with constants determined by the positional encoding, model weights, input dimension, and task dependent parameters. These theoretical findings are experimentally validated.
BibTeX
@inproceedings{wang2026positional,
  author = {Zhijie Wang and Bo Jiang and Shuai Li},
  title = {{Positional Encoding and Prompt-Order Sensitivity in In-Context Learning}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2026},
  url = {https://openreview.net/forum?id=ZJxEzyLoXN},
}
Figure