Jane Street Proves RoPE and ALiBi Exhaust Positional Encodings
Jane Street
Lie group theory applied to translation-invariant attention proves that all linear mechanisms reduce to matrix exponentials, confirming existing designs like RoPE and ALiBi leave no viable architectures undiscovered.
By formulating query and key transformations under continuous time and enforcing translation invariance, positional encodings reduce to a group homomorphism mapping time addition to matrix multiplication, whose unique solution is the matrix exponential A(t) = e^(tX). (28:27)
Linear algebra completely classifies the possible behaviors of positional encodings into three regimes: exponential growth/decay via real eigenvalues, planar rotations via complex conjugate pairs (RoPE), and polynomial shifts via defective Jordan blocks (ALiBi). (69:15)
RoPE corresponds to the pure imaginary diagonalizable case where real decay is set to zero, deploying a geometric frequency spectrum across orthogonal 2D subspaces to prevent phase aliasing across sequence lengths. (52:21)
ALiBi's linear logit penalty is algebraically recovered by non-diagonalizable 2x2 Jordan blocks acting on augmented coordinate channels, confirming that common empirical positional encodings already exhaust the mathematically viable options. (69:15)
Detailed notes
## Background
Published on YouTube by Jane Street on August 26, 2026, this discussion features Grant Sanderson of 3Blue1Brown and Alok Puranik, a researcher at Jane Street. Based on Alok's Jane Street blog post, the two use group theory and representation theory to analyze the foundational mathematical assumptions behind transformer positional encodings.
## TL;DR
Grant Sanderson and Alok Puranik investigate how positional information can be rigorously introduced into transformer attention mechanisms by framing queries and keys as continuous-time functions. By enforcing translation invariance and linear transformations, they prove that the positional interaction forms a group homomorphism from scalar time addition to matrix multiplication, uniquely yielding matrix exponential solutions $e^{tX}$. Analyzing the generator matrix $X$ reveals that real eigenvalues model exponential decay or growth, complex conjugate pairs produce the 2D planar rotations found in Rotary Positional Embeddings (RoPE), and defective non-diagonalizable Jordan blocks generate the linear distance penalties used in Attention with Linear Biases (ALiBi). Ultimately, this mathematical taxonomy demonstrates that existing positional encoding architectures naturally exhaust the primary stable mathematical possibilities.
## Atmosphere & style
The conversation carries the relaxed, intellectually playful vibe of an informal chalk-talk between two deeply curious mathematicians. Sanderson plays the engaged sounding board and intuitive foil to Puranik's structured, rigorous derivations, frequently celebrating mathematical beauty and asking pointed questions about whether the abstraction reveals unmapped model designs. Supported by clean visual intuition, the session feels like a collaborative exploration where theoretical curiosity meets practical machine learning engineering.
## Bulletin
- [28:27](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1707s) By formulating query and key transformations under continuous time and enforcing translation invariance, positional encodings reduce to a group homomorphism mapping time addition to matrix multiplication, whose unique solution is the matrix exponential A(t) = e^(tX).
- [01:09:15](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4155s) Linear algebra completely classifies the possible behaviors of positional encodings into three regimes: exponential growth/decay via real eigenvalues, planar rotations via complex conjugate pairs (RoPE), and polynomial shifts via defective Jordan blocks (ALiBi).
- [52:21](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3141s) RoPE corresponds to the pure imaginary diagonalizable case where real decay is set to zero, deploying a geometric frequency spectrum across orthogonal 2D subspaces to prevent phase aliasing across sequence lengths.
- [01:09:15](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4155s) ALiBi's linear logit penalty is algebraically recovered by non-diagonalizable 2x2 Jordan blocks acting on augmented coordinate channels, confirming that common empirical positional encodings already exhaust the mathematically viable options.
## Key takeaways
- [01:30](https://www.youtube.com/watch?v=k86eUj4hgdc&t=90s) Standard attention mechanisms do not pre-bake temporal order, leaving sequence relationships completely unconstrained unless positional awareness is injected into the linear-algebraic pipeline.
- [03:54](https://www.youtube.com/watch?v=k86eUj4hgdc&t=234s) Framing sequence position as a continuous parameter t accommodates irregular real-world time series, physical systems, state-space models like Mamba, and allows the use of differential calculus.
- [05:58](https://www.youtube.com/watch?v=k86eUj4hgdc&t=358s) Applying separate linear maps F(t) and G(s) to individual queries and keys preserves linear computational scaling per token, rather than incurring quadratic costs across all token pairs.
- [12:08](https://www.youtube.com/watch?v=k86eUj4hgdc&t=728s) Enforcing relative translation invariance reduces the two-variable transformation family to a single-parameter matrix function A(t - s) = F(t)^T G(s).
- [14:47](https://www.youtube.com/watch?v=k86eUj4hgdc&t=887s) Anchoring zero displacement to the identity matrix A(0) = I loses no generality, as any invertible base matrix can be absorbed uniformly into key definitions via a time-independent change of basis.
- [20:45](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1245s) The algebraic identity f(t)^T = g(t)^(-1) establishes the group homomorphism A(s)A(t) = A(s + t), mapping addition in the time domain directly to matrix composition.
- [28:27](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1707s) Differentiating the group homomorphism at zero yields the matrix differential equation A'(s) = A(s)X, which admits the unique closed-form solution A(s) = e^(sX) generated by matrix X.
- [33:28](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2008s) Under complex diagonalization, the transition matrix decomposes into uncoupled 1D and 2D subspaces, reducing multi-dimensional attention dynamics to independent scalar products.
- [38:41](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2321s) Real eigenvalues produce exponential growth or exponential decay, the latter being the core mechanism utilized in linear attention architectures and recurrent models.
- [44:08](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2648s) Pairs of complex conjugate eigenvalues yield planar rotations, directly generating Rotary Positional Embedding (RoPE) when the real scaling factor is zero.
- [55:04](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3304s) RoPE utilizes a wide geometric sequence of frequencies to balance fine-grained distinction of adjacent tokens with long-range tracking without phase wrapping aliasing.
- [58:59](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3539s) Non-diagonalizable matrices featuring nilpotent Jordan blocks truncate the matrix exponential Taylor series, producing polynomial time dynamics such as constant-velocity linear shifts.
- [01:09:15](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4155s) Augmenting query and key vectors with auxiliary coordinates through a 2x2 Jordan block algebraically reconstructs the linear logit penalty used in ALiBi.
- [01:13:42](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4422s) Higher-order Jordan blocks yield quadratic or cubic distance penalties that offer little practical empirical value, indicating that existing literature has largely exhausted the primary viable positional mechanisms.
## Detailed walkthrough
### [00:00](https://www.youtube.com/watch?v=k86eUj4hgdc&t=0s) Representation Theory in Positional Encodings
Grant Sanderson opens by welcoming Alok Puranik and introducing the topic: Alok’s recent Jane Street blog post examining transformer positional encodings through the lens of group theory. When Grant asks what initially prompted this line of inquiry, Alok explains that his routine reading of deep learning literature kept surfacing various ad-hoc positional encodings proposed across different architectures. The undisputed standard is RoPE (Rotary Positional Embedding), which encodes sequence positions by rotating pairs of coordinates within query and key vectors. To anyone with a background in abstract algebra, turning an additive group—like the integers $(\mathbb{Z}, +)$ or real numbers $(\mathbb{R}, +)$ representing time—into a structured matrix operator immediately evokes representation theory.
Alok realized this was not an isolated quirk of RoPE. A parallel pattern appears in linear attention models, where instead of applying rotations to coordinate pairs, position is encoded by exponentially decaying older hidden states over time. Both mechanisms take an additive shift in time and map it homomorphically into linear operations on vector spaces. As Alok reflects on his initial motivation: “It felt like it couldn't be a coincidence that like two very popular methods came from this same like said both had this algebraic structure and now then the natural question is like maybe all of the methods have this algebraic structure is there some like what's the kind of the minimal set of assumptions that gives you this and like do they seem like reasonable assumptions something like that.”
- RoPE maps temporal offsets directly into 2D block-diagonal rotation matrices.
- Linear attention architectures substitute rotations with exponential decay factors over historical values.
- Representation theory formalizes how abstract algebraic groups (such as time translations) act linearly on vector spaces via matrix transformations.
[01:30](https://www.youtube.com/watch?v=k86eUj4hgdc&t=90s) What Must It Be? The Achilles' Heel of Attention
Grant highlights what made Alok’s post stand out: while machine learning papers typically introduce encodings as heuristic choices that happen to work well empirically, Alok approached the problem from first principles by asking “what *must* it be?” Grant pulls up an illustration from his own 3Blue1Brown video on transformers—joking about the "shameless plug"—to review the baseline mechanics of self-attention. When a model processes a sequence such as *"a fluffy blue creature roamed the verdant forest,"* the words *"fluffy"* and *"blue"* need to direct their attention toward the noun *"creature"*. This interaction is mediated by projecting embedding vectors into queries and keys and computing their dot products.
The fundamental strength of raw attention is that it does not hardcode sequence order. It leaves the relationship between tokens entirely unconstrained so the network can learn arbitrary patterns of interaction. Yet this flexibility is also its primary weakness. As Grant points out: “The beauty of the attention mechanism is that it kind of doesn't pre-bake time.” He continues: “It doesn't say, 'Hey, you should necessarily weight the stuff that came right before.' It's agnostic to that. It's like that should all be learned. But that's also the like the Achilles' heel on it because you want some way of knowing, hey, position matters.” Because the attention score is computed strictly through inner products and matrix transformations, any positional awareness must somehow be injected directly into that linear-algebraic pipeline.
```mermaid
flowchart LR
accTitle: Position Encoding Workflow in Attention
accDescr: Queries and keys are modified by position-dependent functions before computing dot product attention scores.
subgraph Tokens["Input Sequence"]
T1["Query Token at time t"]
T2["Key Token at time s"]
end
subgraph Modifiers["Positional Modification"]
T1 -->|"project"| Q["q(t)"] -->|"f(t, q)"| Qt["q̃(t)"]
T2 -->|"project"| K["k(s)"] -->|"g(s, k)"| Kt["k̃(s)"]
end
subgraph Scoring["Attention Score"]
Qt --> DP["Dot Product ⟨q̃(t), k̃(s)⟩"]
Kt --> DP
end
```
[03:54](https://www.youtube.com/watch?v=k86eUj4hgdc&t=234s) Continuous Time Framing and the Finance Connection
Moving to the whiteboard, Alok formalizes the problem. Instead of adopting the standard natural language processing notation of discrete token vectors $Q_1, Q_2, \dots, Q_N$, he chooses to define queries and keys as continuous functions of time: $q(t)$ and $k(s)$, bounded on some interval $0 \le t, s \le T$. Grant interrupts with a side question about whether this continuous framing reflects how quantitative researchers in finance at Jane Street conceptualize sequential data, given that financial market data arrives asynchronously rather than in neat, discrete word tokens.
Alok acknowledges that real-world time series are rarely as cleanly spaced or uniformly discrete as text, but notes that continuous framing is valuable far beyond finance. For instance, continuous formulations naturally accommodate data-dependent decay rates and align with state-space models like Mamba. As Alok observes: “Well, I guess when you're modeling like real world time series, they're not always so cleanly like discrete or as regular.” He adds: “I do also think when you're modeling like kind of real world like physical phenomena it is actually quite nice to say time is continuous we just sample it in some points that we could care for.” If discrete indices are desired, one simply restricts $t$ and $s$ to integer values.
- Queries and keys are modeled as vector-valued functions over continuous time: $q(t), k(t) \in \mathbb{R}^d$.
- Discrete sequence models represent the special case where $t \in \mathbb{Z}$.
- Continuous time models cleanly handle irregular tick data, physical systems, and state-space architectures like Mamba.
[05:58](https://www.youtube.com/watch?v=k86eUj4hgdc&t=358s) Factoring Positional Modifications: Efficiency over $O(N^2)$ Pairwise Tweaks
Alok turns to the attention computation between a query at time $t$ and a key at time $s$. He explicitly ignores the value vectors, noting that because they are only interested in how the attention weights and scores are calculated, the values are irrelevant to the mathematical derivation. In standard attention, the score between $q(t)$ and $k(s)$ is given by the inner product $q(t)^T k(s)$. However, this raw dot product contains no explicit knowledge of time or sequence distance; if the model encounters identical key vectors at distinct timestamps, say $k(0) = k(1)$, the query cannot tell them apart.
To inject positional awareness, one must define functions to modify the vectors:
$$\tilde{q}(t) = f(t, q(t))$$
$$\tilde{k}(s) = g(s, k(s))$$
In the original Attention Is All You Need transformer, these functions simply added fixed sinusoidal positional encodings, whereas in RoPE they apply orthogonal rotations. Alok notes an important architectural constraint: they deliberately apply separate transformations to each of the $N$ queries and keys individually rather than transforming all $N^2$ possible query-key pairs directly. Altering every pair independently would explode computational complexity from linear to quadratic in the embedding transformations. Grant laughs in appreciation of making that foundational engineering trade-off explicit: “I admire your acknowledgement of broad generality here because that's like a pretty reasonable assumption.” Alok sums up the strategy: “It seems like just cleaner to say like, 'Okay, we're just going to go like modify every query exactly once and modify every key exactly once.'”
[08:53](https://www.youtube.com/watch?v=k86eUj4hgdc&t=533s) Restricting Arbitrary Positional Functions to Linear Maps
Alok Puranik and Grant Sanderson begin by examining the inner product between the transformed, time-aware query and key vectors: $\tilde{q}(t)^T \tilde{k}(s)$. Grant notes that while they have merely added twiddles to the original expression, the core intuition is that these representations are now sensitive to their positions in time. However, Alok emphasizes that as initially written, the formulation is impossible to analyze because the transformations $f$ and $g$ are completely arbitrary functions that could behave terribly.
```mermaid
flowchart LR
accTitle: Attention Inner Product with Linear Maps
accDescr: Pipeline showing how raw query and key vectors are multiplied by time-dependent matrices and combined into a bilinear form.
subgraph Inputs["Original Vectors"]
Q["q(t)"]
K["k(s)"]
end
subgraph Transforms["Time-Dependent Matrices"]
F["F(t)"]
G["G(s)"]
end
subgraph InnerProduct["Bilinear Pairing"]
Dot["q(t)ᵀ F(t)ᵀ G(s) k(s)"]
end
Q --> F
K --> G
F --> Dot
G --> Dot
```
To make progress, Alok introduces the crucial simplifying restriction: linearity. Working in an inner product space, linear maps represent the natural mathematical objects to explore. Alok acknowledges that justifying linearity rigorously is subtle, but practical evidence supports it: “In practice, the fact that like nothing that I found in practice was using nonlinear maps anywhere made me more confident that like no one will be too sad about making this assumption and so it's probably just fine.” Grant validates this step, remarking that assuming $f$ takes the form of a matrix dependent on $t$ applied to $q$ feels entirely reasonable in context.
By constraining $f$ and $g$ to linear maps, they replace arbitrary infinite-dimensional function spaces with indexed families of matrices, $F(t)$ and $G(s)$. In a $d$-dimensional vector space, this collapses unconstrained mappings down to $d^2$ values for each matrix. The resulting dot product expands into a structured quadratic form:
$$q(t)^T F(t)^T G(s) k(s)$$
Alok points out that the central product, $F(t)^T G(s)$, completely packages the pairing between queries at time $t$ and keys at time $s$.
---
[12:08](https://www.youtube.com/watch?v=k86eUj4hgdc&t=728s) Translation Invariance and the Shift Matrix $A(t - s)$
With linearity established, Alok turns to what he calls the primary driver of their mathematical derivations: translation invariance. Positional encodings should depend solely on the relative distance between tokens, not on their absolute locations along the sequence. For example, the interaction between the 10th and 5th tokens should mirror the interaction between the 110th and 105th tokens. Grant likens this pursuit of symmetry to a physicist applying Noether's theorem to identify governing conservation laws from invariant principles.
Alok defines a single matrix-valued function $A$ that depends only on the difference $t - s$:
$$A(t - s) = F(t)^T G(s)$$
This definition unifies $F$ and $G$ into one operator. Alok and Grant interpret $A$ as an operation that transports information across time:
- It shifts a key at time $s$ forward into the vector space of a query at time $t$ so they can meaningfully interact.
- In language models, if a key represents an adjective, $A(t - s)$ specifies how that adjective's influence carries forward over $t - s$ steps to modify subsequent nouns before eventually fading away.
---
[14:47](https://www.youtube.com/watch?v=k86eUj4hgdc&t=887s) Setting the Identity Baseline $A(0) = I$
To pin down the behavior of $A(t - s)$, Alok introduces another natural axiom: $A(0) = I$ (the identity matrix). If two tokens sit at identical positions ($t = s$), no shift through time takes place, and the attention mechanism should simply evaluate the standard, unmodified inner product $q(t)^T k(t)$.
Alok demonstrates that enforcing $A(0) = I$ loses no mathematical generality. If $A(0)$ were instead some arbitrary invertible matrix $M$, that transformation could be absorbed directly into the definitions of the keys via a time-independent change of basis:
$$k'(t) = M k(t)$$
Because such a transformation treats every token identically regardless of time, declaring it part of a positional encoding would be redundant: “This is kind of like, you know, like this is really just a change in all of your keys uniformly. Has nothing to do with how you care about time.”
Grant visualizes this simplification geometrically as collapsing a two-dimensional grid of position pairs $(t, s)$ along its diagonals. Every counter-diagonal corresponds to a constant time displacement $t - s$, with the main diagonal representing $A(0) = I$ and adjacent diagonals capturing relative shifts such as $-1$.
When Grant asks whether one could pick any arbitrary time-dependent matrix $A$ to invent an entirely new positional encoding, Alok cautions that consistency requirements apply. He formally writes out the translation invariance condition:
$$F(t)^T G(s) = F(t - s)^T G(0) = A(t - s)$$
This condition anchors the system to a fixed baseline at $G(0)$, reducing what appeared to be a two-parameter family depending independently on $t$ and $s$ to a strictly one-dimensional matrix function of $t - s$.
[18:47](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1127s) Multiplying Two Bridge Matrices $A(s)$ and $A(t)$
Alok Puranik begins by tidying up the relationship established previously between the query and key transformation functions $f$ and $g$. At zero displacement, their product equals the identity:
$$f(t)^T g(t) = A(0) = I$$
This immediately yields the matrix inversion relation $f(t)^T = g(t)^{-1}$.
From there, Alok flags that they need to take a non-obvious leap of intuition: taking two of these position-bridging $A$ matrices and multiplying them together. In the practical world of computing transformer attention scores on GPUs, you never have reason to multiply two $A$ matrices together; you only ever sandwich one between a query and a key vector. But if you interpret $A$ abstractly as a bridge across time—mapping from step $0$ to step $t$, or from step $s$ to step $t$—it becomes entirely natural to ask what happens if you traverse that bridge once and then take another bridge immediately afterward.
Grant Sanderson laughs, noting that this is exactly the kind of move someone conversant in pure mathematics makes: “Someone conversant in group theory wants to ask this question with like a delightful abandon for whether or not anywhere inside the computations being done like in hardware that you'd ever have like two $A$ matrices multiplied.” Alok agrees, pointing out that even if it never arises on the hardware execution level, it is a “structurally natural question to answer” to pin down what mathematical object $A$ must be.
```mermaid
flowchart LR
accTitle: Matrix Bridge Composition
accDescr: Composition of positional shift matrices showing how taking step s then step t equals taking step s plus t.
subgraph Bridges["Time Shifts"]
T0["Time 0"] -->|"A(s)"| TS["Time s"]
TS -->|"A(t)"| TST["Time s + t"]
end
subgraph Direct["Direct Shift"]
T0 -->|"A(s + t)"| TST
end
```
[20:45](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1245s) Proving the Homomorphism: $A(s)A(t) = A(s + t)$
Grant anticipates the intuitive answer: if $A(s)$ translates a representation from time $0$ to $s$, and $A(t)$ translates across an interval of duration $t$ (which can also translate from $s$ to $s + t$), composing them ought to satisfy:
$$A(s)A(t) = A(s + t)$$
To test whether the earlier definitions support this, Alok sets up the product explicitly using the concrete definition $A(t) = f(t)^T g(0)$:
The middle terms, $g(0) f(t)^T$, do not immediately cancel. However, translation invariance allows shifting both arguments of the left-hand factor by any arbitrary time scalar without altering the inner product. Shifting the arguments of the first factor forward by $t$ transforms $f(s)^T g(0)$ into $f(s + t)^T g(t)$:
$$A(s)A(t) = f(s + t)^T g(t) f(t)^T g(0)$$
Because $f(t)^T = g(t)^{-1}$, the interior product $g(t) f(t)^T$ collapses straight into the identity matrix $I$. Removing it leaves:
$$A(s)A(t) = f(s + t)^T g(0) = A(s + t)$$
Grant marvels at how cleanly it resolves: “That's very neat.” Alok reflects candidly on the neatness of the proof, admitting there is an element of circular design in how he framed the setup: “I think there's something a little bit circular about what I've done here where like I've like written down all these assumptions that like kind of demand this structure and then gone like 'wow, the structure popped out.'” Nonetheless, he argues that each underlying constraint—translation invariance and an identity action at zero—is so physically and computationally reasonable that no practitioner would genuinely object to them.
[24:26](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1466s) Additive Groups, Multiplicative Matrices, and 2D Encodings
The identity $A(s)A(t) = A(s + t)$ is the central conceptual pivot of the entire inquiry. It establishes a group homomorphism: addition in the input argument (the scalar time shift) maps directly to matrix multiplication in the output.
Alok stresses that even without advanced training in group or representation theory, anyone looking at an operation where addition turns into multiplication immediately suspects an exponential function: “You see this equation and it screams out like exponential.” For real numbers, this is standard high school algebra, but because $A$ is a matrix, interpreting that exponential demands tools from physics or representation theory.
Grant asks Alok about his personal research process: did he start from the abstract group constraints and logically arrive at exponentials, or did he inspect existing positional methods and work backward? Alok explains that it was very much the latter: “When you read all this literature, you like you go like, okay, some of these have actual exponentials, some of these have rotations, which are really just complex exponentials. So, like these have got to be coming from somewhere.”
Alok notes that while he is by no means the first to spot representation theory behind positional encodings, the perspective is especially prominent in computer vision:
- In Vision Transformers (ViTs), attention must navigate a 2D grid of image patches rather than a 1D sequence of tokens.
- Practitioners must compose translations along both the horizontal and vertical axes simultaneously.
- To avoid nonsensical positional interactions, researchers explicitly use representations of the direct sum group $\mathbb{R} \oplus \mathbb{R}$ (two copies of the real additive group).
[27:10](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1630s) Differentiating Near Zero: The Continuous Time Advantage
Eager to formalize why matrix exponentials must emerge, Grant jokes about fighting the urge to immediately write down Euler's number: “I see this expression and it's hard not to to write down the letter $e$.” Alok agrees to walk through a quick, intuitive proof.
Wiping part of the whiteboard while preserving the baseline definition of $A$ as the bridge inserted between query and key vectors, Alok sets up the mathematical machinery:
- Assume that the matrix-valued function $A(t)$ is differentiable with respect to $t$.
- Evaluate the derivative of $A$ specifically at $t = 0$.
Alok admits that choosing to take a derivative at $t = 0$ might seem arbitrary, but points out that zero is the single reference point where the value of $A$ is unconditionally grounded—namely, $A(0) = I$.
Grant observes that this move demonstrates the subtle power of modeling token position continuously rather than as discrete steps: “Which is a side note is just a great justification for why thinking of time continuously... like this would not be a question to ask if you were just giving like integer indices.” Alok confirms that while integer indices allow for simpler inductive constructions, treating time as a smooth continuum opens up the machinery of calculus, leading directly into the differential formulation of Lie groups and matrix exponentials.
[28:27](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1707s) Differentiating the Group Law and the Matrix Exponential
Grant Sanderson and Alok Puranik resume their derivation of the attention transformation matrix $A(s)$. Grant jokes about discrete steps versus continuous setups, observing that moving step by step by adding one repeatedly is in some sense simpler, to which Grant quips, “Well we're being delightfully uh not it's not over complicated it's general.”
```mermaid
flowchart LR
accTitle: Matrix Exponential Derivation
accDescr: Differentiating the functional equation A of s plus t equals A of s times A of t yields the matrix ODE solved by an exponential.
subgraph EqGroup["Functional Identity"]
direction TB
E1["A(s + t) = A(s) A(t)"]
E2["Differentiate at t = 0"]
end
subgraph DiffGroup["Matrix ODE"]
direction TB
D1["A'(s) = A(s) A'(0)"]
D2["Let X = A'(0)"]
end
subgraph SolGroup["Solution"]
direction TB
S1["A(s) = A(0) exp(sX)"]
S2["A(s) = exp(sX) (since A(0) = I)"]
end
Starting from the relation $A(s+t) = A(s)A(t)$, Alok differentiates both sides with respect to $t$ and evaluates at $t = 0$. The left-hand side yields $A'(s)$, while on the right-hand side, the factor $A(s)$ acts as a constant coefficient, leaving $A(s)A'(0)$. When Alok initially writes out the evaluation notation, Grant asks if there is any reason not to just write $A'(0)$, which Alok agrees is much cleaner. Denoting this initial velocity matrix $A'(0)$ by a constant matrix $X$, the relation becomes $A'(s) = A(s)X$.
Alok remarks that over the real numbers, this differential equation immediately signals an exponential, and the exact same holds over matrices by definition. Grant reinforces this connection, observing: “Yeah, that's actually a good way to define the matrix exponential.” Because $A(0)$ must be the identity matrix to preserve the identity at step zero, the solution simplifies completely:
$$A(s) = e^{sX}$$
- The starting functional relation $A(s+t) = A(s)A(t)$ expresses translation invariance across positions.
- Taking the derivative with respect to $t$ at $t = 0$ turns the group equation into the differential equation $A'(s) = A(s)X$.
- The constant generator matrix is defined as $X = A'(0)$.
- Setting initial conditions $A(0) = I$ yields the closed-form solution $A(s) = e^{sX}$.
---
[30:56](https://www.youtube.com/watch?v=k86eUj4hgdc&t=1856s) Taylor Expansions and Real vs. Matrix Dynamics
To demystify taking the exponential of a matrix, Grant points out that while taking $e^M$ might not seem obvious at first glance, it is formally defined via its standard Taylor series expansion:
$$e^M = I + M + \frac{1}{2!}M^2 + \frac{1}{3!}M^3 + \dots$$
This infinite sum is well-defined for any square matrix because one can take arbitrary whole-number powers of square matrices. Grant notes that while someone mathematically curious might worry about the convergence of such series, thinking about eigenvalues and the differential property—that its derivative looks like a constant matrix multiplying itself—clarifies why the expression behaves as a proper exponential. Alok emphasizes that having the explicit power-series expansion on hand is crucial because they will need it once they dig into the concrete dynamics of what the matrix actually does.
```mermaid
flowchart TD
accTitle: Qualitative Regimes of Scalar vs Matrix Exponentials
accDescr: Scalar exponents lead to growth, decay, or rotation, while matrix exponents allow rich multi-dimensional dynamics.
subgraph ScalarCase["Scalar Exponential: exp(ct)"]
direction TB
C1["c > 0: Growth"]
C2["c < 0: Decay"]
C3["c in Imaginary: Rotation"]
end
subgraph MatrixCase["Matrix Exponential: exp(tX)"]
direction TB
M1["Scalar multiples of I: standard growth/decay/rotation"]
M2["General matrix X: coupled multi-dimensional subspaces"]
end
ScalarCase -->|"Generalize via X"| MatrixCase
```
Grant draws an analogy to familiar real and complex scalar systems. In scalar differential equations, the qualitative behavior depends entirely on the constant in the exponent:
- A positive real constant produces pure exponential growth.
- A negative real constant produces exponential decay.
- An imaginary constant produces pure rotation.
Grant highlights how matrices expand this landscape: “And so you're sort of asking depending on what we make X, what's the universe of things that could happen that like presumably have feelings of like growth, decay, and rotation because that's what happens in our more like happy-go-lucky land of real and complex numbers.” Alok agrees, noting that while any real or complex behavior can be trivially embedded into a matrix via a scalar multiple of the identity, working in full matrix space opens the door to far richer dynamics.
---
[33:28](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2008s) Invariance Under Change of Basis
With the full solution set characterized as $A(s) = e^{sX}$, Alok introduces a crucial simplifying assumption: changes of basis in the query and key representations do not matter for positional encodings. Specifically, any time-invariant linear change of basis—such as mapping $Q \mapsto R Q$ via a fixed rotation matrix $R$—can be absorbed by the surrounding neural network layers.
Alok states: “From a positional encodings point of view, this is a no-op. From a neural network's point of view, like our linear layers can deal with that. That's not our problem in the positional encoding.”
Because basis transformations applied to $X$ propagate directly through the series expansion into $A(s)$ (as all intermediate change-of-basis matrices cancel out in the matrix powers), the problem reduces to understanding the generator $X$ only up to similarity transformations (change of basis).
---
[34:41](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2081s) Decoupling via Diagonalization
Up to a change of basis, the natural tool to analyze matrix exponentiation is eigendecomposition. Assuming $X$ can be diagonalized over the complex numbers (which holds for "most" matrices in the generic sense), $X$ can be written with complex eigenvalues $\lambda_1, \lambda_2, \dots, \lambda_n$ along its main diagonal and zeros everywhere else:
Exponentiating a diagonal matrix is straightforward: powers of a diagonal matrix simply equal the powers of its individual diagonal elements. Consequently, the exponential $e^{tX}$ is itself diagonal, containing entries $e^{t\lambda_j}$ along the diagonal:
Grant explains the geometric intuition behind why off-diagonal interactions vanish: in the eigenbasis, the operator acts on each 1D invariant subspace independently, so the components never mix. Alok emphasizes that this property transforms the bilinear attention query-key product into an uncoupled sum of scalar terms:
$$Q^\top e^{tX} K = \sum_{j=1}^n Q_j e^{t\lambda_j} K_j$$
Grant reflects on the conceptual clarity that comes from diagonalizing into complex scalars: “And I'll emphasize even though like symbolically it sort of looks very similar, like there's a very different emotion in thinking about that as being an operator in the exponent versus thinking about it as just being a number because like this one, like, oh, it's a number. We know what that does. It's like it grows, it decays, or it rotates.”
- In the eigenbasis, component $Q_j$ interacts strictly with component $K_j$ scaled by the scalar factor $e^{t\lambda_j}$.
- There is zero cross-talk between different index components $j$ and $k$ ($j \neq k$).
- The eigenvalues $\lambda_j$ can be complex numbers, naturally enabling rotational frequencies alongside growth or decay rates.
[38:41](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2321s) Diagonalizing Components and Real Eigenvalues
Grant and Alok reflect on the familiar mathematical feeling when studying matrix exponentials: an initial dread that the matrix exponential $e^{tX}$ could be impossibly complicated, followed by the realization that if the matrix is diagonalizable, “actually like there's nothing new under the sun here.” Grant compares this relief to pre-calculus, where students realize that complex exponentials and standard trigonometry are fundamentally the same concept. While not every matrix is diagonalizable—an asterisk they set aside for later—Alok explains that diagonalizability allows them to analyze the behavior of positional encodings by zooming in on just a single decoupled component. In attention, a full dot product sums interactions between elements of $Q$ and elements of $K$; by isolating a single 1D component, they can observe how that single piece scales across relative time $t$.
```mermaid
flowchart TD
accTitle: Real Eigenvalue Cases for Relative Position
accDescr: Shows how the sign of real eigenvalue x influences token interaction over time t.
subgraph Cases["Behavior of e^(t x) as t increases"]
Pos["x > 0: Exponential Growth<br/>(Distant past tokens dominate; unstable)"]
Zero["x = 0: Constant / Degenerate<br/>(Time-independent component; valid in mix)"]
Neg["x < 0: Exponential Decay<br/>(Distant past fades; seen in RNNs and linear attention)"]
end
```
Alok notes that while they will zoom into one component at a time, real-valued matrices often force them to look at two-dimensional subspaces when eigenvalues are complex. Starting first with the strictly real case, Alok sets up the scalar component where the generator is a scalar $x \in \mathbb{R}$, yielding the scalar transformation $A(t) = e^{tx}$. When evaluated inside an attention term between a query token at position $t$ and a key token at position $0$, this yields an interaction term proportional to $Q(t)\,e^{tx}\,K(0)$. Alok breaks down the three possible behaviors based on the sign of $x$:
- **$x > 0$ (Exponential Growth):** The influence of a token in the past grows exponentially the farther back it occurred. As Grant puts it, “the longer ago this was in the past, the more you should care about it,” which Alok agrees is “inherently unstable” and undesirable for modeling language.
- **$x = 0$ (Constant):** The exponential evaluates to $e^0 = 1$, eliminating time dependence entirely. While degenerate on its own, Alok points out it is completely reasonable within a larger multi-component representation: “Some components maybe just you don't want to decay over time. Like they're actually truly time independent.”
- **$x < 0$ (Exponential Decay):** The past fades exponentially as distance $t$ increases. Grant observes that this matches the implicit time decay seen in recurrent neural networks (RNNs), and Alok adds that this exact decaying mechanism appears explicitly in the linear attention literature.
---
[44:08](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2648s) Complex Eigenvalues and 2D Rotations
When moving to the complex eigenvalue case, diagonalizing a real-valued matrix necessarily produces complex conjugate eigenvalue pairs $a \pm bi$. Grant draws the classic 2D rotation matrix for an angle $\theta$:
$$\begin{pmatrix} \cos\theta & -\sin\theta \\ \sin\theta & \cos\theta \end{pmatrix}$$
He points out that this real rotation matrix diagonalizes over the complex numbers into eigenvalues $e^{\pm i\theta}$, taking the form $\operatorname{diag}(e^{i\theta}, e^{-i\theta})$. Alok highlights this geometric connection: “the theta you can see like exactly how these complex rotations and the more geometric rotations do do nicely correspond here.”
```mermaid
flowchart LR
accTitle: Complex Generator Decomposition
accDescr: Splitting a complex 2x2 generator into a scaling component and an imaginary rotation component.
A["X_diag = <br/>diag(a + bi, a - bi)"] --> B["Scaling part:<br/>a * I"]
A --> C["Rotation generator:<br/>b * diag(i, -i)"]
B --> D["e^(a t): Decay or growth"]
C --> E["e^(± i b t): Planar rotation (RoPE connection)"]
```
To analyze this systematically, Alok writes the diagonalized $2 \times 2$ block of the generator $X_{\text{diag}}$ as:
$$X_{\text{diag}} = \begin{pmatrix} a + bi & 0 \\ 0 & a - bi \end{pmatrix} = a I + b \begin{pmatrix} i & 0 \\ 0 & -i \end{pmatrix}$$
This decomposition splits cleanly because the scalar identity matrix $aI$ commutes with any matrix. As Grant observes, “the general intuition isn't if they if they commute with each other then you can do that,” confirming that $e^{t(A + B)} = e^{tA}e^{tB}$ holds when $A$ and $B$ commute.
- The real part $a$ yields an overall scalar multiplier $e^{at}$, which acts identically to the scalar $x$ from the real case (decaying when $a < 0$, blowing up when $a > 0$, or disappearing when $a = 0$). Grant jokes about the notation, remarking, “it's nice to see that AI has shown up in the lecture.” To keep the algebra clean, Alok sets $a = 0$ for the remainder of the derivation.
- Exponentiating the remaining imaginary term produces $e^{t X_{\text{diag}}} = \operatorname{diag}(e^{ibt}, e^{-ibt})$. As the product $bit$ appears in the exponents, Alok quips, “as you see the bits have shown up in the lecture as well,” showing how this conjugate complex exponential naturally represents the continuous 2D rotation at the core of methods like Rotary Positional Embedding (RoPE).
[49:22](https://www.youtube.com/watch?v=k86eUj4hgdc&t=2962s) Decomposing Diagonalizable Action into 2D Rotations and Decays
Alok Puranik and Grant Sanderson emphasize the importance of understanding the correspondence between general diagonalizable real matrices and rotation matrices under a change of basis. Instead of tracking complex values abstractly, a real matrix acting on a two-dimensional invariant subspace can be written as a rotation matrix $R(\theta t)$ combined with scaling. Grant pulls up a visual animation that Alok created, remarking on the connection to complex exponentiation: the real part controls exponential decay or growth, while the imaginary part controls rotation as the parameter evolves. Grant playfully asks whether Alok considered building an interactive "vibe coding" version and confirms Alok wrote the animation from scratch in Manim, offering the tip that Manim can indeed be made interactive.
```mermaid
flowchart LR
accTitle: Matrix Exponential Action on Invariant Subspaces
accDescr: Real and imaginary components map to decay and rotation over 1D and 2D subspaces.
subgraph Action["Action of e^(Xt)"]
direction TB
R["Real Part: a"] -->|"Determines"| Growth["Exponential Growth / Decay"]
I["Imaginary Part: b"] -->|"Determines"| Rot["Rotation by Angle theta = bt"]
end
subgraph Subspaces["Subspace Decomposition"]
direction TB
D1["1D Subspaces (Real Eigenvalues)"]
D2["2D Subspaces (Complex Conjugate Pairs)"]
end
Action --> Subspaces
```
Grant observes that this setup intuitively captures all time dependence for diagonalizable matrices: on isolated subspaces, the only behaviors possible are growth, decay, and rotation. Alok confirms that this covers the entirety of the diagonalizable case. Any larger diagonalizable matrix is formed merely by stacking independent one-dimensional subspaces (real values) and two-dimensional blocks (complex conjugate pairs) along the diagonal without interaction between them:
> “And again, it's really important here. There's no interactions, which is why I feel justified in like studying these one and two dimensional subspaces kind of in isolation.” — Alok Puranik
[52:21](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3141s) Connecting the Theory to Rotary Position Embeddings (RoPE)
Grant asks Alok to connect this linear algebra foundation to engineering practices like RoPE (Rotary Position Embedding). Alok explains that RoPE is precisely the pure imaginary, complex case where the real decay factor $a$ is set to zero ($a = 0$). Because there is neither decay nor blow-up, RoPE consists purely of rotations across pairs of dimensions.
To formulate this in the matrix framework, RoPE defines a set of frequencies:
$$\theta_1, \theta_2, \dots, \theta_{n/2}$$
Rather than computing the matrix logarithm $X$ directly—which Alok jokingly admits to always forgetting for a rotation matrix—Alok constructs the transition matrix $A(t)$ by stacking $2 \times 2$ block rotation matrices $R(\theta_k t)$ down the diagonal:
This structure takes $n/2$ orthogonal two-dimensional planes and rotates each at its own characteristic frequency $\theta_k$.
[55:04](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3304s) Frequencies as Multi-Scale Clocks in Attention
Grant asks whether the specific choices of $\theta$ are an inevitable mathematical consequence or an engineering design decision. Alok clarifies that RoPE adopts a geometric sequence of frequencies specifically chosen to handle multiple time horizons. In RoPE, the largest frequency is chosen to be on the order of 1 (corresponding to the shortest period), while the smallest frequency drops to around $1/10{,}000$ (corresponding to long periods spanning thousands of tokens), with intermediate frequencies spaced exponentially between them.
Alok explains the intuition behind this spacing: a frequency $\theta$ acts as an inverse time scale or rotation rate, best suited for distinguishing distances around length scale $1/\theta$ (or $2\pi/\theta$). If a model only had fast frequencies, tokens separated by many cycles would blend together once the phases wrap around repeatedly. Having a broad geometric spectrum ensures that:
- Fast clocks distinguish fine-grained token differences (e.g., whether a word was one or two positions ago).
- Slow clocks distinguish coarse global context (e.g., whether a concept appeared 1,000 versus 5,000 words ago).
Alok begins translating the block-diagonal rotation matrix back to concrete functions $f(t)$ and $g(s)$ that modify keys and queries—such as setting $g(0) = I$ and $f(t)^T = A(t)$. However, Grant suggests bypassing the tedious hand-waving needed to materialize $f$ and $g$ line-by-line, noting that the audience can already see how RoPE emerges directly from rotation in diagonalizable systems:
> “I think one of the more interesting things to try to get at is like: is there a positional encoding that people haven't experimented with that you can discover as a result of saying like, once we have this framing, you're choosing what $X$ is... is there anything unknown that you get by, like, as a fruit of your labor for having become so abstract?” — Grant Sanderson
Alok agrees that this serves as the perfect segue to explore the lingering asterisk they previously set aside: the non-diagonalizable case.
[58:59](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3539s) Non-Diagonalizable Matrices and Jordan Blocks
The discussion turns toward the non-diagonalizable case in linear algebra—a regime that is frequently set aside because such matrices are ill-behaved and algebraically awkward. As Alok notes, standard practice often explicitly restricts models to diagonalizable transformations. After all, non-diagonalizable matrices form a measure-zero set: perturbing any defective matrix by an infinitesimal amount immediately restores diagonalizability. Despite this mathematical fragility, these matrices prove crucial for modeling certain behaviors in neural representations.
When a matrix cannot be diagonalized, it can instead be represented in Jordan normal form using Jordan blocks. Alok introduces the simplest non-trivial example, a $2 \times 2$ block with zeros along the main diagonal:
$$X = \begin{pmatrix} 0 & 1 \\ 0 & 0 \end{pmatrix}$$
Grant points out that in the slightly more general construction, the zeros on the diagonal would be replaced by some real scalar value $\lambda$, but Alok opts to keep the diagonal zero to build intuition from first principles.
```mermaid
flowchart LR
accTitle: Two-step Nilpotent Action of a Jordan Block
accDescr: Diagram illustrating how applying the matrix X acts on the basis vectors, showing that the y-axis moves to the x-axis, the x-axis is killed, and applying X twice annihilates any input vector to zero.
Alok explains the geometry behind this algebraic setup. While the matrix has an algebraic eigenvalue of zero with multiplicity two, the eigenspace is defective:
- “One of these is like a good proper eigenvalue that kind of that really does stand alone. It has its own eigenvector, has its own subspace, doesn't affect anything else.”
- The second eigenvalue is coupled and leaks into the first subspace: applying $X$ to $\begin{pmatrix} 1 \\ 0 \end{pmatrix}$ yields $\begin{pmatrix} 0 \\ 0 \end{pmatrix}$, completely squishing the x-axis as expected.
- However, applying $X$ to $\begin{pmatrix} 0 \\ 1 \end{pmatrix}$ results in $\begin{pmatrix} 1 \\ 0 \end{pmatrix}$. The $y$-component is eliminated, but an $x$-component is generated.
- Applying $X$ a second time annihilates this newly created component: $X^2 \begin{pmatrix} 0 \\ 1 \end{pmatrix} = X \begin{pmatrix} 1 \\ 0 \end{pmatrix} = \begin{pmatrix} 0 \\ 0 \end{pmatrix}$.
Because $X^2 = 0$, the matrix is nilpotent. When computing the matrix exponential $e^{tX}$ using its standard Taylor series:
$$e^{tX} = I + tX + \frac{(tX)^2}{2!} + \dots$$
Every term of degree two and higher vanishes. The infinite power series truncates cleanly to a simple linear polynomial:
$$e^{tX} = I + tX = \begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix}$$
This behavior is striking: exponentiation has produced a polynomial in $t$ rather than the periodic trigonometric functions or exponential growth/decay seen in diagonalizable representations.
---
[01:03:03](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3783s) Physical Intuition: The Drifting Hockey Puck
Grant questions the architectural meaning of this polynomial behavior in positional encodings. In earlier cases, rotating matrices acted like a Fourier decomposition across frequency domains, while exponential decay reflected the natural intuition that tokens further apart should exert less influence over time. Grant remarks, “I have no intuition on what this means.”
To ground the mathematics, Alok provides an analogy from linear dynamical systems: a frictionless hockey puck sliding along a one-dimensional track.
```mermaid
flowchart TD
accTitle: Dynamical System State Evolution
accDescr: Flowchart demonstrating how the state vector of position and velocity evolutions linearly under matrix exponentiation over time t.
subgraph State["State Vector"]
S0["Initial state: [x₀, v]ᵀ"]
end
subgraph Result["Final State at time t"]
St["State at t: [x₀ + tv, v]ᵀ"]
end
S0 --> Mat
Mat --> St
```
- **Physical System**: A puck begins at an initial position $x_0$ and moves with constant velocity $v$ on an ideal surface with no friction or external forces.
- **State Representation**: The state is captured by the vector $\begin{pmatrix} x_0 \\ v \end{pmatrix}$.
- **Kinematics**: After elapsed time $t$, the new position is $x_0 + tv$, while the velocity remains unchanged at $v$.
- **Matrix Action**: Applying $e^{tX} = \begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix}$ directly to $\begin{pmatrix} x_0 \\ v \end{pmatrix}$ yields:
$$\begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix} \begin{pmatrix} x_0 \\ v \end{pmatrix} = \begin{pmatrix} x_0 + tv \\ v \end{pmatrix}$$
Alok summarizes: “You can kind of think of this matrix as generating the dynamics of like something just flying off in the distance with some like constant speed.” If one were to expand the Jordan block to a $3 \times 3$ nilpotent matrix with 1s on the superdiagonal, $X^3$ would vanish while $X^2 \neq 0$, producing quadratic time evolution akin to constant acceleration.
---
[01:06:06](https://www.youtube.com/watch?v=k86eUj4hgdc&t=3966s) Connecting Nilpotent Dynamics to ALiBi
Grant asks what this physical behavior implies for transformers: “What does the hockey puck positional encoding look like? Right? What does that even mean to think of a term like this through $A$, then through its like influence on your $f$ and $g$ which in turn influence your positional encodings?”
Alok explains that taken naively, this mechanism induces an influence that scales linearly with token distance. While less catastrophically divergent than exponential growth, unbounded linear growth initially seemed practically unappealing, leading him to believe non-diagonalizable blocks were useless. However, another researcher pointed out that this linear term directly models ALiBi (Attention with Linear Biases).
In standard relative positional methods, positions transform the query and key vectors themselves. In ALiBi, the vectors remain unrotated, and a linear penalty proportional to token distance is subtracted directly from the attention logit:
$$\text{logit}(t, s) = q_t^T k_s - \text{penalty} \cdot (t - s)$$
- “This doesn't do anything to the vectors; it just sticks this like as a completely separate penalty term and it says like reduce the score when they're further apart.”
- The formulation respects translation invariance, as the logit modification depends strictly on the relative distance $t - s$.
- The presence of the linear distance term $t - s$ mirrors the linear polynomial $I + tX$ derived from the two-dimensional Jordan block.
- To bridge the gap between matrix-transformed vectors and ALiBi's scalar logit penalty, Alok proposes augmenting the query and key vectors with fixed auxiliary components.
[01:09:15](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4155s) Recovering ALiBi from Defective Matrices
Wrapping up their classification, Grant Sanderson and Alok Puranik leave diagonalizable generators behind. As Grant puts it, “kill all diagonal matrices,” prompting Alok to joke that “the old model of the world is gone.” To see whether non-diagonalizable generators correspond to any known machine learning techniques, Alok sets out to recover ALiBi (Attention with Linear Biases) by appending extra components to the query and key vectors. ALiBi introduces a linear penalty on token distance, which takes the form of $-p(t - s)$ (or simply $-pt$ when setting the key position $s = 0$). To generate this linear offset without producing unwanted diagonal terms, they use a defective matrix generator whose exponential yields an upper-triangular unipotent matrix containing $t$:
$$\begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix}$$
```mermaid
flowchart LR
accTitle: ALiBi Derivation via Defective Matrix Generator
accDescr: Augmenting query and key vectors through an upper-triangular matrix to produce a linear ALiBi bias term.
subgraph Inputs["Augmented Vectors"]
Q["Q̂ = [Q, -p, 0]"]
K["K̂ = [K, 0, 1]"]
end
subgraph Defective["Defective Generator Exp."]
M["Matrix: [[1, t], [0, 1]]"]
end
subgraph Output["Attention Score Term"]
R["-p · t Term (ALiBi Penalty)"]
end
Q --> Defective
K --> Defective
Defective --> R
```
Alok works through the algebra of matching the components. If the augmented query $\hat{Q}$ ends with vector components $(-p, 0)$ and the augmented key $\hat{K}$ ends with $(0, 1)$, multiplying across the defective transition matrix isolates the off-diagonal $t$:
Grant asks if Alok will split the factor symmetrically across both sides as a $\sqrt{p}$, but Alok keeps it direct: “I was just going to stick a negative $p$ in there and a 1 in here.” When Alok stumbles momentarily over index alignment, Grant laughs, affirming the messy trial-and-error: “No, no, no. I mean this is the process of it's honest process of just like doing like I have a feeling there's this connection between like something that comes up in machine learning land and then my like abstract beautiful framework of like, you know, the space of all possible positional encodings.”
By explicitly fixing these appended coordinates in $\hat{Q}$ and $\hat{K}$, they prevent unwanted linearly exploding polynomial artifacts from contaminating the content-based dot product. As Alok summarizes, “this is actually a case where like if you, you know, fix a couple components of your inputs and then you staple on this like what's called like a defective matrix into your generator for your positional encoding, you can exactly recover ALiBi which is really satisfying.” Grant highlights that this neatly finishes their exhaustive mathematical taxonomy: “So you've hit all the bases. You've hit your real exponentials, your complex exponentials, and your non-diagonalizables that turn into polynomials.”
- **Real exponentials:** Represent pure decay or amplification factors along coordinate axes.
- **Complex exponentials:** Give rise to 2D rotation blocks, recovering Rotary Position Embeddings (RoPE).
- **Non-diagonalizable (defective) blocks:** Yield polynomial growth in $t$, which, when bounded by constant augmented query/key entries, reproduces ALiBi's linear distance penalty $-pt$.
---
[01:13:42](https://www.youtube.com/watch?v=k86eUj4hgdc&t=4422s) Jane Street Culture and the Exhaustion of the Hypothesis Space
Grant shifts the conversation toward Alok's role at Jane Street, asking whether preparing deep-dive explorations connecting pure math to practical machine learning is typical for internal presentations among colleagues. Alok chuckles, noting, “this was honestly one of the more relevant things that I'm giving a talk on.” He explains that there is an informal boundary between everyday production work and the intellectual discussions that happen late in the week: “after everyone is like turned their chairs around on a Friday afternoon and we're like, 'Okay, we've probably gotten enough work done for the week and we're just kind of like talking about more miscellaneous stuff.'” Because this specific mathematical framing yielded genuine clarity on why standard positional encodings behave as they do, Alok initially wrote it up as an internal blog post before the team decided to refine and publish it externally.
Turning to the broader implications of the work, Grant asks if this classification changed how Alok views positional encodings, or if it simply offered peace of mind that researchers have already discovered the primary viable options. Alok admits:
> “At the outset I really wasn't sure what I'd find here, but I guess like once it was all said and done, I did feel kind of more comfortable knowing like there wasn't some like big gap in the literature or something.”
While higher-order Jordan blocks can mathematically generate quadratic or higher-degree polynomial terms ($t^2, t^3, \dots$), Alok expresses confidence that they hold little untapped utility for practical attention mechanisms: “I think like now that I understand the dynamics of those somewhat better, I do feel relatively confident that like probably not super useful.” Grant confirms that higher-degree polynomial blocks are unlikely to suddenly unlock practical model performance breakthroughs. Satisfied with the journey across group representations, linear algebra, and attention mechanisms, Grant wraps up the discussion, thanking Alok for a fun and enlightening walkthrough.
## Notable quotes
> [01:30](https://www.youtube.com/watch?v=k86eUj4hgdc&t=90s) The beauty of the attention mechanism is that it kind of doesn't pre-bake time. — Grant Sanderson
## Mentioned
Grant Sanderson, Alok Puranik, 3Blue1Brown, Jane Street, RoPE (Rotary Positional Embedding), ALiBi (Attention with Linear Biases), Attention Is All You Need, Mamba, Vision Transformers (ViTs), Manim
## Video description
Grant Sanderson of 3Blue1Brown and Alok Puranik, a researcher at Jane Street, work through Alok’s latest blog post on positional encodings in transformers. Starting from a few natural assumptions about attention, they use group and representation theory to explore what forms a positional encoding can take. Along the way, they connect the theory to familiar methods like RoPE (Rotary Positional Embedding) and ALiBi (Attention with Linear Biases), and investigate whether it reveals anything new.
Read Alok's blog post here: https://blog.janestreet.com/using-group-theory-to-explore-positional-encodings-attention/
Jane Street证实RoPE与ALiBi穷尽了主要位置编码形式
将李群理论应用于平移不变注意力机制,证明所有线性机制均可归约为矩阵指数,从而证实RoPE和ALiBi等现有设计已涵盖所有可行的架构。
Grant Sanderson与Alok Puranik通过将查询和键形式化为连续时间函数,深入探讨了如何严格地向Transformer注意力机制中引入位置信息。通过施加平移不变性和线性变换约束,他们证明位置交互构成了一个从标量时间加法到矩阵乘法的群同态,其唯一解为矩阵指数$e^{tX}$。对生成元矩阵$X$的分析表明:实特征值对应指数衰减或增长,共轭复数对产生旋转位置嵌入(RoPE)中的二维平面旋转,而不可对角化的亏损若尔当块则生成线性偏置注意力(ALiBi)中采用的线性距离惩罚。最终,这一数学分类表明现有的位置编码架构已自然穷尽了主要稳定的数学可能性。
通过在连续时间下构建查询与键的变换并施加平移不变性约束,位置编码可归约为一种将时间加法映射到矩阵乘法的群同态,其唯一解为矩阵指数A(t) = e^(tX)。 (28:27)
线性代数将位置编码的可能表现彻底归类为三种形态:基于实特征值的指数增长/衰减、基于共轭复数对的平面旋转(RoPE),以及基于亏损若尔当块的多项式偏移(ALiBi)。 (69:15)
RoPE对应于实数衰减设为零的纯虚数可对角化情形,其在正交的二维子空间中部署几何频率谱,以防止跨序列长度时发生相位混叠。 (52:21)
ALiBi的线性Logit惩罚可通过作用于增广坐标通道上的不可对角化2x2若尔当块在代数上复现,这证实了常见的经验性位置编码已涵盖了数学上可行的选项。 (69:15)
Reading summary
Analyzing transformer positional encodings through group representation theory reveals that assuming translation invariance and linearity inevitably restricts positional operators to matrix exponentials of the form $e^{sX}$. Through eigendecomposition and Jordan normal form, this unified algebraic framework completely classifies existing empirical methods into real exponential decay, RoPE rotations, and ALiBi linear penalties.
First Principles: Linearity, Invariance, and Lie Generators (8:53)
Standard transformer attention calculates query-key inner products without inherent awareness of token sequence order. To inject relative position while maintaining linear computational efficiency, positional modifications must act individually on each query $q(t)$ and key $k(s)$ via linear maps $F(t)$ and $G(s)$, rather than scaling quadratically over all $N^2$ token pairs. Enforcing translation invariance dictates that the interaction depends solely on relative offset: $A(t - s) = F(t)^T G(s)$, with the baseline condition $A(0) = I$ absorbing any uniform key transformations.
Interpreting $A$ as an operator that bridges representations across continuous time leads directly to the group homomorphism $A(s)A(t) = A(s + t)$, converting additive temporal shifts into matrix multiplication. Differentiating this relation with respect to $t$ at $t = 0$ yields the matrix ordinary differential equation $A'(s) = A(s)X$, where $X = A'(0)$ acts as a constant generator. Given $A(0) = I$, the unique solution across continuous time is the matrix exponential $A(s) = e^{sX}$.
Diagonalizable Generators: Exponential Decay and RoPE Rotations (38:41)
Because time-invariant changes of basis can be absorbed by the surrounding neural network layers, the dynamics of $e^{sX}$ depend strictly on the canonical form of the generator $X$. For generic, diagonalizable matrices, $X$ decouples into independent one-dimensional and two-dimensional invariant subspaces without cross-talk.
A real eigenvalue $\lambda = x$ yields a scalar factor $e^{tx}$. When $x < 0$, it produces exponential decay over time, mirroring the inductive bias found in recurrent neural networks and linear attention architectures (while $x > 0$ yields unstable exponential growth). In contrast, complex conjugate eigenvalue pairs $a \pm bi$ introduce planar rotations. Setting the real component to zero ($a = 0$) isolates pure rotations by angle $\theta = bt$. Stacking these $2 \times 2$ rotation blocks across a geometric spectrum of frequencies $\theta_k$ recovers Rotary Position Embeddings (RoPE), where fast frequencies resolve local word boundaries and slow frequencies track global context across thousands of tokens.
Defective Matrices: Recovering ALiBi from Nilpotent Jordan Blocks (58:59)
Beyond diagonalizable systems lies the measure-zero set of defective matrices, represented via Jordan normal form. For a defective $2 \times 2$ nilpotent generator with zeros on the diagonal and a 1 on the superdiagonal, the matrix squares to zero ($X^2 = 0$). Its Taylor series expansion terminates cleanly after the first degree, producing the linear polynomial $e^{tX} = I + tX = \begin{pmatrix} 1 & t \\ 0 & 1 \end{pmatrix}$. This structure governs dynamical kinematics equivalent to a frictionless body drifting at constant velocity.
While unbounded linear growth initially appeared impractical for vector transformations, augmenting query and key vectors with fixed auxiliary entries maps this polynomial directly into attention logits. Sandwiching $I + tX$ between fixed components isolates an unscaled linear offset, mathematically reproducing the empirical distance penalty $-p(t - s)$ used in Attention with Linear Biases (ALiBi).
The representation-theoretic formulation provides an exhaustive mathematical taxonomy that unifies linear attention decay, RoPE rotations, and ALiBi linear penalties under a single algebraic framework. Although higher-order Jordan blocks can mathematically generate quadratic or higher-degree polynomials, Alok Puranik concludes they hold little practical utility, indicating that machine learning practitioners have already identified the primary viable positional mechanisms.
[1:30] Grant Sanderson: The beauty of the attention mechanism is that it kind of doesn't pre-bake time.
Original transcript
[0:00] Alok, thank you for joining me. So, you
[0:02] recently wrote this really nice blog
[0:03] post about studying positional encodings
[0:05] and transformers with group theory.
[0:07] We're going to dive right into it, but
[0:08] before we do it, why did you like what
[0:10] was making you think about this in the
[0:11] first place? I do a fair amount of just
[0:13] like reading papers and trying to stay
[0:15] up to date with what people are thinking
[0:16] about in the field of deep learning. And
[0:18] so, one thing that comes up from time to
[0:19] time is just variants of positional
[0:21] encodings that people have, you know,
[0:23] proposed try different architectures.
[0:25] Um, and like the big classic is rope. Uh
[0:27] I think rope is like in some ways the
[0:30] default. Um and rope has this nice
[0:32] structure where it like rotates these
[0:34] pairs of coordinates. Um and so you
[0:36] convert like time into these rotations.
[0:40] And that looks a little familiar if like
[0:43] you come from the background of like
[0:44] representation theory or something like
[0:45] that because this idea of like taking
[0:48] this group in this case like the the
[0:51] real numbers or the integers with with
[0:53] addition and then converting those to
[0:56] some like matrix operator that like
[0:59] structurally looks very similar.
[1:00] >> Um that concept is like almost the
[1:04] entire study of the field of
[1:05] representation theory and then some
[1:07] similar cases popped up elsewhere. So uh
[1:10] in linear attention a related well not
[1:12] obviously related but I think actually
[1:14] very closely related thing happens where
[1:16] instead of um instead of encoding time
[1:18] via these rotations of vectors they
[1:21] encode time by like exponentially
[1:23] suppressing old values. But this is kind
[1:26] of another instance of the same
[1:28] phenomenon. I'll tell you what like I
[1:30] really liked about the poster when I saw
[1:32] it. when [clears throat] you read about
[1:34] attention mechanisms and like different
[1:36] encodings and things like this, it comes
[1:37] across like I guess this is a
[1:39] sufficiently natural choice and then you
[1:41] came at it as saying like what must it
[1:42] be? Um and like one of the more
[1:44] intriguing things there is to ask like
[1:45] is it the case that there are methods
[1:48] that like haven't been explored before
[1:50] which you kind of could touch on a
[1:51] little bit. Oh, I mean I I know. I think
[1:52] this was exactly the like the motivation
[1:55] which was like well I noticed like these
[1:57] two examples that are both pretty widely
[1:59] used come from this class of things like
[2:02] this class of like representations and
[2:04] like then the natural question became
[2:07] like okay do all of these methods like
[2:09] like is the whole universe of methods
[2:11] actually just the class of these
[2:12] representations or like is there some
[2:14] other reason like it felt like it
[2:15] couldn't be a coincidence that like two
[2:17] very popular methods came from this same
[2:20] like said both had this algebraic
[2:22] structure and now then the natural
[2:23] question is like maybe all of the
[2:24] methods have this algebraic structure is
[2:27] there some like what's the kind of the
[2:28] minimal set of assumptions that gives
[2:30] you this and like do they seem like
[2:31] reasonable assumptions something like
[2:33] that I mean let's dive in I'm presuming
[2:35] most of the people watching this have
[2:36] some familiarity with like attention
[2:38] already um I feel like it doesn't hurt
[2:40] to at least pull up an image this is
[2:42] just from my own video so I'm going to
[2:43] do like a shameless [laughter] plug um
[2:45] but like the problem statement that we
[2:47] have where when you're processing a
[2:49] bunch of embeddings you know, they they
[2:51] get turned into a bunch of query
[2:52] vectors. They also get turned into a
[2:54] bunch of key vectors. The way that
[2:56] you're deciding how does one set of
[2:58] embeddings influence another. So like
[2:59] the example that I was focusing on has
[3:01] some sentence that says like a fluffy
[3:03] blue creature roamed the verdant forest
[3:04] and like how is it that fluffy and blue
[3:06] know that they should influence the noun
[3:08] creature? That the only thing you're
[3:10] really doing is taking dot products. Um
[3:12] the beauty of the attention mechanism is
[3:14] that it kind of doesn't pre-bake time.
[3:16] It doesn't say, "Hey, you should
[3:18] necessarily wait the stuff that came
[3:20] right before." It's agnostic to that.
[3:21] It's like that should all be learned.
[3:22] But that's also the like the Achilles
[3:24] heel on it because you want some way of
[3:26] knowing, hey, position matters. Like, so
[3:28] then if you also want your um embeddings
[3:30] to somehow say here's where I am. Uh but
[3:34] you're only allowed to do this in the
[3:35] language of like matrix operations on
[3:37] it. What do you do? What are what are
[3:39] the ways to communicate where it is? And
[3:41] so we'll put this away. Let's get to
[3:43] like kind of the whiteboarding. How do
[3:45] how do you start to think about it? Like
[3:46] what's the principled way to say I'm not
[3:48] going to go in assuming uh the
[3:50] literature's positional encodings? I
[3:52] just want to say what's the space of all
[3:53] encodings? Where do we begin?
[3:54] >> Yeah. So I guess we have to begin with
[3:56] the dot products. Um so you've got some
[3:58] queries and okay so conventionally the
[4:00] queries would be like some Q1 Q2
[4:04] so on QN. Um actually because I kind of
[4:08] want these to generalize to continuous
[4:09] time, I'm going to make a slightly
[4:11] unconventional choice and just write
[4:13] these as functions of of time.
[4:15] >> Okay.
[4:15] >> Um so this is just some q of t. Um and
[4:18] then t like you know whatever zero less
[4:21] than or equal to t less than or equal to
[4:23] some big t or something like that. I'm
[4:24] not sure this will ever matter but
[4:26] that's okay. And then likewise you have
[4:28] some some keys and these are like some k
[4:30] of t. Um, and if you just t integers,
[4:33] now you get the normal sequential.
[4:35] >> Can I ask a side question on this? I
[4:36] remember when I was looking at your
[4:37] post, I was like, is [clears throat]
[4:38] this how ML people in finance think
[4:41] about these usually as like time series
[4:43] kind of like continuous time? Because
[4:44] like language processing, it's so
[4:46] intrinsically intrinsically discreet.
[4:48] But then I don't I don't know what
[4:50] models Jane Street uses, right? But if
[4:51] I'm imagining doing some like market
[4:53] data thing, maybe something that's more
[4:55] agnostic to the time steps makes more
[4:57] sense. Is that like a standard way of
[4:59] thinking about it? Well, I guess when
[5:00] you're modeling like real world time
[5:03] series, they're not always so cleanly
[5:05] like discreet or as regular. And it's
[5:08] like and actually this framing ended up
[5:10] being really interesting even in like
[5:13] outside financial applications because
[5:15] um this is you know kind of a kind of a
[5:17] skip ahead a lot but um
[5:19] >> in some places you want to learn data
[5:22] dependent like decays or something like
[5:24] that and I think this is just strictly
[5:25] more general but I I do also think when
[5:27] you're modeling like kind of real world
[5:29] like physical phenomena it is actually
[5:31] quite nice to say time is continuous we
[5:33] just sample it in some points that we
[5:35] could care for. Yeah.
[5:36] >> Um this is also I think what like
[5:40] >> um the like mamba folks like to do as
[5:44] well when they're framing their things.
[5:46] So
[5:46] >> um Okay, great.
[5:47] >> So our keys and queries dependent on
[5:49] time. Intrinsically nothing is telling
[5:51] us what that time is. Uh so we have to
[5:53] come up with some way of doing that.
[5:55] >> Yeah. Yeah. Um okay. And so now we we
[5:58] want to be able to ask like how much
[6:01] does um the query at time t um and the
[6:07] key at time s like
[6:09] >> uh how much attention should this query
[6:11] paid to this key
[6:12] >> um and actually like I'm dropping a
[6:14] meaningful fraction intention
[6:16] computation here by throwing out the
[6:17] values but actually for what we're doing
[6:18] we don't really care about the values
[6:19] >> because you're just coming up with the
[6:20] attention pattern
[6:21] >> we just want the scores like the
[6:22] attention weights
[6:23] >> um
[6:24] >> and so the conventional you know in
[6:25] intention computation like the
[6:26] conventional thing you do is you take
[6:28] this dotproduct Q of T transpose K of S.
[6:31] >> Mhm. Um okay and this is a good start
[6:34] but like as as you point out like
[6:36] there's nothing ex like q is technically
[6:39] a function of like the time and
[6:40] technically so is k but um this
[6:43] dotproduct doesn't explicitly account
[6:45] for time in any way and in particular
[6:46] like um they don't necessarily know how
[6:50] like far apart they are or anything like
[6:52] that like they don't they don't actually
[6:54] know like if if you saw the same key
[6:56] like if k of zero and k of one were the
[6:58] same you'd have no way to distinguish
[6:59] them in this computation which could be
[7:01] a
[7:02] So this is where you have a few options.
[7:05] Um the choice that we uh that I made
[7:09] like for this post in how to proceed is
[7:11] like let's just say we are going to
[7:14] modify our queries and modify our keys
[7:17] in some explicitly time dependent way.
[7:19] So now we have let's call this like I
[7:22] don't know Q twiddle of t is like
[7:25] there's some query modifying function
[7:27] that takes in a uh time and it takes in
[7:31] the query at that time
[7:33] >> and it spits out some modified query and
[7:35] then you do the same for for your t's.
[7:37] So so k twiddle of s is some g of s uh k
[7:43] of s. In the original transformers, this
[7:47] would have been like adding your
[7:49] sinosoids. Um, but then like in in rope,
[7:52] this would be a rotation. Um, so you
[7:54] kind of these are just arbitrary
[7:56] functions. So far, I haven't really said
[7:57] anything about like what form they'll
[7:59] take. Okay, so one thing to notice is
[8:01] like why why am I like saying that every
[8:04] Q can only get modified in one way? Like
[8:06] why why is this like changing all of our
[8:08] queries as opposed to like changing the
[8:10] like the dot products? like there are,
[8:12] you know, n squared pairs that we're
[8:14] dotproducting, but we're only allowing
[8:15] ourselves to modify like n things here
[8:17] and n things here. And this is kind of
[8:19] just for efficiency reasons. Like it's
[8:21] probably impractical to like you
[8:23] originally had, you know, n vectors, n
[8:26] query vectors, n keys. It's very likely
[8:30] impractical to blow that up into like n
[8:32] squared queries and n squared keys where
[8:34] you modify them differently for every
[8:36] single pair of times. It seems like just
[8:38] cleaner to say like, "Okay, we're just
[8:39] going to go like modify every query
[8:41] exactly once and modify every key
[8:43] exactly once."
[8:43] >> I admire your acknowledgement of broad
[8:45] generality [laughter] here because
[8:46] that's like a pretty reasonable
[8:47] assumption. Yeah. That it's just
[8:48] happening on each one.
[8:49] >> Yeah.
[8:50] >> Okay. So now, so now um we can rewrite
[8:53] our doproduct as uh between these like
[8:57] transformed things. So you got this q
[8:58] twiddle of t transpose
[9:02] k twiddle of s. Um we haven't like
[9:05] proved anything yet. We're just like
[9:07] trying to write down some [snorts] form
[9:08] to
[9:09] >> we've added we've added twiddles to the
[9:10] previous expression but the idea is that
[9:12] these are more time aware.
[9:13] >> Yeah. Exactly. Yeah. Right. Um okay. So
[9:18] as written it's really unclear how to
[9:20] analyze this at all. Um so now a
[9:22] question is like okay what what like
[9:24] might a reasonable person restrict our
[9:26] fng? Because fng are literally arbitrary
[9:28] functions. They could be like
[9:29] arbitrarily badly behaved. Um we
[9:31] probably need to like add some
[9:32] restrictions to make sure we do
[9:33] something reasonable. The big
[9:35] restriction that I wanted to impose is
[9:38] linearity. And I think this one is a
[9:40] little bit tricky to like rigorously
[9:41] justify. Um in my mind it was like okay
[9:45] we're working with these two vectors.
[9:46] We're taking inner products. This is
[9:48] like very much like an inner product
[9:50] space problem.
[9:51] >> Um like linear maps are kind of the
[9:54] natural maps to consider here. If you
[9:57] allow for nonlinear maps, there's like
[9:58] this whole other universe of things. uh
[10:01] in practice, the fact that like nothing
[10:03] that I found in practice was using
[10:04] nonlinear maps anywhere made me more
[10:06] confident that like no one will be too
[10:08] sad about making this assumption and so
[10:11] it's probably just fine.
[10:12] >> Again, I admire your hat to generality
[10:14] because it seems very reasonable
[10:15] thinking f is going to look like some
[10:17] matrix dependent on T times Q, right?
[10:20] Like that's not a that doesn't at all
[10:22] feel like an unreasonable thing in the
[10:23] context.
[10:24] >> Yeah. Yeah. So that's that's the first
[10:25] big assumption, but it's actually a
[10:26] really important one because it takes us
[10:29] from this like infinite space of
[10:31] possibilities on f to a very specific
[10:34] shape. In particular, F is now a matrix.
[10:36] Um well really it's an indexed family of
[10:38] matrices. We depend on T. Mhm.
[10:40] >> Um so so now we can you know write a
[10:43] much simpler or at least a much more
[10:46] concrete expression here which is um
[10:51] this is going to be some I'll change the
[10:53] capital f for this matrix um f of t q of
[10:57] t and likewise for this k we'll say it's
[10:59] some capital g of s uh k of s. Um
[11:06] this is nice because if we're working in
[11:08] like d-dimensional space, we've gone
[11:09] from completely arbitrary functions to
[11:12] like you know d square numbers here and
[11:14] d square numbers here, you know, subject
[11:15] to um depending on t and s.
[11:18] >> Mhm.
[11:18] >> Um so this already makes things more
[11:20] kind of concrete and now we can usefully
[11:23] plug this back into our little dot
[11:24] product here. And so this is going to
[11:26] become um Q of T
[11:31] uh transpose
[11:33] F of T transpose G of S K
[11:39] [clears throat] of S.
[11:41] Um
[11:43] >> and then you've got this nice little
[11:44] like quadratic form going on.
[11:46] >> Yeah. Yeah. And like you can kind of
[11:49] think of this as like defining this guy
[11:51] like defines the dotproduct in this like
[11:54] Q like there's some pairing between your
[11:55] queries and your keys and like all of
[11:57] that info about that pairing is wrapped
[11:58] up in this little product here. Um
[12:01] >> and this is just much more concrete
[12:04] already. Um now it's time to write down
[12:08] a few more assumptions. Uh I think the
[12:10] big one and like really the kind of
[12:12] driver of all these results is going to
[12:15] be this idea of translation variance. We
[12:18] really want this positional encoding
[12:20] like its effect to only depend on the
[12:23] difference in times. Um like the way
[12:26] like the tenth token looks at the fifth
[12:29] token should be the same way like the
[12:30] 110th token looks the 15th token like
[12:33] that.
[12:34] >> Um
[12:34] >> so this whole inner expression you want
[12:36] to think of it as something that depends
[12:37] only on the difference between uh TNS.
[12:40] >> Yeah, exactly.
[12:42] >> Again, like quite reasonable. Also, it's
[12:44] a very physicist way of thinking, like
[12:46] very Not's theorem. You're looking at
[12:47] like, okay, there's a symmetry here.
[12:49] Like, how does that symmetry, you know,
[12:50] translate into uh, you know, some
[12:52] constraint,
[12:53] >> right? Right. We'll actually just say
[12:55] like we're going to define this new
[12:56] quantity um, a of t minus s is equal to
[13:03] f of t transpose
[13:06] g of s.
[13:08] um and like this quantity being well
[13:11] defined I mean you can really say like
[13:12] these expressions by this assumption
[13:14] have to coincide and so you can like
[13:16] define this quantity based on that
[13:18] otherwise this would vary depending on
[13:19] the exact choice of T and S but this
[13:21] makes this well defined um so now we've
[13:23] actually kind of like in some gotten rid
[13:25] of the idea of distinct F and G all the
[13:27] all the interesting parts of this are
[13:29] wrapped up in this matrix A and you can
[13:33] kind of think of this matrix A as
[13:34] telling you how to like take a key at
[13:37] time s and like move it forward into the
[13:40] same space as this query at time t to
[13:43] make them like possible to operate like
[13:44] like
[13:45] >> more abstractly we might even just say
[13:47] like you know actually we're not allowed
[13:49] to take products of things at different
[13:51] times until we like shift this key
[13:53] forward to time t. So like in the
[13:56] language example, it's like if this um
[13:58] if this key is like encoding some
[14:00] adjective or something like that, then
[14:03] you want the thing in the middle to say,
[14:04] hey, the things that are only like
[14:06] immediately ahead of you are going to be
[14:07] like the nouns that you influence. Or
[14:09] more broadly, if this key is just
[14:11] representing some embedding at some
[14:13] point in time, it's like a tells you
[14:14] once you've stepped forward by a certain
[14:16] amount, how much influence should you
[14:18] have on all the stuff that lives at that
[14:20] like future time step?
[14:21] >> Okay.
[14:22] >> Yeah. Yeah. A is this like it's somehow
[14:25] like what is the meaning of this
[14:28] adjective like now that we are end like
[14:31] now that we like t minus a steps later
[14:33] like the the meaning of the adjective is
[14:34] like shifting over time and like at some
[14:36] point it's probably irrelevant because
[14:37] it's too far back. So now the question
[14:39] is like what are like good like what
[14:42] what are like the reasonable choices of
[14:43] a and what they imply. Um
[14:47] so one more thing that I'm going to see
[14:49] and this is like highly motivated by
[14:51] this kind of intuition here about like a
[14:54] is like telling you how to like move
[14:55] things through time. Um I'm going to
[14:58] demand that a of zero is the identity.
[15:02] Um
[15:02] >> okay
[15:03] >> and this is and like in that earlier
[15:05] intuition it's kind of like saying like
[15:07] well if you're not moving anything
[15:08] through through time then there's
[15:10] nothing to do. You're just like happy
[15:12] with your original like value. You have
[15:14] your original K of S. You have your
[15:15] original Q of T. So, um, A of Z is I.
[15:21] Um, and if you trace this through, this
[15:23] is just saying that when you have a a
[15:26] query and a key at equal times, we're
[15:28] happy to look at the unmodified
[15:30] dotproduct.
[15:31] >> Um, you can kind of convince yourself
[15:33] that like if it's if this were any
[15:35] invertible matrix and not the identity,
[15:36] you could actually just fold that matrix
[15:38] into your keys in some time independent
[15:41] way. Um if you said got like you know a
[15:44] of 0 equals m then you could redefine
[15:48] like actually I want my keys to be um
[15:54] like m uh k of t and then like you just
[16:01] basically you do this like folding in
[16:02] and then you like replace your a of zero
[16:03] with identity and you've gotten the same
[16:05] outcome without and this is like a time
[16:07] independent transformation so it feels a
[16:09] little bit weird to like declare that as
[16:10] part of the pal encoding. This is kind
[16:12] of like, you know, like this is really
[16:13] just a change in all of your keys
[16:15] uniformly. Has nothing to do with how
[16:16] you care about time. Um, so I think
[16:18] there's some some reasonable
[16:20] justification for that one. Like you
[16:21] haven't actually lost much or any
[16:22] generality by making this particular
[16:24] assumption. You had some nice like
[16:26] diagrammatic ways of uh holding this in
[16:30] your head. Great. Okay. Okay, so if this
[16:31] like f of something time g of something
[16:35] um is describing that part that sits in
[16:37] the middle that says like how much does
[16:38] time influence stuff, then all you
[16:40] really care about for its value is
[16:41] difference in S&T and t. So it's kind of
[16:43] like you want to collapse along the
[16:44] diagonal. Um
[16:46] >> yeah. Yeah. All these diagonals are
[16:47] constants. So you just care about which
[16:48] of the counter diagonals you're on.
[16:50] >> Yeah. And so
[16:51] >> that's the that's the difference.
[16:53] >> Yeah. So when we're thinking of it, it's
[16:54] like a of zero is describing the
[16:56] relationship between, you know, tokens
[16:57] at zero, tokens both at one, tokens both
[16:59] at two. where like negative one moves
[17:02] you back in time one unit. Um yeah,
[17:04] which is again I think abundantly
[17:06] reasonable. Um and so and then a of zero
[17:08] being the identity is where you were
[17:10] saying. Um and and so if that's the case
[17:12] then a is enough to tell you you can
[17:14] like recover f and g uh from that right
[17:16] like if you
[17:18] >> yeah up to some like common rotation
[17:20] that's irrelevant because it vanishes in
[17:21] the dotproduct. Um so like you can
[17:23] always like given a choice of A um we
[17:27] we'll see actually how given a choice of
[17:28] A you can recover F and G because
[17:30] that'll kind of be like the the punch
[17:33] line in some sense.
[17:33] >> So could I let A be just any arbitrary
[17:36] um time dependent matrix and like invent
[17:38] my own positional encoding.
[17:40] >> Ah okay so we have some consistency
[17:42] requirements and actually I should write
[17:43] down the positional yeah let's go
[17:45] >> I should write down translation
[17:46] invariance somewhere specifically
[17:48] because I think it'll be useful to refer
[17:49] to that. So the translation variance
[17:51] property we can write as um I guess like
[17:56] f of t transpose g of s is equal to um
[18:04] f of t minus s transpose g of zero. Um
[18:11] [sighs]
[18:12] this is good enough because it's kind of
[18:14] like saying we can always put things at
[18:16] g of zero and so like this is just a
[18:19] fixed quantity. This has like we've kind
[18:21] of taken this like two parameter
[18:22] function like it takes like t and s and
[18:24] gives you some matrix and said like
[18:26] secretly this is like a onedimensional
[18:28] thing. There's one parameter t minus s
[18:30] and that just defines a whole quantity
[18:31] and like this um should coincide with um
[18:37] >> a of t minus s.
[18:38] >> Yeah. A of T minus S.
[18:41] Um okay. And then so by bying A of Z
[18:45] equals identity, we specifically now
[18:47] conclude um f of t transpose g of t is
[18:54] equal to a of 0 equals identity. So uh
[19:00] yeah. So we we just get this inversion
[19:02] relationship between these two. f of
[19:05] tanspose equals g of t inverse.
[19:10] >> Um, okay. So, now there's a bit of a
[19:13] leap of intuition required, which is
[19:15] like we're going to do something that's
[19:16] not innately
[19:18] obvious, but we're going to multiply two
[19:20] a matrices together and just see what
[19:22] happens. Um, and I think this is like
[19:25] not at all obvious why you'd do this if
[19:27] you were just looking at this from the
[19:28] perspective of like computing attention
[19:30] weights. like at no point do you
[19:31] actually ever have to actually multiply
[19:33] two of these A matrices together while
[19:34] computing attention scores. But if you
[19:37] think of A as this like bridge from time
[19:40] you know zero to time T and or like from
[19:43] time um S to time T it is it is kind of
[19:47] natural to say like if you take this
[19:48] bridge once and then you take this
[19:49] bridge a second time to get different
[19:51] yet another time like what happens like
[19:54] it does a very like natural pop out.
[19:56] Someone uh conversant in group theory
[19:58] wants to ask this question with like a
[20:00] delightful abandon for whether or not
[20:02] anywhere inside the like computations
[20:04] being done um like in hardware, right?
[20:07] That you'd ever have like two A matrices
[20:08] multiplied,
[20:09] >> right?
[20:09] >> Makes sense to me. So you're just trying
[20:11] to understand the theory of what A
[20:12] should be. And so
[20:13] >> yeah, it's like a structurally natural
[20:14] question to answer even if it never like
[20:16] quite shows up in the practical
[20:18] application we're we're looking for. So
[20:20] I guess like the like let's just let's
[20:22] just see what happens if we just take a
[20:24] of s um times a of t. Um and like
[20:32] intuitively what's supposed to happen
[20:33] here is like we're going to like a of s
[20:36] tells you how to move from like zero to
[20:39] s and then a of t tells you how to move
[20:41] from zero to t but also how to move from
[20:43] s to s plus t.
[20:45] >> So you expect this to be a of s plus t.
[20:46] Yeah, we have some guess that maybe this
[20:48] is going to be a s plus t and like what
[20:50] actually happens when you do this out.
[20:52] Well, um we can expand this in terms of
[20:55] our uh f and g matrices. Uh we got so
[20:59] let's see are we like plugging in this
[21:00] part? Oh yes.
[21:04] Um so like we'll plug in this um yeah
[21:08] maybe I should have written this as like
[21:09] an actual definition a rather than this
[21:11] uh almost a little bit too general
[21:14] definition. I think the actual
[21:15] definition we're we're interested in is
[21:17] this um f of t transpose g of zero. Um
[21:24] okay so and that's like equivalent to
[21:26] the previous thing because of the
[21:28] translation variance and like this tells
[21:30] you the more general thing.
[21:32] >> Um
[21:33] okay so when we write this out we just
[21:35] expand both of these terms. So first we
[21:38] get um f of s transpose
[21:43] g of z
[21:45] um
[21:47] f of t transpose
[21:52] of zero.
[21:53] >> Mhm.
[21:54] >> Okay. Um
[21:56] now we this this middle product like
[22:00] could have some interesting interaction.
[22:02] Um, we can make this much more explicit
[22:05] by just translating this left side
[22:07] forward by T, which we're allowed to do
[22:09] because of this this relationship. Like
[22:11] we know we can like subtract or add any
[22:14] common quantity from the arguments of
[22:16] this frrpose and this G without changing
[22:18] anything.
[22:18] >> So both of these you're going to add a T
[22:20] to.
[22:20] >> Yeah, exactly. I'll just like maybe mark
[22:22] that here. I'll say I'll add a plus T
[22:24] there and a plus T there, which is fine
[22:25] by translation variance. Um so this is
[22:28] all equal to um f of s + t transpose
[22:35] g of t
[22:37] f of tanspose
[22:40] g of zero. Um okay but now we recognize
[22:43] something which is that these guys are
[22:44] inverses. Yeah
[22:45] >> that's very convenient. We can just
[22:46] eliminate that whole thing. Uh and what
[22:48] are we left with? We got an f of s plus
[22:50] t transpose and a g of zero. And if we
[22:52] look back at our definition well that
[22:54] looks familiar.
[22:56] So this is just a of s plus t.
[23:00] >> That's very neat. Okay.
[23:02] >> Yeah. So just as we hoped, when you like
[23:04] have this translation from 0 to s and
[23:06] then this translation from 0 to t, um
[23:10] you like compose these and you get a
[23:11] translation from 0 to s plus t.
[23:13] >> And just so that I'm I'm following like
[23:14] why it all happened, we're using the
[23:17] translation invariance on um being able
[23:19] to move that forward. And then we're
[23:21] using the inverse that came about from
[23:24] ultimately from the assumption that like
[23:26] uh its action at zero is the identity.
[23:28] Okay. Yeah.
[23:29] >> But you already kind of led in with the
[23:31] intuition on like if you think of what A
[23:33] is doing as like translating hey what's
[23:36] happening at time s and you want to like
[23:37] move forward or just what's happening um
[23:39] that's one time and you want to move
[23:40] forward by s and this is like telling
[23:42] you how that should uh change the the
[23:45] influence there. It like it's a very
[23:48] believable
[23:48] >> Yeah. I think there's something a little
[23:50] bit circular about what I've done here
[23:51] where like I've like written down all
[23:53] these assumptions that like kind of
[23:54] demand this structure and then gone like
[23:56] wow the structure popped out. But I
[23:58] think like hopefully I've you know
[24:00] motivated a that's partly why I spend so
[24:02] much time kind of talking through like
[24:03] why these demands on this structure are
[24:06] pretty reasonable ones like why I think
[24:09] like
[24:09] >> no one would really object too much to
[24:11] like adding these constraints and then
[24:13] because then once you like are willing
[24:15] to add all those constraints you can get
[24:17] some very kind of concise description of
[24:19] of what you've you've built here. You
[24:21] end up with like a very like rigid kind
[24:22] of object. Um it like has to follow this
[24:26] nice consistency. So this is kind of the
[24:29] this is the big observation really
[24:31] because
[24:32] this is that consistency that I kind of
[24:34] alluded to earlier where it's like
[24:37] um you have something where addition in
[24:40] the argument of a corresponds to
[24:42] multiplication in the A matrices
[24:45] themselves.
[24:45] >> Right. Right. Right.
[24:46] >> And that's the heart of like everything
[24:49] that comes after this. And even someone
[24:51] who's not like familiar with group
[24:52] theory or representation theory, if they
[24:54] see this and they like squint their eyes
[24:56] and forget the fact that A is supposed
[24:57] to be a matrix, I think what immediately
[24:59] like pops into their mind is to think,
[25:01] hey, if I have addition and it turns
[25:03] into multiplication, that should look
[25:05] like some kind of um like exponential.
[25:08] Uh and that's like you see this equation
[25:10] and it screams out like exponential. But
[25:12] of course, this is, you know, if you're
[25:13] just a like a high school student
[25:15] thinking about real numbers, it's not as
[25:16] obvious what that would mean uh when A
[25:18] is a matrix, unless you happen to have a
[25:21] background in physics or representation
[25:22] theory or something like that.
[25:24] >> Um I actually for you, so like at this
[25:27] point, you see this, you're in the know,
[25:29] you think like, all right, I know I'm
[25:31] going to land on exponentials in some
[25:32] form. For you like noodling around with
[25:34] this, uh was that the direction of the
[25:36] logic or was it that you kind of
[25:38] recognized backwards going in? and
[25:39] you're like, "Hey, a lot of these
[25:40] positional encodings seem to have like a
[25:43] certain exponential feel to them. Can I
[25:45] justify why that must be the case?"
[25:47] >> Yeah, I think I I definitely started by
[25:50] like, you know, when you read all this
[25:51] literature, you like you go like, okay,
[25:53] some of these have actual exponentials,
[25:55] some of these have rotations, which are
[25:56] really just complex exponentials. So,
[25:58] like
[25:59] >> these have got to be coming from
[26:00] somewhere.
[26:01] >> Um, like what like what kind of
[26:03] motivation gives rise to these? Uh, and
[26:05] I'm like I'm far from the first one to
[26:07] make this observation that like
[26:08] representations of certain groups show
[26:11] up in positional encodings. Um, this
[26:13] gets talked about more explicitly in um
[26:15] positional encodings for images because
[26:18] in images you don't just have one
[26:20] direction of travel that you're kind of
[26:21] trying to encode with these. You have
[26:23] like two like it's a 2D object. Uh, so
[26:26] you apply transformers to images. A
[26:28] pretty common thing to do is like you
[26:30] actually have two-dimensional positional
[26:32] encodings and then like it is pretty
[26:35] useful to do some math to figure out
[26:36] that like just to make sure that like
[26:38] when you're composing two dimensions of
[26:39] positional encodings you're like doing
[26:41] something sane. So I think um yeah
[26:44] people who think about that kind of
[26:45] stuff do sometimes do fairly similar
[26:48] math to try and make sure they are like
[26:50] giving in their case uh what's called
[26:52] like a representation of like our direct
[26:56] sum r I guess like it's a a sum of two
[26:59] copies of this of this additive group.
[27:01] >> Maybe we can show that also. [laughter]
[27:03] I'm I'm jumping ahead a little bit just
[27:05] because you know I see this expression
[27:06] and and it's hard not to to write down
[27:08] the the um the letter E. Um yeah.
[27:10] [laughter] Do you want to carry forward
[27:12] where I mean that really is it right?
[27:14] It's
[27:14] >> Yeah. So I guess I can give a little bit
[27:15] of motivation here like a quick like you
[27:18] know not very rigorous proof that like
[27:20] the thing we're going to get out of this
[27:22] is exponentials.
[27:22] >> Okay.
[27:23] >> Um
[27:25] totally safe free up this portion.
[27:27] >> Um
[27:28] >> um hopefully at this point it's like
[27:29] pretty clear. You see a you think of it
[27:32] as
[27:33] >> uh
[27:34] >> what is it that you squish in between
[27:35] your your key and query embeddings to
[27:37] account for the time difference. try to
[27:39] leave these alone because the you know
[27:40] definition helpful. Yeah.
[27:41] >> Yeah.
[27:43] >> Um okay. So if we assume that a is um
[27:47] differentiable I think one thing we can
[27:50] do is take a derivative with respect to
[27:54] t near t equals 0. Um I'm not going to
[27:57] attempt to motivate why this is a useful
[27:59] [laughter] thing to do. I'm just going
[28:00] to say like like I guess the zero choice
[28:02] is reasonable because like I think we
[28:04] zero is the one place we have grounded
[28:06] the value of a. Yeah.
[28:07] >> Um okay. So what I'm using derivative um
[28:12] >> which is a side note is just a great
[28:14] justification for why thinking of time
[28:16] continuously
[28:18] >> like this would not be a question to ask
[28:19] if you were just giving like integer
[28:21] indices.
[28:22] >> Yeah I mean this whole thing is actually
[28:23] a lot easier if you just have integer
[28:24] indices because you can just say like we
[28:27] can just get from zero to anywhere by
[28:28] adding one repeatedly [laughter] which
[28:30] is actually quite a bit simpler in some
[28:32] sense. Um
[28:34] >> well we're being delightfully uh not
[28:37] it's not over complicated it's general.
[28:39] Yeah. Yeah.
[28:41] [laughter] Um t equals z.
[28:46] Um
[28:56] so this left hand side we should get
[29:00] well this a this first a s term doesn't
[29:02] contribute. So that's just stays as a
[29:04] coefficient. Um this a of t term
[29:06] >> a prime
[29:07] >> is just going to be a prime of t
[29:10] evaluated at t equals z. And on the
[29:12] right hand side we again just get a
[29:15] prime but this time of s.
[29:17] >> Mhm.
[29:18] Um well I guess that's supposed to t
[29:20] evaluate at t equals z a prime of s.
[29:22] >> Yeah.
[29:22] >> Um okay so now we get a of
[29:26] s
[29:29] a is there is there a reason we didn't
[29:31] just write a prime of zero. Uh I
[29:33] probably should have just done that. It
[29:34] seems seems a little nicer.
[29:41] Okay.
[29:41] >> Um yeah. Okay. This is actually this is
[29:44] actually just the crux of it. Um,
[29:46] >> so we got a thing whose derivative is
[29:48] equal to some constant matrix times
[29:51] itself.
[29:52] >> Yeah.
[29:53] >> Right. So we can we can just say like
[29:54] what we'll say a prime of zero. We'll
[29:55] just call this like some x. Um, so now
[29:59] we have a of s x= a prime of x s. Um,
[30:05] and like if you see this differential
[30:07] equation over like the real numbers, you
[30:10] immediately know like this is an
[30:11] exponential. Um, it turns out the same
[30:13] is true over over matrices. kind of by
[30:15] definition.
[30:16] >> Yeah. Yeah, that's actually a good way
[30:17] to define the matrix exponential.
[30:20] >> Um, cool. So now we uh Yeah. So the
[30:24] solution this just ends up being um a of
[30:28] s.
[30:37] >> Um okay. So we solve the differential
[30:39] equation. We get a of s is equal to a of
[30:42] zero e to the sx. that's just ends up
[30:45] being the solution. Um, but we actually
[30:47] already know that a of zero is identity.
[30:48] So we don't actually care about this
[30:49] term or this factor. Um, so this is
[30:52] pretty clean. Just a of s is e to the
[30:55] sx.
[30:56] >> Is it worth
[30:57] >> and again maybe this is something it's
[30:58] like you're sort of assuming uh everyone
[31:00] knows but just uh e to the if if you
[31:04] have a matrix and you're taking e to the
[31:07] matrix. It's like not immediately clear
[31:09] what that is, but yeah, just I mean
[31:13] again it's maybe people already know
[31:14] this, but it's going to be
[31:16] >> basically you do your Taylor's
[31:18] expansion. Um
[31:21] uh but you're you're just like taking
[31:23] whole number powers of your matrices of
[31:25] your matrix which is like perfectly well
[31:27] defined because as long as it's a square
[31:29] matrix then you're able to um 1 over six
[31:32] times that as long as it's a square
[31:35] matrix you can just take powers of it
[31:36] and uh someone in the no might ask about
[31:38] like convergence of that. Um but then
[31:40] someone really in the know would think
[31:41] about Igen values the like the
[31:43] differential property is maybe the the
[31:44] thing to think about. It's like it it is
[31:47] something it will evaluate to something
[31:49] and like by definition it's a thing
[31:50] whose derivative looks like some um some
[31:53] matrix times times itself.
[31:55] >> Yeah. Although actually I'm glad you
[31:56] brought that up because we are going to
[31:57] need that tailor expansion when we try
[31:59] to get into the weeds of like what have
[32:00] we actually done with this matrix.
[32:03] >> Great.
[32:03] >> Um
[32:05] okay so now we're at this point of like
[32:07] we kind of like have all the solutions
[32:09] like like from everything we've done
[32:11] we've like this is it. This is the space
[32:14] positional encodings according to the
[32:15] assumptions we played down. But now we
[32:17] need to know like what how to
[32:18] characterize this like like can we pull
[32:20] out like familiar pieces? Can we find
[32:22] unfamiliar pieces that are like
[32:24] described by these dynamics?
[32:26] >> So like the analogy would be um with
[32:28] real numbers once you solve this
[32:29] equation you have like it's e to some
[32:31] constant times t. And like that constant
[32:33] being positive means you have growth.
[32:34] That constant being negative means you
[32:36] have decay. And like those are the two
[32:37] qualitative things that can happen. If
[32:39] complex numbers enter the chat, that
[32:41] constant could be imaginary and you're
[32:42] allowed for rotation, but that's the
[32:44] universe of things that can happen. And
[32:45] so you're sort of asking depending on
[32:47] what we make X, what's the universe of
[32:50] things that could happen that like
[32:51] presumably have feelings of like growth,
[32:54] decay, and rotation because that's what
[32:55] happens in our more like happy golucky
[32:57] land of real and complex numbers.
[33:00] >> Yeah. And like because you can for every
[33:02] like for for a given real number you can
[33:04] just promote it to a matrix by saying
[33:06] like real number times identity matrix
[33:07] you can get exactly those those dynamics
[33:09] but like because we're working with
[33:10] matrices there could just be more out
[33:12] there in addition to that.
[33:14] >> Yeah. So um
[33:16] >> I think you're safe to erase.
[33:18] >> Yeah that sounds sounds good.
[33:28] Um okay so now I want to make one more
[33:32] kind of simplifying assumption which is
[33:34] that um changes of basis in our keys and
[33:37] our queries just don't matter to us.
[33:40] >> Um like in particular like changes of
[33:42] basis that are kind of time uh like time
[33:45] invariant or something like that. Like
[33:46] if we if we wanted to redefine our our
[33:48] queries as like actually Q is going to
[33:52] be replaced by like Q is actually going
[33:54] to be like some
[33:56] rotation matrix uh times our old Q. Um
[34:01] >> this doesn't have anything to do with
[34:02] time. We're just going to say that's
[34:03] like from a positional encodings point
[34:05] of view. This is a noop. From a neural
[34:06] network's point of view like our linear
[34:08] layers can deal with that. That's not
[34:09] our problem in the positional encoding.
[34:11] >> Okay. um that so this actually does make
[34:14] our life easier because we that means we
[34:16] only need to care about these matrices a
[34:20] up to some change of basis.
[34:23] >> Okay.
[34:23] >> Sure.
[34:24] >> Um like we are or and actually the same
[34:26] is true for X because it turns out like
[34:28] when you apply change of basis to X you
[34:30] end up applying exactly the same change
[34:32] of basis to A
[34:33] >> which makes sense because you're just
[34:34] doing it to every one of these.
[34:35] >> Yeah. All of the kind of internal
[34:37] products cancel and so it just works
[34:39] out. Um,
[34:41] okay. Well, I guess if you're familiar
[34:44] with learning algebra, when you see we
[34:46] only care up to a change of basis and
[34:47] you see an exponential, your mind kind
[34:50] of goes to diagonalization.
[34:52] >> Um, and like this is this is exactly
[34:53] that value thing like you mentioned
[34:55] earlier. Um like most matrices um for
[35:00] some technical definition of most can be
[35:02] diagonalized and in particular
[35:03] diagonalize X. Um so let's say like um
[35:08] let's say X just has this shape. Uh it's
[35:10] like lambda 1, lambda 2, lambda n and
[35:15] some big zeros over here. Um so this is
[35:19] nice. Um though the reason this is
[35:22] really nice is that when you
[35:23] exponentiate it, nothing else like there
[35:26] no interactions between these guys. Like
[35:28] e to the tx is just going to be
[35:32] like e to the t lambda 1
[35:35] >> down to e to the t e to the
[35:40] [gasps]
[35:42] lambda n.
[35:44] Uh and then I think all these guys stay
[35:46] the same. Um and you'll notice like when
[35:49] you multiply this by any vector uh or
[35:52] when you really when you do this whole
[35:53] like you know q um e to the tx k there's
[35:59] no interaction here u between the
[36:01] different components of q and k like the
[36:03] first component of q and the first
[36:05] component of k interact via this
[36:07] diagonal first the diagonal but like the
[36:09] first component of q and like the second
[36:11] component of k there's just a big zero
[36:13] on all the off diagonals so and there's
[36:17] like intuitively I mean again maybe
[36:19] we're assuming people are comfortable
[36:20] with diagonalization
[36:22] which is probably true but like uh
[36:24] intuitively the reason that they don't
[36:25] interact here is if you look at the
[36:27] actual expansion of it and you say hey
[36:29] what does it look like to square a
[36:30] matrix if it's diagonal you're just like
[36:32] squaring the diagonal entries what does
[36:33] it look like to cube it if it's diagonal
[36:35] you're just cubing the diagonal entries
[36:37] so this whole sum where usually all the
[36:39] powers of m like result in all this
[36:40] complexity of everything kind of like
[36:42] mixing together in it there's none of
[36:44] that it's just applying those powers
[36:46] along the diagon
[36:47] And like the vague intuition is hey if
[36:49] you're able to change your basis freely
[36:51] and you choose a bas the igen basis
[36:53] something where the way that the matrix
[36:55] acts along any one of the subspaces is
[36:57] like confined to that subspace the
[36:59] spaces sort of don't interact with each
[37:00] other. Whatever it's doing to this
[37:01] subspace you just study it there.
[37:03] Whatever it's doing to this subspace you
[37:04] just study it there. Um and so yeah it's
[37:06] kind of like you've you've broken it up
[37:08] into its particles for just and and and
[37:10] also maybe important to mention lambdas
[37:12] they can be complex. When we talk about
[37:14] diagonalizing, we mean like
[37:15] >> Yeah. diagonalizing with complex values.
[37:18] >> Yeah. And this is like this is exactly
[37:20] the value of this like value formulation
[37:23] like by changing basis into this like
[37:25] this this basis where the matrix is
[37:27] diagonal. We've like it's like it's kind
[37:30] of like a magical fact that it's
[37:31] possible to pick a basis where there's
[37:33] no interaction in the different
[37:34] components. Totally. Um so that's like
[37:36] that's really what makes this this work.
[37:38] Um and so yeah, so this this product
[37:42] ends up like really splitting up into
[37:44] like this sum of scalar products like
[37:48] the sum over j of like uh q j uh this is
[37:55] confusing. Oh my actually and this is
[37:57] fine. I guess we haven't actually used
[37:59] this for um which q we're talking about.
[38:01] So this is gonna be yeah [laughter]
[38:03] >> it's helpful. um e to the t lambda j
[38:09] um k j. Um and so yeah, this like this
[38:12] like just decomposes into this nice sum
[38:14] over the individual basis components and
[38:17] again there's no interaction between
[38:18] like like J and some other like J+ one
[38:21] will never are never going to mix here.
[38:23] Um, and I'll emphasize even though like
[38:26] symbolically it sort of looks very
[38:27] similar, like there's a very different
[38:29] emotion in thinking about that as being
[38:31] an operator in the exponent versus
[38:32] thinking about it as just being a number
[38:34] because like this one, like, oh, it's a
[38:35] number. We know what that does. It's
[38:36] like it grows, it decays, or it rotates.
[38:38] It's like a very well understood thing.
[38:39] I don't I remember being kind of mind-b
[38:41] blown by that as an undergrad where like
[38:43] there's this initial feeling of
[38:44] explosion when you learn about matrix
[38:46] exponentials. It's like this could be so
[38:48] complicated and then if it's
[38:49] diagonalizable, you're like, oh,
[38:50] actually like there's nothing new under
[38:52] the sun here. Yeah, it's like it's
[38:53] almost like the next level of the
[38:55] feeling in like pre-calculus when you
[38:56] learn like complex exponentials and
[38:58] trigonometry are just the same thing.
[39:00] >> Exactly.
[39:00] >> And of course there is like a little
[39:02] asterisk here because like not
[39:03] everything's diagonalizable, but we'll
[39:04] we'll get there.
[39:05] >> Yeah.
[39:06] >> Um
[39:07] >> um okay. Okay. So, I think it's worth
[39:08] being pretty explicit about like what um
[39:11] what like these components look like
[39:14] because actually because this breaks
[39:15] down so nicely. The reason I'm even like
[39:17] writing this out this way is because
[39:19] it's we kind of get all of the the math
[39:22] by just looking at like a single
[39:24] component and how like just one element
[39:27] interacts with like some element of Q
[39:30] and some element of K. Um and then we
[39:32] just like add them all up at the end. Uh
[39:35] which is relatively straightforward. So
[39:37] now, so we're going to zoom way in. It's
[39:39] just one component.
[39:41] >> Um,
[39:42] >> but I lied a little bit because actually
[39:43] in some cases we're going to want two.
[39:45] And the distinction here is whether um
[39:47] whether this lambda is going to be real
[39:50] or um complex.
[39:52] >> So I think we can, you know, redcon that
[39:57] a was going to be real valued. That's
[39:59] probably fine. [laughter] Like I think
[40:02] probably no one was was actually that
[40:03] concerned about that. Um yeah but it's
[40:05] worth worth stating because when you
[40:07] diagonalize a real valued matrix there
[40:10] are two kinds of things that can pop out
[40:13] you can get so first we'll look at the
[40:14] the simpler case where you just get some
[40:17] like some element here like this lambda
[40:19] one say um let's just say like lambda
[40:22] one is like some real some z okay um if
[40:28] lambda one is just some real value z um
[40:31] that's great it stands kind of on its
[40:33] own um And then we get like some um
[40:38] something like q um uh let's see
[40:42] actually let's back up for a moment what
[40:44] a is um a of t is equal to e to the
[40:51] t z. Um and I'm completely abusing
[40:54] notation. A is a scalar now. Sorry. Um I
[40:57] guess you can put some brackets around
[40:58] it if you'd like. That's
[41:00] >> it's kind of wild to choose z as your
[41:01] variable for meant to be. That's fair.
[41:03] I'm not I'm not saying change it. I'm
[41:05] just kind of, you know,
[41:05] >> I can use a lower case X because it
[41:07] really is just the scalar version of our
[41:08] uppercase X.
[41:10] >> Okay. Sure.
[41:11] >> Yeah. So, we get some just this one by
[41:14] one matrix. Um, and now you can matrix.
[41:17] >> Yeah.
[41:18] >> Real number
[41:19] >> baby steps here. So, now we get some
[41:21] like
[41:23] >> Q
[41:25] E to the TX
[41:28] uh K. And I guess this is like Q of uh T
[41:32] I suppose. I'll make this a little
[41:34] bigger. [gasps]
[41:36] It's like Q of T that we're going to
[41:40] wrap up here. Uh K of 0 I suppose. Um
[41:46] and at this point you're just looking at
[41:47] this exponential. You can see like okay
[41:49] there are kind of three options to care
[41:51] about. There's like X is positive, there
[41:53] is X is zero, or X is negative. Um, and
[41:58] I think I might do I have a diagram of
[42:00] this.
[42:00] >> We can draw little graphs here, right?
[42:02] Because like if you think of this as
[42:03] basically saying how much is a token um
[42:06] at position zero going to influence a a
[42:09] token at position t, it's kind of like,
[42:11] okay, if we've got over here, here's
[42:13] your one token, and then here's another
[42:14] token out at t, how should that
[42:16] influence change? It's like, it would be
[42:18] kind of weird for it to grow. It's like
[42:20] the longer ago this was in the past, the
[42:22] more you should care about it, right? So
[42:24] this is like your x is positive case
[42:26] which is just kind of weird and then
[42:28] you've got uh it's like flat um like
[42:30] there's just no time dependence which
[42:32] >> right it's kind of degenerate but like
[42:34] >> it's like why you have positional
[42:35] encodings at all but like maybe you
[42:37] don't want but then what what feels way
[42:39] more reasonable I guess is like um if
[42:41] your x is uh I guess x is a little bit
[42:44] of a weird choice on like constant
[42:45] because you think x-axis but like in
[42:47] other case if the if the thing that sits
[42:49] in your exponent um as a constant is
[42:52] less than zero it's something that's
[42:53] decaying and Actually, I mean,
[42:55] intuitively that would kind of make
[42:56] sense that like the farther something is
[42:58] in the past, like you have this
[42:59] exponential decay, which like a lot of
[43:01] old school like um you know, time
[43:03] dependent neural network stuff, it's not
[43:05] so explicit. It's like implicit like
[43:07] RNN's and things like that where there's
[43:09] this certain like uh decay of influence
[43:11] over time. Um like maybe you want that,
[43:13] maybe you don't. But I guess what you're
[43:15] saying is right for for the for real
[43:18] valued lambda here, that's kind of like
[43:20] all you're left with as an option.
[43:22] >> Yeah. Yeah. Yeah. And like the zero
[43:23] case, even though it looks a little bit
[43:25] silly in isolation, you have to keep in
[43:26] mind we're looking at just a single
[43:27] component of a bigger matrix. So it's at
[43:29] least like probably fine to have the x
[43:32] equals zero case. Yeah. Like like some
[43:34] components maybe just you don't want to
[43:36] decay over time. Like they're actually
[43:37] truly time independent. So it's like
[43:39] okay to have some of those in the mix.
[43:41] But yeah, the x greater than zero case
[43:43] is definitely a problem because like the
[43:46] further you look back in the past like
[43:48] the exponentially more important things
[43:49] look is just like kind of inherently
[43:51] unstable. Um and in fact you do find it
[43:53] in the literature like people do
[43:55] sometimes use the like x is less than
[43:57] zero case here and it like in particular
[43:59] in linear tension this does in fact show
[44:01] up. Um
[44:02] >> okay that's interesting. Um and so then
[44:05] in the case where lambda's complex
[44:07] valued um
[44:08] >> yeah so now we um now we're actually
[44:11] want to use a slightly different form
[44:14] than this diagonal form because the
[44:16] complex value case like I mean the
[44:18] diagonal form is mathematically correct
[44:19] but it's not the most intuitive and it
[44:21] doesn't actually tie the best to kind of
[44:24] existing literature which is one of the
[44:26] things we would like to be able to do
[44:27] here.
[44:27] >> I guess like I don't know a nice example
[44:29] someone can hold in their head um maybe
[44:32] can I read it?
[44:33] >> Sure. Yeah.
[44:33] >> So let's say you have uh you want some
[44:36] matrix that's going to rotate things by
[44:37] theta
[44:39] just like in two dimensions. Um so this
[44:42] is also theta. And so if you write it
[44:44] down is you've got like your cos theta,
[44:47] your sin theta,
[44:49] your negative sin theta and your cos
[44:54] theta.
[44:56] Like this is diagonalizable. And what it
[44:58] would look like is having some imaginary
[45:01] value. I mean, we can even just write
[45:03] it.
[45:03] >> Yeah.
[45:04] >> Um, as like something that you've got
[45:06] kind of like an i and a negative i or
[45:08] something kind of like that. Maybe some
[45:10] constants, something like that.
[45:11] >> Yeah. Yeah. I I think you would in
[45:13] particular, I think the matrix you get
[45:14] is like when you try to diagonalize this
[45:16] is like e to the i theta 0 0 e to the
[45:20] negative i theta. Um, and so like the
[45:22] theta you can see like exactly how these
[45:24] complex rotations and the more geometric
[45:27] rotations do do nicely correspond here.
[45:30] um which is very important for kind of
[45:32] yeah part two of of this exploration. Um
[45:36] so let me let me see so with right so
[45:40] when you have a complex lambda with like
[45:42] any non-zero imaginary component because
[45:44] our original matrix we said was going to
[45:46] be real you're guaranteed to actually
[45:48] get these things in pairs. So you're
[45:50] going to get um this conjugate pair like
[45:55] uh z comma z conjugate and maybe we just
[45:58] write this as a plus b i for clarity um
[46:02] like a + b i comma a minus b i um and
[46:09] these are going to be in your x matrix
[46:13] >> this because it's a little
[46:14] >> sure yeah so um the diagonalized version
[46:18] of x and we'll just write like x diag um
[46:21] is going to look like this.
[46:30] Okay. Um it's actually useful to split
[46:33] this into like two parts. Um where it's
[46:38] like a i plus
[46:42] b
[46:43] uh i 0 negative i. Um
[46:49] it's partly this is yeah partly this is
[46:53] useful because this AI component like no
[46:56] matter what change of basis you do
[46:58] that's not going anywhere like that kind
[47:00] of like it's almost just completely not
[47:01] going to interact with anything else we
[47:03] do. Um, and in that includes like in the
[47:06] exponential like there's a whole
[47:09] complicated field of math around when is
[47:11] it valid to say like e to the a plus b
[47:14] equals e to the a
[47:17] >> e to the b. Uh but thankfully if one of
[47:19] these terms is just a * i, it's not that
[47:22] complicated. It just works.
[47:23] >> Okay.
[47:23] >> Um so we're now able to say like
[47:27] >> the general intuition isn't if they if
[47:28] they commute with each other then you
[47:30] can do that.
[47:31] >> Yeah. Um,
[47:33] so we'll just say like a of t uh equals
[47:38] as usual e to the tx and that's going to
[47:41] be um
[47:44] this like we're going to get an e to the
[47:47] a factor from this ai term and then
[47:50] we're going to get um
[47:53] >> it's nice to see that AI has shown up in
[47:55] the lecture. Yeah, sorry bad. Um,
[48:01] okay. So, I guess we need to actually
[48:02] talk about what this is. I'm just going
[48:04] to promise everyone that like this A has
[48:07] exactly the same role that X had here
[48:10] where like if A, if this real part A is
[48:13] positive, you get exponential blowups.
[48:14] That's bad. If it's zero, you get
[48:17] nothing, which is maybe fine. It just
[48:19] kind of drops out entirely and doesn't
[48:20] contribute. And if it's negative, you
[48:22] get exponential decay, which is also
[48:23] fine. Um but it is going to clog a bunch
[48:26] clog up a bunch of equations. So I'm
[48:28] going to mostly ignore it and just set a
[48:30] to zero for the most part. Um
[48:33] so we'll just ignore this term. Um this
[48:36] term though is um up to a change of
[48:39] basis. So it's like similar to this
[48:42] matrix. Um
[48:47] oh sorry no I need to exponentiate it
[48:48] first. Let's let's do that first. When
[48:50] you exponentiate this, you get um e to
[48:54] the x sorry e to the tx diag
[48:59] is equal to
[49:01] um it'll look like you have bi
[49:04] >> uh e yeah e to the b i 0 e to the
[49:10] negative bi. Um and this is for time
[49:14] dependent in each one of them.
[49:15] >> Oh sorry yes e to the bit t negative
[49:17] bit. Um as you see the bits have shown
[49:19] up in the lecture as well. [gasps]
[49:22] >> Yeah.
[49:22] >> Yeah. We're doing all kinds of computer
[49:23] science here. [laughter]
[49:24] Um [clears throat]
[49:26] so now it's really actually really
[49:28] important to get that correspondence
[49:29] between these kinds of matrices and
[49:31] these rotation matrices because it turns
[49:33] out this is like equivalent under change
[49:36] of basis to a uh rotation I'm just going
[49:41] to write this compactly for now as a
[49:43] rotation by bt and specifically this is
[49:47] going to be like like ta
[49:50] >> yeah so just like in fact we'll just
[49:51] write like r of theta
[49:53] >> um equals this guy.
[49:55] >> Can I pull up just the animation that
[49:56] you made for this? I I you know I feel
[49:59] like for those who are maybe have some
[50:01] familiarity with complex exponentiation
[50:03] and things it it's like not too
[50:05] surprising maybe that this is the energy
[50:07] that you end up getting out but I mean
[50:10] ultimately it does come down to you're
[50:11] saying what is this complex value that
[50:13] is your value and depending on you know
[50:16] that real part is giving you the
[50:17] exponential decay or growth and such but
[50:19] then the imaginary part well you see
[50:22] you're moving around the parameter did
[50:24] you contemplate making this like a nice
[50:26] you know vibe coding and interactction
[50:27] version where you're like uh moving
[50:30] around the bits.
[50:30] >> That's a good idea. Um yeah.
[50:32] >> Did you make this in manum by the way?
[50:33] >> This was in manum. Um
[50:35] >> you know it can be you can make it
[50:37] interactive.
[50:38] >> Oh okay. Good to know. This was a
[50:40] selfcoded by the way.
[50:41] >> Okay that's fair. That's [laughter]
[50:42] fair. Um okay great. This this is the
[50:44] part that I want. Yeah. Yeah.
[50:46] >> Pause an opportunity.
[50:47] >> Choosing a particular um a particular
[50:50] value for Z and just seeing what happens
[50:52] as the action of A. It's like the amount
[50:54] it rotates is based on the imaginary
[50:56] part. the amounts of decays is based on
[50:57] the the real part.
[50:58] >> Yeah. Yeah.
[50:59] >> I I think a lot of people will find that
[51:00] decently intuitive. And I guess the
[51:02] point that you want to hammer home in
[51:03] the spirit of saying like no really we
[51:04] are being as general as possible is to
[51:07] say any matrix that's diagonalizable
[51:10] when you look at a certain subspace that
[51:11] is what's happening on it, right? that
[51:13] there's like a change of basis between
[51:15] thinking of it in terms of like complex
[51:17] values that are staying to some subspace
[51:19] versus changing it to where like
[51:21] something more like this where you've
[51:22] got a twodimensional real subspace and
[51:24] there's rotation on that which there's a
[51:26] whole thing you could get into but like
[51:27] that I feel like that's a reasonable
[51:29] intuition because the upshot that you're
[51:30] aiming for here is like what can the
[51:32] time dependence look like and if at the
[51:34] end of the day on certain subspaces it's
[51:37] like growth decay and rotation are like
[51:39] the things that it can be like that's a
[51:41] satisfying conclusion we still have that
[51:43] asterisk on like what if it's not
[51:44] diagonalizable,
[51:45] >> right? So, so actually what you see here
[51:48] is the entirety of the like
[51:51] diagonalizable case. Um like we've we've
[51:54] restricted ourselves to like
[51:55] one-dimensional subspaces with real
[51:57] values on this side and two dimensional
[51:59] subspaces with complex values on this
[52:02] side. Um and then anything bigger than
[52:05] that is diagonalizable just comes from
[52:07] stacking these together. And when you
[52:09] stack them together, you basically get
[52:10] this like you just get the sum of parts
[52:12] kind of thing. Like and again, it's
[52:13] really important here. There's no
[52:14] interactions, which is why I feel
[52:16] justified in like studying these one and
[52:18] two dimensional subspaces kind of in
[52:20] isolation. And to ground it, can you
[52:22] connect this pile of like, hey, we're
[52:24] just doing a linear algebra lesson to
[52:26] like rope and linear positional
[52:28] encodings and things like that that feel
[52:30] a little bit more engineering oriented.
[52:32] >> Yeah. Yeah. Let's look at the the rope
[52:33] case because I think that's a that's a
[52:35] nice one. Um, and actually this is why I
[52:37] left this up because um, it will be
[52:40] useful to go back and like materialize
[52:42] our F and our G because they and in fact
[52:44] it is good to know that they are like
[52:46] the same ones that appear in rope.
[52:47] >> Yeah.
[52:47] >> Um, so in rope we are using this complex
[52:53] case and we're always setting this a to
[52:56] zero. There's no decay and no blow up in
[52:59] rope. You only get this rotational part
[53:01] with this pure imaginary
[53:04] case. Um, so carve out a little section
[53:07] of the board, I guess.
[53:08] >> I mean, I think I'm I'm safe to just
[53:10] remove definition of exponential here.
[53:13] >> Yeah. In the roof case, you get this
[53:14] like list of um frequencies. I guess
[53:18] we'll just call like theta 1, theta 2 up
[53:22] to theta, I guess n /2.
[53:24] >> Um, so we want to build a matrix out of
[53:28] this and we're going to use the the same
[53:30] formulations before. So I'm going to
[53:31] kind of like put it in the p perspective
[53:33] of what we've done here. So we'll set x
[53:36] equal to u and I'll do I guess I'll do
[53:39] the diagonal case I suppose. Well no
[53:43] actually it would it would be nice to do
[53:44] the the nice sort of
[53:46] >> like two dimensional subspaces.
[53:48] >> Yeah. Um yeah. So X is going to have a
[53:51] stack of these two dimensional blocks
[53:53] and the top block is going to look
[53:55] >> you could just maybe label it like let R
[53:57] of theta which we've already done theta
[54:00] be a shortand for that whole 2x two.
[54:03] >> Yeah that seems good actually. Yeah then
[54:05] then easier to not work with X because I
[54:07] keep forgetting the logarithm of a
[54:09] rotation matrix. Um [laughter] okay. So
[54:11] instead we'll just write a of t is going
[54:15] to be um
[54:17] r of theta 1 t r of theta 2 t and so on
[54:27] and r of theta n / 2 t.
[54:32] Um
[54:35] and right you can you can kind of see
[54:37] that this is like we've taken like n
[54:40] over two different copies of what
[54:42] happened here um and replaced like b
[54:44] became these various thetas and we've
[54:46] just like stacked them along the
[54:48] diagonal um and like okay well actually
[54:52] a a is nothing we care about like a is
[54:54] not quite how you operationalize this on
[54:56] like your keys and queries. So let's go
[54:58] back to this definition.
[54:59] >> Mhm. So um
[55:02] >> and actually just to be clear
[55:04] >> what freedom do you have or not have on
[55:06] like these values of theta like are you
[55:08] thinking
[55:08] >> um so rope has a prescription for these
[55:10] rope picks thetas to be a geometric
[55:13] sequence I believe um and you have some
[55:16] like there are okay I guess I've ignored
[55:18] all the practical considerations there
[55:19] are lots of like bad choices of theta
[55:21] here um rope picks the lowest period
[55:25] theta are frequencies so actually it is
[55:26] the largest theta to be on the order of
[55:28] one and Then the longest periods on rope
[55:32] get like exponentially longer than that.
[55:33] Like let's just say like 10,000 or
[55:35] something. Um and so the um smallest
[55:40] theta so all the be I believe they're
[55:42] all positive in rope. Um the the largest
[55:45] ones will be about on the order of one.
[55:46] The smallest will be on the order of
[55:48] like one over 10,000. And then all the
[55:49] ones in the middle are kind of
[55:50] exponentially spaced in some geometric
[55:52] sequence.
[55:52] >> Okay. And that's like a the spirit of
[55:55] the question is does this should should
[55:57] a viewer think of that as feeling like a
[55:58] choice or a design decision? Uh sorry
[56:01] like a design decision or like an
[56:02] inevitability what your it does happen
[56:05] to be.
[56:05] >> Yeah. I think it's like it's like a good
[56:09] choice for like the practical thing
[56:11] we're trying to do which is distinguish
[56:12] different time scales. Yeah. Um, and
[56:15] like you can kind of guess, I'm not
[56:17] going to try to make this rigorous, but
[56:19] you can try to guess like um if if like
[56:22] you have a given value of theta, um,
[56:25] theta is like good for length
[56:32] like one over theta or maybe you want to
[56:34] stick a 2 pi over theta in there or
[56:35] something. Like there's like theta is
[56:38] like an inverse time. It's a rate at
[56:39] which you're rotating stuff. You can
[56:41] it's a little bit intuitive. I think
[56:42] that like after you've gone through a
[56:45] bunch of cycles of theta um it's just
[56:48] like muddling everything together and so
[56:49] you kind of want good coverage of all
[56:51] your length scales which means like one
[56:54] over theta should cover a bunch of
[56:55] different
[56:56] >> so like one subspace is giving you like
[56:57] a very fast clock one subspace is giving
[56:59] you a slightly slower clock
[57:01] >> right yeah the faster and the faster
[57:02] your clock is the better you are at
[57:03] these fine grained tasks about like you
[57:06] know was that one word ago or two words
[57:07] ago the slower your clock is the better
[57:10] you are at tasks like Oh, was that like
[57:12] a thousand words ago or like 5,000 words
[57:14] ago?
[57:14] >> Okay.
[57:15] >> So, just wanted that said and then so
[57:17] you were about to put this in the
[57:18] language of the more like abstract
[57:20] framing that we have for the fully
[57:22] general case saying we don't care about
[57:24] A. When you operationalize this, it
[57:26] looks like your F and your G, which is
[57:29] like the way um of of baking position
[57:32] into your keys and queries.
[57:34] >> Right. Right. So now we can and actually
[57:35] it's not too hard to come up with a
[57:38] working F and G. Um for example we can
[57:41] take like
[57:43] f of t trans we can like set g of z
[57:45] equals identity for example. Um so let's
[57:48] say and let's say like f of t transpose
[57:52] is um
[57:55] >> actually we set this equal to a of t. I
[57:57] think that's going to work fine.
[57:59] actually can like I'm for for my taste
[58:02] I'm happy to sort of wave the hands at
[58:04] the fact that like in principle you can
[58:06] turn this into the relevant like F and G
[58:08] and like in principle the fact that uh
[58:11] one of the main things that was coming
[58:12] up once we say if it's a diagonalizable
[58:15] matrix like what happens rotation is
[58:16] part of that that lines up that lines up
[58:18] with rope I think maybe in the spirit of
[58:20] um time and uh intellectual energy of
[58:23] whoever is watching it I think one of
[58:24] the more interesting things to try to uh
[58:26] get at is like is there a positional
[58:29] encoding that people haven't
[58:30] experimented with that you can discover
[58:32] as a result of saying like once we have
[58:34] this framing you're choosing what x is
[58:37] um you know some of the known cases
[58:39] correspond to rope some of the known
[58:40] cases give you this exponential decay is
[58:42] there anything unknown that you get by
[58:44] like as as as a fruit of your labor for
[58:46] having become so abstract
[58:48] >> yeah okay so this is a good segue to the
[58:51] case we've been you know ignoring
[58:53] tactfully for now which is like what if
[58:56] it's not diagonalizable um and is This
[58:59] is like a very frequently ignored case
[59:01] because they're not very well behaved.
[59:03] Um, so like a lot of times like it's
[59:05] explicit that you want to restrict
[59:07] yourself to diagonalizable cases and
[59:08] like and in particular there aren't that
[59:10] many of them in some sense like for any
[59:12] non-dagonalizable matrix you can perturb
[59:14] it a tiny bit and get a diagonalizable
[59:16] matrix instead. Um, nevertheless these
[59:19] are actually pretty important to cover.
[59:21] So let's yeah switch to that case.
[59:26] >> Okay.
[59:32] Um the non-dagonal nondagonalizable case
[59:36] gives you what are known as Jordan
[59:37] blocks. And um they're really hard to
[59:40] think about in generality. So I'm just
[59:42] going to look at the simplest
[59:43] non-trivial Jordan block, which is going
[59:46] to look like this is going to be notably
[59:48] not diagonal. It's going to look
[59:49] something like this. Uh 0 1 0 0. um
[59:55] >> the slightly more general version would
[59:58] have these these zeros on the diagonal
[60:00] would be replaced with some other real
[60:02] value on the diagonal instead. So like
[60:04] some like
[60:05] >> that's what I initially thought you were
[60:06] going to
[60:07] >> um yeah I want to keep this as simple as
[60:09] possible just so we can get some some
[60:10] intuition before we complicate things.
[60:13] Um okay so this this is saying we have
[60:17] this happens when you have
[60:20] values in algebraic sense but they're
[60:23] somehow like stuck together. um in
[60:26] particular like one of these is like a
[60:28] good proper igen value that kind of that
[60:30] really does stand alone. It has its own
[60:31] igen vector, has it own subspace,
[60:33] doesn't affect anything else. But um
[60:35] another one of these is going to be like
[60:39] a kind of u bad in value like it won't
[60:43] actually stay in its own subspace. It'll
[60:45] like leak into the first subspace when
[60:47] you try to use it. Um and we can make
[60:49] this very specific. We'll say like so x
[60:51] um like so algebraically this has a
[60:54] double value at zero but okay well when
[60:57] you do x 1 0 you in fact get zero as you
[61:02] might expect. So the x-axis,
[61:04] >> yes, x-axis indeed gets flattened as we
[61:06] hoped, but then you compute x of 01.
[61:12] Um, and this does not do what you might
[61:14] hope. Like this instead gives you a
[61:17] what's called it's kind of like coupled
[61:19] to the other space. So you get uh one
[61:22] zero. So it did kill the component in
[61:24] the y direction. Like it took its y
[61:26] vector and said the y component is gone.
[61:29] But then it like this x component popped
[61:30] up. And you can actually notably if you
[61:33] apply a second x to this so you have x
[61:37] squar 01 uh it will then kill the
[61:41] remaining x component and you actually
[61:43] do get zero which is very intuitive like
[61:45] the first column is telling you x-axis
[61:47] gets squished. Second column is telling
[61:48] you y-axis goes onto x. So you've got
[61:51] this like two-step motion of like rotate
[61:52] yourself and then and then die. And so x
[61:55] squ is degenerate. Um
[61:57] >> um yeah yeah yeah and actually yeah in
[61:59] fact x squ is just equal to zero um
[62:01] which is going to be very um because
[62:03] important because I guess oh yeah the
[62:05] power series is now gone um so but yeah
[62:08] it's really important to note that so x
[62:10] squ equals z and so um what is e to the
[62:14] tx? Well, you get your first identity
[62:18] term as you as you hope. You then get
[62:20] your linear term. Um, and then that's
[62:23] it. There are [laughter] no further
[62:25] terms because there's this like x2 over
[62:29] 2 plus whatever. But like x squ is zero.
[62:32] So all higher powers x are also zero. So
[62:34] this all just goes away.
[62:35] >> Just right. Yes. The t is important.
[62:38] Yeah.
[62:39] >> Yeah. Also extra t square as well. Um,
[62:43] right. Yeah. So you just get I + XT.
[62:47] Okay. So something a little bit
[62:48] unexpected has happened which is that we
[62:50] took the exponent of something and we
[62:52] got a polomial out in T, right? Um this
[62:55] has not happened before. Before we got
[62:57] triometric functions, we got exponents
[62:59] and those were kind of the expected
[63:00] things you get when you take
[63:01] exponentials of stuff.
[63:03] >> Well, what does this even mean? Um, if
[63:04] you think of its role as the like
[63:06] positional encoding influencer A, like
[63:10] if if we chose this as our X and we're
[63:12] like great, now we have an A that does
[63:13] this. Like I knew how to think about
[63:15] rotation. I'm like, okay, it's sort of a
[63:16] 4A decomposition. Knew how to think
[63:18] about decay. It's like you want time to
[63:20] matter less the bigger it is. I have no
[63:23] intuition on what this means.
[63:25] >> Yeah. So matrices like this um one place
[63:27] they pop up is in like linear dynamical
[63:31] systems where you're like some matrix
[63:33] governs the time evolution of a thing.
[63:35] And in this case I'm actually going to
[63:36] provide a fairly simple thing that
[63:38] governs the time evolution of which is
[63:40] we just got some yeah we'll just have a
[63:41] a number line. Yeah got some x knot and
[63:44] then this puck starts here and now it's
[63:47] going off with some velocity V.
[63:49] >> Yeah.
[63:50] >> Okay. So let's just say okay no friction
[63:54] velocity is unchanging no forces. How do
[63:56] we model this system over time? Well, we
[63:59] only have like I'm going to just assert
[64:02] that we have these two like state
[64:04] variables here. You've got this V and
[64:06] you've got this X knot. Um so I'm just
[64:09] going to say that we're going to
[64:09] summarize the state in that way. Um the
[64:14] state is some position and some
[64:15] velocity. Okay. Uh, and I'm not
[64:18] bothering to pick a different variable
[64:19] here because the velocity is constant.
[64:20] So, you know.
[64:21] >> Okay.
[64:22] >> Um, and actually we can be more specific
[64:24] because we know exactly where this is
[64:25] going to end up after some amount of
[64:27] time. T is going to end up at like X
[64:30] plus um T V X plus TV V. Um,
[64:37] >> okay. And that so that looks a lot like
[64:40] um the dynamics of applying this. Uh,
[64:43] >> yeah. Well, so what is this matrix?
[64:45] Let's actually just write this matrix
[64:46] explicitly. So e to the tx is i + x t is
[64:53] um 1 t 01.
[64:58] >> Mhm.
[64:58] >> Um and when you apply that
[65:02] >> if you apply that to xv
[65:03] >> to xv
[65:04] >> or actually when you apply that
[65:05] specifically to x knot v. So
[65:08] >> yeah. So e to the tx
[65:12] x knot v is a yeah that should be
[65:15] exactly equal to this guy.
[65:17] >> So x knot + tv v. Um so you can kind of
[65:24] think of this matrix as generating the
[65:26] or like actually this matrix really as
[65:28] like generating the dynamics of like
[65:30] something just flying off in the
[65:31] distance.
[65:32] >> Okay.
[65:32] >> Uh with some like constant speed. Um,
[65:35] and that is actually I think a
[65:36] reasonable intuition for what's
[65:38] happening here. It's like it is giving
[65:41] you this like polinomial behavior. If
[65:43] you if we added we can actually make the
[65:44] Jordan block bigger if we wanted. Uh,
[65:46] I'm not going to explicitly work the
[65:48] dynamics, but like the the bigger
[65:50] version would look something like this
[65:53] um 0 0 1 0 0. Um, and if we did that
[65:59] instead, then x cubed would be zero, x
[66:02] squ wouldn't be. So we'd end up with
[66:03] like quadratic behavior instead of
[66:05] linear behavior.
[66:06] >> It's something like an acceleration term
[66:07] in there. And so okay, so this is the
[66:09] point of like from a physicist
[66:11] intuition, what is the meaning of a
[66:13] non-diagonalizable matrix when you
[66:14] exponentiate it? Um what is the uh what
[66:18] does the hockey puck positional encoding
[66:20] look like? Right? What what does that
[66:22] even mean to think of a term like this?
[66:25] um through a then through its like
[66:28] influence on your F and G which in turn
[66:30] influence your positional encodings.
[66:32] What does this set of dynamics imply for
[66:34] how keys and queries at a certain
[66:36] distance apart influence each other?
[66:39] Yeah. So in full generality it means
[66:40] like there is some linearly growing
[66:45] association between like like there's
[66:47] linearly growing influence. It's not
[66:49] quite as badly behaved as this
[66:50] exponentially growing influence that we
[66:52] would get from like a positive real
[66:53] value, but it's still like not that well
[66:56] behaved in in general. But then
[66:58] actually, so initially I was like, okay,
[66:59] I don't know what to do with these. Like
[67:00] these seem pretty useless. I think it's
[67:02] maybe time to give up. Um but someone
[67:04] actually pointed out um that like
[67:08] nothing I had done earlier covered
[67:10] something called alibi and alibi and is
[67:13] this case where it's alioding
[67:16] where it looks more like one thing I I
[67:19] alluded to way earlier where you just
[67:21] modify the scores. You don't do anything
[67:22] to the vectors themselves. You just take
[67:24] the dot product and you subtract some
[67:26] term from it. And actually the term you
[67:28] subtract is specifically um okay now I
[67:31] think it's time to get rid of this one.
[67:33] Um so alibi
[67:38] um you say the
[67:42] let's I'll just call it like the logic
[67:44] um ts is equal to um q tanspose
[67:53] k s you subtract something. So we'll say
[67:58] it's like some some penalty
[68:01] um times
[68:04] uh t minus s.
[68:06] >> So initially this seems like a very
[68:08] different framing from how we even came
[68:09] at the whole thing where you were saying
[68:11] all the influence of time is happening
[68:13] kind of between these two vectors.
[68:15] >> Right. Right. So this doesn't do
[68:17] anything to the vectors. um it just
[68:19] sticks this like as a completely
[68:21] separate penalty term and it says like
[68:23] like reduce the score when they're
[68:25] further apart. And you can you can
[68:27] pretty clearly see this satisfies this
[68:29] like translation variance like it very
[68:30] explicitly only depends on this
[68:32] difference t minus s. Um,
[68:36] okay. Well, there's already kind of a
[68:38] tenuous connection you can draw where
[68:40] it's like, hm, okay, we've got some
[68:41] linear term happening in this in time
[68:44] and we know how to make one linear term
[68:46] in time, so maybe we can do something
[68:48] there. Um, so here's the here's the
[68:51] connection you can make. Um, we're going
[68:54] to like augment our inputs Q and K with
[68:59] an additional component on each side
[69:01] with a fixed value. Um, and the Q value
[69:05] will just be I guess I think we'll we'll
[69:07] just call them like
[69:09] uh I think we need two two values. So
[69:11] let me maybe do this like more space set
[69:15] of premium. I think we're maybe done
[69:16] with this part.
[69:17] >> Yeah, that's it.
[69:18] >> Probably. Look at that.
[69:19] >> Okay,
[69:21] >> we're explicitly not diagonalizable.
[69:23] >> Yeah. Yeah.
[69:23] >> So kill kill all diagonal matrices.
[69:25] >> Yeah, the old model of the world is is
[69:27] [laughter] gone.
[69:30] Okay, so we're going to stick a little
[69:32] component on. And so we had like we're
[69:33] just like just say Q hat is going to be
[69:36] like whatever our old Q was and then
[69:39] we'll tack on these two new components
[69:41] and on Q we'll call them zero and one
[69:43] and
[69:45] sorry I'm going have to reverse the
[69:47] order of those I think just pattern
[69:48] matching we're going to get to later
[69:50] actually be one and zero and then on K
[69:54] we're going to get our old K and then
[69:58] negative one and zero.
[70:00] >> Okay. Um,
[70:01] >> so these are this queue doesn't have any
[70:04] time influence possible.
[70:06] >> Yeah, I'm almost certain I've already
[70:07] messed this up and I have to like make
[70:08] some modifications to make this fit. Um,
[70:11] but we'll get to that when I'll go back
[70:14] and fix this when we get there. Um,
[70:16] okay. Yeah. Actually, so I guess the
[70:18] idea that we want is like we want to
[70:20] recreate this negative term using like
[70:24] like something
[70:26] times something transpose I guess times
[70:30] 1 t. Yeah, maybe this is a more
[70:32] productive direction to come at this
[70:33] from um
[70:37] like we know we know we're going to end
[70:39] up with something that looks like this
[70:41] and we would like this to be equal to um
[70:46] p uh negative pt.
[70:51] Uh I'm you don't need the t minus s
[70:52] because like you just set s to zero and
[70:54] that's kind of what this is going to
[70:56] assume. So we can actually this is not
[70:59] too hard to solve once you know what
[71:00] you're looking for like once you know
[71:02] you want this kind of term. Um well
[71:07] we really hope these one one things
[71:10] don't contribute which actually so
[71:12] probably we need on this side
[71:14] >> um we like to have these no like
[71:17] matching components but we need this T
[71:20] to turn into a negative PT. So what do
[71:22] we do? Well, this T appears in the
[71:26] product of the second component on the
[71:28] right and the first component on the
[71:30] left. So,
[71:31] >> are you going to split it up as like a
[71:32] square root of P or
[71:34] >> you could not going to do anything so
[71:35] elegant. I was just going to stick a
[71:36] negative P in there and a one in here.
[71:41] >> Um, and then everything else, let's just
[71:43] fill in with zeros and let's see where
[71:46] that leaves us. Okay, so this is
[71:47] completely wrong. I'm going to pretend I
[71:49] didn't do that.
[71:50] >> No, no, no. I mean this is the process
[71:51] of it's [laughter] honest process of
[71:53] just like doing like I have a feeling
[71:55] there's this connection between like
[71:56] something that comes up in machine
[71:57] [laughter] learning land and then my
[71:59] like abstract beautiful frame egg
[72:01] framework of like you know the space of
[72:03] all possible positional encodings and
[72:05] like you know you have a guess you
[72:07] modify it like
[72:09] >> um okay so I think if we if we actually
[72:12] do this out we can confirm that this
[72:13] gives you a right answer um like this
[72:16] one gets you a product of two things one
[72:18] which is zero so it doesn't contribute
[72:20] This one also gets you a product of two
[72:22] things. One which is zero also doesn't
[72:23] contribute. But this T hits that
[72:25] negative P and this one and you get the
[72:28] thing you wanted which is this negative
[72:29] PT. Um and so that tells us actually how
[72:31] we should modify these guys up here
[72:33] because this negative P 0 should show up
[72:35] in our Q. I see. Okay.
[72:37] >> So we'll just pencil that in. Um and
[72:40] then this other uh 01 needs to show up
[72:43] in our K. So we can pencil that in as
[72:45] well. Um okay. And we've kind of in some
[72:49] sense we've like violated the initial
[72:50] assumptions of what I wanted to do which
[72:52] was like not do any time invariant stuff
[72:54] to our inputs. But like it turns out in
[72:57] this case to get like the good outcome
[72:59] where we don't get linearly growing
[73:01] nonsense um and like instead of kind of
[73:03] focus it on this particular form of term
[73:06] you do have to be very particular about
[73:07] like how you modify these um input keys
[73:11] and queries. Um but yeah, so this is
[73:14] actually a case where like if you you
[73:16] know fix a couple components of your
[73:18] inputs and then you staple on this like
[73:21] uh what's called like a defective matrix
[73:23] into your generator for your positional
[73:25] encoding, you can exactly recover um
[73:28] alibi which is really satisfying. Yeah,
[73:30] because it initially seems to violate uh
[73:32] the assumptions but then like it really
[73:33] does fit in the so you've hit all the
[73:35] bases. You've hit your real
[73:37] exponentials, your complex exponentials
[73:38] and your non-dagonalizables
[73:40] that turn into polinomials. Yeah,
[73:42] >> I'm sure there's a million more things
[73:44] to say on this, but kind of partly in
[73:46] the spirit of time, but also partly in
[73:47] the spirit of curiosity, kind of like a
[73:49] cultural question around this, which is
[73:51] I know you'll sometimes give lectures to
[73:53] like fellow people. Is this typical of
[73:56] of that? Like the kind of thing where
[73:57] you'd be like, "Hey, here's just some
[73:58] like fun math that is maybe related to
[74:00] the machine learning we're doing, but
[74:01] also just, hey, who doesn't love
[74:03] thinking about, you know, applying
[74:05] linear algebra and group theory to these
[74:07] questions?" like how representative of
[74:09] this is the kind of thing that you might
[74:11] be lecturing to some of your co-workers
[74:12] on.
[74:13] >> Yeah, this was honestly one of the more
[74:16] relevant things that I'm [laughter]
[74:17] giving a talk on. Um I mean like I mean
[74:21] this I guess there's some line between
[74:23] like things that I would bring up like
[74:25] while we're doing work and things that I
[74:27] would bring up like after everyone is
[74:28] like turned their chairs around on a
[74:30] Friday afternoon and we're like, "Okay,
[74:32] we've probably gotten enough enough work
[74:33] done for the week and we're just kind of
[74:34] like
[74:35] >> talking about more miscellaneous stuff."
[74:37] Um, I guess like this was this was
[74:39] relevant enough that I like was like,
[74:41] "Oh, this is like a neat result that I
[74:43] kind of want to share with like the
[74:44] broader like ML research community at
[74:46] Jane Street." So, I first wrote like an
[74:47] kind of internal blog post about it and
[74:49] then we went like, "Okay, actually this
[74:51] is pretty cool and would make for a good
[74:54] public blog post as well." And that's
[74:55] that's when I decided to kind of like,
[74:57] you know, clean it up. We did some some
[74:58] copy editing and like make a nicer
[75:00] public facing version of it.
[75:02] >> Nice. And did you I mean as you as you
[75:04] stepped back from it, has it like
[75:05] changed the way that you think about
[75:07] positional encodings at all or is it
[75:09] more just that it's like you still think
[75:10] about them in the same way, but there's
[75:12] a certain comfort in knowing that the
[75:14] space truly is like pretty sufficiently
[75:16] explored?
[75:18] >> Yeah, at the outset I really wasn't sure
[75:20] what I'd find here, but I guess like
[75:22] once it was all said and done, I did
[75:24] feel kind of more comfortable knowing
[75:26] like there wasn't some like big gap in
[75:29] the in the literature or something. It
[75:30] did feel like the sensible options were
[75:33] pretty well studied. And then there's
[75:35] like this strange corner like like
[75:37] notably this example only kind of like
[75:39] brushes the surface of that corner
[75:41] because like we didn't even get to like
[75:43] non-zero values or larger Jordan blocks
[75:45] or whatever. But like I think like now
[75:47] that I understand the dynamics of those
[75:49] somewhat better, I do feel relatively
[75:52] confident that like probably not super
[75:54] useful. I think like the
[75:55] >> like if you had some quadratic terms
[75:56] that came about from a bigger block,
[75:58] it's not going to be something that like
[75:59] unlocks something in
[76:00] >> practice. I don't think so.
[76:01] >> Okay. Not going to not going to be
[76:03] making any promises. I wasn't like super
[76:05] thorough trying to figure out the exact
[76:06] implications of this, but it didn't seem
[76:09] like an obvious, you know, mistake to me
[76:11] that no one's like really studying
[76:12] those.
[76:13] >> Okay. I found that very satisfying. I
[76:15] think that's kind of a fun connection of
[76:16] a lot of different things. I think
[76:17] that's a great point to call out. Also,
[76:19] thanks for doing this. I This was very
[76:20] fun. Appreciate it.