TX

Transformer & Self-Attention Workbench

Interactive mechanism probe: Embeddings • QKV Projections • Attention Matrix • Softmax • Autoregressive Next Token
Ready: Multi-Head QKV Active
Input Sequence (Click any token to set as Active Query $q_i$) 9 Tokens
Step 1
Scaled Dot-Product Matrix
Step 2
Q × K × V Decomposition
Step 3
MLP & Residual Stream
Step 4
Next-Token Logits
Attention Heatmap: $\text{Softmax}\left(\frac{Q K^T}{\sqrt{d_k}}\right)$ Hover cell to inspect
Active Query Spotlight • Token "it"

Evaluating how much Query token $i$ attends to each Key token $j$ across the sequence.

$\text{Score}(i, j) = \frac{q_i \cdot k_j}{\sqrt{d_k}}$
$\alpha_{i,j} = \frac{\exp(\text{Score}_{i,j} / \tau)}{\sum_k \exp(\text{Score}_{i,k} / \tau)}$
Top Attended Keys from Query:
Context Value Aggregation:
$z_i = \sum_j \alpha_{i,j} \cdot v_j \longrightarrow \text{Weighted combination of antecedent embeddings}$
Why Transformers Revolutionized AI: Core Invariants

Constant Path Length $\mathcal{O}(1)$

Unlike Recurrent Neural Networks (RNNs) that process word-by-word with vanishing gradients across long distances, self-attention connects any two tokens in a single operation regardless of distance.

Massively Parallel Matrix Math

All queries, keys, and values are computed simultaneously via batched matrix multiplication ($Q K^T$), fully saturating GPU tensor cores during training.

Multi-Head Specialization

Multiple attention heads learn complementary linguistic roles: syntactic subject-verb dependencies, coreference disambiguation, positional offsets, and semantic broad context in parallel.

Enjoy this tool? Build your own with Super