Transformers with Signatures: Towards Universal In-Context Learning in Path Space

Ziheng Cheng, Xin Guo, Ben HamblyarXiv 2026

TL;DR

Transformers are famously good at learning on the fly from a few examples—a magic trick called in-context learning (ICL)—but we have struggled to guarantee how or why this works when the inputs are messy, continuous time-series paths rather than static vectors. By pairing standard transformers with path signatures—a mathematical tool that turns nonlinear geometric trajectories into linear features—the authors prove that a compact transformer can learn complex, path-dependent functions in context, even when the examples are statistically tangled up over time. Better yet, it beats bigger, raw-data transformers on financial and dynamical tasks while remaining unfazed by irregular sampling grids.

What Problem Does This Paper Address?

Imagine showing a model a few examples of stock price trajectories paired with the payouts of an undisclosed exotic financial option, then handing it a new trajectory and asking: What’s the payout here?

To solve this via in-context learning (ICL)—adapting dynamically from the prompt without updating model weights—we hit two walls in existing theory:

  1. Nonlinearity in path space: Most theoretical explanations of ICL assume simple linear regression on static vectors. Real-world time series involve outcomes that depend nonlinearly on the entire geometric history of a path.
  2. Broken IID assumptions: Standard ICL theory assumes examples are independent and identically distributed (IID). In reality, prompt demonstrations are often consecutive slices of the same ongoing process (like sequential market windows), meaning they share temporal and statistical dependencies.

Furthermore, letting neural networks learn path representations from scratch creates black-box features that lack clear geometric meaning and break down if sensor sampling rates suddenly change.

Methods

The authors bridge algebraic topology and modern LLMs by feeding path signatures into a causal softmax transformer.

  • The Classic Tool (Path Signatures): A path signature is a sequence of iterated integrals of a continuous path. Its superpower is universal nonlinearity: any continuous, nonlinear function of a path can be approximated arbitrarily well by a simple linear combination of its signature coordinates. This effectively linearizes a deeply nonlinear problem.
  • The Novel Construction (In-Context Lasso): Because signature spaces grow exponentially with truncation depth, finding the right linear combination requires sparsity (Lasso regression). While prior theoretical ICL papers relied on simplified toy mechanisms (like linear, unmasked, or ReLU attention), the authors explicitly construct a standard causal masked softmax transformer—the exact engine inside frontier LLMs—that emulates iterative proximal-gradient steps for Lasso.
Figure 1: Attention computation at position t. The query and key vectors determine the attention scores through their inner products. The causal mask restricts each token to information from itself and preceding tokens. Each head forms a weighted average of the corresponding value vectors; the head outputs are summed and added to ht, as in eq. (2.3).

In each optimization layer, two softmax attention heads use query-key inner products to compute prediction residuals and approximate the squared-loss gradient step, while the ReLU MLP performs exact soft-thresholding and coordinate clipping. Stacking these layers solves Lasso in context, backed by finite-sample error bounds that explicitly allow statistical dependence across demonstrations (verified for dissipative diffusions, CIR short-rate models, and long-memory fractional Ornstein–Uhlenbeck processes).

Datasets

The authors evaluate their framework (TF-Sig) against raw-path transformers (TF-Raw-Flat and TF-Raw-Seq) and single-task Lasso-Sig across three synthetic benchmarks and one real-world financial dataset:

  • Sparse Signature Recovery: Synthetic 5D Brownian motion paths testing exact support recovery of sparse linear signature functionals.
  • Controlled Differential Equations (CDEs): Synthetic paths from a 5D Ornstein–Uhlenbeck process driving a nonlinear CDE, tested across uniform and irregular observation grids.
  • Optimal Execution: Synthetic trading-rate schedules (from Gaussian processes) modeling transient price impact, trained on exponential kernels and tested out-of-distribution (OOD) on unseen power-law kernels.
  • Real-World Crypto Option Payoffs: 5-minute cumulative log-return paths built from Binance Public Data transaction records. Training uses 2023 data (BTC, ETH, BNB, SOL, XRP, ADA), while validation and testing use unseen crypto assets from 2024 and 2025 to infer undisclosed Asian and variance option payoffs.

Key Insights and Ideas

  • Geometry meets attention: Lead-lag path signatures naturally encode financial quantities like realized quadratic variation (variance) as exact linear combinations of second-order terms. Handing these pre-baked geometric features to the transformer relieves it from learning path calculus from scratch.
  • Free grid-invariance: Because signatures are defined via path integrals, TF-Sig naturally handles missing data, coarser sampling, or irregular timestamps without architectural gymnastics.
  • Why not just run Lasso? If signatures linearize the problem, why bother with a transformer? When signature truncation is too shallow to fully linearize a target function, pure Lasso-Sig struggles. The transformer provides crucial extra nonlinear expressivity and leverages cross-task priors learned during pre-training.

Key Results

Across all tasks, TF-Sig matches or outperforms raw-data transformers using substantially fewer trainable parameters:

  • Sparse Recovery: TF-Sig achieves a 0.988 F1 score at training context length $N=128$, and extrapolates zero-shot to unseen lengths, hitting 1.000 F1 at $N=512$.
  • Grid Robustness (CDEs): On in-distribution grids, TF-Sig reaches an $R^2$ of 0.85 (MSE 0.160), crushing TF-Raw-Seq ($R^2$ 0.64) and TF-Raw-Flat ($R^2$ 0.30), and maintains the lowest MSE across all coarser and nonuniform test grids.
  • Unseen Market Regimes (Optimal Execution): Under OOD shift to unseen non-singular and singular power-law kernels ($N=32$), TF-Sig achieves $R^2$ scores of 0.963 and 0.990, beating TF-Raw-Seq while using 39.8% fewer parameters (0.126M vs. 0.209M).
  • Real Market Option Payoffs: On held-out 2025 crypto assets ($N=16$), TF-Sig cuts MSE by 70.2% compared to the best raw baseline (0.033 vs. 0.112) with 33.4% fewer parameters. Extrapolating to $N=32$ drops MSE further to 0.023 (vs. 0.467 for standalone Lasso-Sig), driven largely by massive accuracy gains on variance options.

Limitations and Future Work

While the paper does not feature a standalone limitations section, several theoretical and practical constraints are noted in the analysis:

  • Exponential Feature Growth: Truncated signature dimensions grow exponentially with depth ($P = (d+1)^M$). Consequently, statistical guarantees rely on sparsity assumptions, and high-dimensional paths or deep truncations can quickly inflate embedding sizes.
  • Theoretical Depth Scaling: To guarantee an arbitrarily small transformer approximation error $\epsilon_{\mathrm{TF}}$, the constructive proof requires $\mathcal{O}(\epsilon_{\mathrm{TF}}^{-3})$ layers—a worst-case theoretical bound much deeper than the compact 2-to-12 layer networks that succeed empirically.
  • Long-Range Dependence Sample Costs: For fractional processes in the long-memory regime (Hurst parameter $H > 1/2$), slow covariance decay degrades concentration rates to $N^{2-2H}$, requiring more in-context demonstrations to achieve the same error bounds.

Summary updated

BibTeX
@misc{cheng2026transformers,
  author = {Ziheng Cheng and Xin Guo and Ben Hambly},
  title = {{Transformers with Signatures: Towards Universal In-Context Learning in Path Space}},
  year = {2026},
  eprint = {2611.31439},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.31439},
}
Figure