Full Transformer Architecture
64D Bilingual Shakespeare + Hafez

LLM Interactive Architecture

Build a transformer from scratch - an interactive, end-to-end guide to understanding how Large Language Models work from raw text to generated output.

Embedding Dim
d = 64
Vector length per word
Attention Heads
h = 4
4 parallel heads
Transformer Layers
L = 4
4 stacked blocks
Vocabulary
V = 256
256 bilingual tokens

What is a Large Language Model? 🤖

A Large Language Model (LLM) like ChatGPT is, at its core, a next-token prediction machine. Given a sequence of text, it predicts the most probable next word or subword by learning statistical patterns from massive datasets.

Under the hood, an LLM is built from a transformer architecture (Vaswani et al., 2017). The transformer's key innovation is self-attention: a mechanism that lets every word in a sequence attend to every other word to understand context.

In this interactive laboratory, you build every component of a working LLM from scratch. The model is lightweight (~550K parameters vs. GPT-3's 175B), but the underlying architecture is identical.

How This Live Laboratory Works 🧭

This is not a static tutorial - it is a live laboratory. A real PyTorch model runs on the backend. When you type text, it flows through actual tensor pipelines. When you train, real gradients update weights.

Recommended Learning Flow 🚀:

Work through Steps 1–10 in order. Each step explains the math, provides interactive visualizers, and offers reference PyTorch code. Explore Step 11 (Modern Architectures) to see how frontier models like LLaMA 3 and DeepSeek-V3 evolved.

Live Model Architecture 🏗️

PyTorch GPT
Embedding Dimension (d_model)64
Attention Heads (n_heads)4 (16D per head)
Transformer Layers (n_layers)4 Blocks
Context Window Length64 Tokens
Vocabulary Size (V)256 (Tied Weights)
Dropout Rate0.1
Total Parameters~550,000

Training & Dataset Status 📊

AdamW (3e-4)
Dataset CorpusShakespeare + Hafez (Bilingual)
Total Training Steps2,000 Steps
Batch Size32
Initial Lossln(256) ≈ 5.545
Converged Loss~1.82
Learned BPE Merges416 Merges
Token Compression Ratio1.87×

Architecture Roadmap

Step through each mathematical transformation from raw tokens to probabilities.

1
Subword BPE
~8 min

Tokenization (BPE)

Beginner

Transform raw text into integer token IDs using Byte Pair Encoding (BPE).

Explore module
2
64D Geometry
~8 min

Token Embeddings

Beginner

Convert discrete token IDs into 64-dimensional continuous vectors capturing semantic meaning.

Explore module
3
Sinusoidal & RoPE
~7 min

Positional Encoding

Beginner

Inject geometric order into permutation-invariant self-attention representations.

Explore module
4
Causal Masking
~12 min

Self-Attention

Intermediate

Allow each token to dynamically attend to every other preceding token via scaled dot-product.

Explore module
5
4 Heads × 16D
~10 min

Multi-Head Attention

Intermediate

Split 64D embeddings across 4 specialized 16D attention heads for diverse feature subspace learning.

Explore module
6
Residuals & MLP
~10 min

Transformer Block

Intermediate

Combine Pre-LayerNorm, Multi-Head Attention, residual connections, and FeedForward MLP.

Explore module
7
Logits & Projection
~8 min

Full GPT Model

Intermediate

Final LayerNorm, tied de-embedding projection W_u = W_e, and vocabulary logits.

Explore module
8
Cross-Entropy
~15 min

Training Loop

Advanced

Cross-entropy loss calculation, perplexity metrics, and AdamW gradient descent convergence.

Explore module
9
Weight Gradients
~12 min

Backpropagation

Advanced

Mathematical derivation of tied-weight gradients, unobserved token dynamics, and loss backpropagation.

Explore module
10
Autoregressive Sampling
~10 min

Live Generation

Advanced

Autoregressive next-token sampling loop with temperature scaling and nucleus sampling.

Explore module
11
RoPE / SwiGLU / MoE
~15 min

Modern Architectures

Advanced

Frontier upgrades: RoPE, RMSNorm, SwiGLU, GQA, MLA, and Mixture of Experts (MoE).

Explore module