mej7.comHow AI Works
A VISUAL AI LABORATORY

What actually happens inside AI?

From your words to tokens, vectors, matrices, attention, probabilities and the final answer — explore what happens inside a modern language model.

// Don't just use AI. Understand what happens inside it.
FOR EVERYONE — EVEN A 4-YEAR-OLD

How AI works, in the simplest way possible

Forget the hard words for a second. AI does three simple things, over and over, super fast: it Looks, it Guesses, and it Says. Watch the boxes spin.

TOKENIZATION

Your words become tokens

Neural networks don't process words as human concepts. Text is first converted into <b>tokens</b> — pieces of text represented numerically.

Text↓Tokens↓Token IDs

Token IDs depend entirely on a model's specific tokenizer/vocabulary — the IDs shown here are illustrative, not universal.

SUBWORD TOKENIZATION

Long or rare words are often split into smaller pieces. For example, "unbelievable" might become:

unbelievable

This is just an illustrative example — real splitting depends on the specific tokenizer in use.

In more detail

A language model cannot read letters or words directly. It works with numbers, so the first step is to cut the text into pieces called tokens and to replace each piece with an integer ID taken from a fixed vocabulary.

A token may be a whole word, a part of a word, a single character, a punctuation mark, or a word together with its leading space. Most modern models use subword tokenization, for example byte-pair encoding (BPE). The vocabulary is built by starting from small units and repeatedly merging the pairs that occur most often in a large sample of text. Frequent words usually become a single token; rare or long words are split into several pieces. This keeps the vocabulary at a manageable size (typically tens of thousands to a few hundred thousand entries) while still allowing any text to be represented, often by falling back to individual bytes.

Why this matters in practice:

  • The context window and, for many services, the price are counted in tokens, not words. In English, one token is on average a bit less than one word (a common rule of thumb is about three quarters of a word), but the ratio varies. Languages that are less represented in a tokenizer's training text, such as Albanian, often need more tokens per word.
  • Numbers, code and unusual spellings can split in unexpected ways. This is one reason why models can struggle with tasks such as counting the letters in a word.
  • Token IDs belong to one tokenizer. The same text receives different IDs in different models, and an ID has no meaning on its own. The next step turns it into a vector.

Simplification: the splits and IDs in the visualization are illustrative. Real tokenizers use their own vocabularies and rules.

EMBEDDINGS

Tokens become vectors

Each token ID is looked up in a table and turned into a <b>vector</b> — a list of numbers. Words with related meanings tend to end up with nearby vectors.

Token ID→Embedding lookup→Vector
ILLUSTRATIVE VALUES
"king"[0.21, -0.42, 0.87, 0.13, ...]

The embedding space below is reduced to 2 dimensions for human eyes — real models use hundreds or thousands of dimensions.

Simplified visualization for teaching purposes — positions are illustrative, not real coordinates from a production model.

VECTOR ARITHMETIC

This is the classic illustration of what embeddings capture: relationships between words behave a bit like arrows you can add and subtract.

king−man+woman≈queen
king man woman result ≈ queen

Illustrative geometry in a simplified 2D space — real embedding arithmetic happens across hundreds of dimensions and doesn't always land this cleanly.

In more detail

After tokenization, each token ID is used to look up one row in a large table called the embedding matrix. That row is a vector, a list of numbers (768 numbers in GPT-2 small, thousands in larger models), and it is the model's starting representation of that token. The values in the table are parameters learned during training, not designed by hand.

Training pushes tokens that are used in similar ways toward similar vectors, so directions in this space often reflect aspects of meaning or grammar. This is why "cat" and "dog" tend to end up closer to each other than to "carburetor". The classic illustration is the analogy king − man + woman ≈ queen, reported for word embeddings such as word2vec (Mikolov et al., 2013). Treat it as an illustration, not a law: in those experiments the words from the question are normally excluded from the candidate answers, results vary, and the input embeddings of modern language models do not behave so neatly.

Two important points:

  1. 1. The embedding of a token is the same wherever it appears. "Bank" starts from the same vector in "river bank" and in "bank account". It is the later layers, above all attention, that make the representation depend on context.
  2. 2. Real embedding spaces have hundreds to thousands of dimensions. The 2D picture is a projection made for human eyes, and it loses information.

Simplification: positions in the visualization are illustrative, not coordinates from a real model.

WEIGHTS

The model is full of numbers called weights

Every connection between neurons has a weight. Change the weights below and watch the output change live. Click "Run forward pass" to see values flow through the network.

CONTRIBUTION
Input = 0.80×Weight = 0.50=0.40

This is the basic formula: <span class="mono">input × weight = contribution</span>. Contributions from many inputs are summed to form a neuron's activation.

In more detail

A weight is a number that controls how strongly one value influences another. In a single artificial neuron, each input is multiplied by its weight, the results are added together, a bias (another learned number) is added, and the total is passed through an activation function:

output = f(w₁x₁ + w₂x₂ + … + b)

A large positive weight means the input pushes the result up, a negative weight pushes it down, and a weight near zero means the input barely matters. Looking at one weight tells you almost nothing. The behavior of a network emerges from millions or billions of weights working together.

Weights are the main kind of parameter that a model learns. Training adjusts them in many small steps so that the model's predictions improve. After training, the weights are fixed: they do not change while you chat with the model.

Weights are not facts stored as sentences. Knowledge in a network is spread across many weights, and there is no simple table where a fact can be looked up.

Simplification: the visualization shows one multiplication (input × weight). A full neuron also sums many such products, adds a bias and applies an activation function.

MATRICES

Neural networks multiply numbers

Matrix multiplication lets a network transform large amounts of information in a single mathematical step. Click a result cell to see exactly which row and column combined to produce it.

MATRIX A
×
MATRIX B
=
RESULT C

Amber = the row from A being used. Cyan = the column from B being used. Each result cell is the dot product of that row and that column.

In more detail

A layer of a neural network has many neurons, and each one needs a sum of products. Matrix multiplication computes all of them at once.

If A has m rows and n columns, and B has n rows and p columns, then C = AB has m rows and p columns. Each entry C[i][j] is the dot product of row i of A with column j of B: multiply the matching entries and add the results. The "inner" sizes (n) must match.

In a neural layer, the input vector x is multiplied by a weight matrix W, a bias vector is added, and the result goes through an activation function: y = f(xW + b).

Two reasons this matters:

  • Speed. Graphics processors (GPUs) are built to perform huge numbers of these multiplications in parallel. Most of the computation in a transformer is matrix multiplication.
  • Meaning of the dot product. A dot product is larger when two vectors point in a similar direction. This idea is at the heart of attention (sections 09 and 10).

Note that the order matters: in general AB is not the same as BA.

Simplification: the matrices here are tiny. In real models they have thousands of rows and columns.

· LINEAR ALGEBRA

What a matrix really does: it bends space

Every 2×2 matrix is a rule for transforming every point in a plane — stretching, rotating, shearing, or flipping it. Drag the sliders, or try a preset, and watch the whole grid warp in real time.

Determinant (area scale factor)1.00

Positive determinant: space keeps its orientation — nothing gets flipped.

î (where "right" ends up) ĵ (where "up" ends up)

In more detail

A matrix can be seen as a function that moves every point of space. In two dimensions, a 2×2 matrix tells you where the two basic arrows go: its first column is where the arrow (1, 0) lands, and its second column is where (0, 1) lands. Every other point follows from these two.

Transformations of this kind include rotation, scaling, shearing, reflection and projection. They are called linear because they keep the origin fixed, keep straight lines straight, and keep grid lines parallel and evenly spaced. (When a bias is added, the operation is called affine.)

The determinant tells you by what factor areas change. A negative determinant means the orientation is flipped. A determinant of zero means the plane has been squashed onto a line or a point; information has been lost and the transformation cannot be undone.

Why this matters: the weight matrix of a layer applies a linear transformation to its input vector, in hundreds or thousands of dimensions rather than two. Layer after layer, these transformations reshape the space in which the model represents information. But several linear transformations in a row are equivalent to a single one, which is why networks also need the non-linear step explained next.

ACTIVATION

Activation functions

After each multiplication, the result passes through an activation function, which lets the network learn non-linear patterns.

f(x)0.00

In more detail

Without activation functions, a stack of layers would collapse into one single linear transformation, no matter how many layers it had. An activation function applies a simple non-linear function to each number, and this is what lets networks learn curved, complex relationships.

  • ReLU: f(x) = max(0, x). Negative values become zero; positive values pass unchanged. Simple and fast.
  • Sigmoid: f(x) = 1 / (1 + e^(−x)). Squashes any number into the range 0 to 1.
  • Tanh: squashes numbers into the range −1 to 1.

Sigmoid and tanh become very flat for large positive or negative inputs, which can slow learning. ReLU avoids this for positive inputs, but a neuron can get stuck outputting zero for everything.

Large transformer models mostly use smoother variants. GPT-2 and BERT use GELU, and many recent models use gated variants such as SwiGLU. The principle is the same: a non-linear step after each linear one.

· NEURAL NETWORK LAB

See the network compute

Full interactive feed-forward laboratory — forward pass, matrix multiply, training on real toy data, and neuron autopsy. All numbers come from the actual simulation.

In more detail

A neural network is a stack of layers. Each layer takes a vector of numbers, multiplies it by a matrix of weights, adds biases and applies an activation function. The output becomes the input of the next layer. "Feed-forward" means that information flows in one direction, from input to output. This process is called the forward pass.

Training adjusts the weights so that the outputs match the desired targets on many examples (sections 17 and 18). A network with at least one hidden layer and a non-linear activation can approximate any continuous function on a bounded region to any desired accuracy, given enough neurons (the universal approximation theorem). That theorem says it is possible, not that it is easy to find the right weights.

Transformers contain feed-forward networks too: the MLP in every block (section 13). The lab below uses a tiny network on a toy problem. Real language models use the same building blocks at a vastly larger scale.

ATTENTION

What should the model focus on?

Pick a word and see how much "attention" it pays to every other word in the sentence — both as connecting lines and as a heatmap.

Attention doesn't simply mean "the AI understands what's important" — it's a mathematical mechanism that lets every token incorporate information from other tokens, with varying strengths.

In more detail

Attention lets each token gather information from other tokens. For every position, the model computes a set of weights over the positions it is allowed to look at (the weights are non-negative and add up to 1) and builds a new representation as a weighted mix of the information found there.

Consider "The animal didn't cross the street because it was too tired." To represent "it" usefully, the model needs information from "animal". Attention is the learned mechanism that makes this possible. In decoder-only models such as GPT, each token can look only at itself and the tokens before it (the causal mask), because the model generates text from left to right.

One caution: attention weights show where a head reads from, but they are not a complete explanation of why the model produced an output. Research has shown that a high attention weight does not always mean the token was decisive (Jain & Wallace, 2019; Wiegreffe & Pinter, 2019). Also, a real model has many heads in many layers; one heatmap shows just one slice.

Simplification: the sentence and weights in the visualization are illustrative.

Q / K / V

Query, Key, Value

Every token produces three vectors with different roles in the attention mechanism. The angle between a Query and a Key vector determines how strongly they match.

Q
Query
What this token is looking for
K
Key
What each token offers for matching
V
Value
Information passed forward
Similarity (dot product)—
Q × Kᵀ↓attention scores↓softmax↓weighted combination of V

In more detail

Each token's vector x is multiplied by three different learned matrices to produce three vectors:

  • Query q = x·W_Q: what this position is looking for.
  • Key k = x·W_K: what this position offers for matching.
  • Value v = x·W_V: the information this position passes on if it is selected.

The match between position i and position j is the dot product q_i · k_j. A higher score means more attention. The dot product equals |q|·|k|·cos θ, so it depends on both the angle and the lengths of the vectors. In the slider above the lengths are kept fixed, which is why only the angle matters there. In real models the lengths matter too.

The scores are divided by √d_k (section 10), turned into weights with softmax, and used to mix the value vectors: the output at position i is Σ_j weight(i, j) · v_j.

Why three separate matrices? Because what a token is looking for does not have to be the same as what it offers or what it passes on. This gives the model flexibility.

"Query", "key" and "value" are helpful metaphors. In reality they are just learned linear projections, and what they encode must be found out by analysing the trained model.

TRANSFORMERS — Q·K·V IN DETAIL

Inside the Transformer: how Q, K and V actually multiply

A full, real walk-through of scaled dot-product attention: computing Q, K and V, transposing K, multiplying, scaling, applying the triangular causal mask, and running softmax — with real numbers, for a tiny 4-token example.

X = 4 tokens × 2 dims Wq, Wk, Wv = 2 × 2
STEP1 / 12

Numbers here are a small, made-up example chosen to be easy to follow by hand — real models use hundreds of dimensions and different values, but the operations (multiply, transpose, scale, mask, softmax) are exactly these.

This triangular mask is used in autoregressive (decoder-style) models like GPT, which generate text left-to-right. Encoder-style models (like BERT) typically skip this mask and let every token see the whole sequence.

In more detail

The whole operation is one formula:

Attention(Q, K, V) = softmax( Q Kᵀ / √d_k + M ) V

where M is the mask: 0 for allowed positions and −∞ for forbidden ones. The steps in the walk-through are:

  1. 1. Input X: one row per token.
  2. 2. Projections: Q = X·W_Q, K = X·W_K, V = X·W_V.
  3. 3. Transpose K, so that the multiplication works.
  4. 4. Scores S = Q Kᵀ: an n × n table; entry (i, j) is how well query i matches key j.
  5. 5. Scaling by √d_k. Dot products of long vectors tend to grow with their dimension d_k (if the entries are independent with variance 1, the variance of the dot product is d_k). Large scores push softmax toward an almost one-hot result with tiny gradients. Dividing by √d_k keeps the scores in a good range.
  6. 6. Causal mask: −∞ is added to the forbidden (future) positions, so they receive weight exactly 0 after softmax.
  7. 7. Softmax on each row: every row becomes weights that add up to 1.
  8. 8. Multiply by V: each output row is a weighted average of the value rows.

Shapes: Q and K are n × d_k, V is n × d_v, the score table is n × n, and the output is n × d_v. Because of the n × n table, the cost of attention grows with the square of the sequence length, which is why long contexts are expensive.

Simplification: the numbers in this example are small and made up so that you can follow them by hand. GPT-2 small, for example, uses d_k = 64 per head.

MULTI-HEAD ATTENTION

Several attention "heads" at once

The model runs several attention mechanisms in parallel ("heads"), each potentially learning different patterns.

Different heads can learn different patterns — the examples shown here are simplified interpretations for visualization, not fixed roles proven for every model.

In more detail

Instead of one attention operation, a transformer layer runs several in parallel, called heads. Each head has its own matrices W_Q, W_K and W_V, which project the vectors to a smaller size (usually d_model divided by the number of heads; in GPT-2 small, 12 heads × 64 = 768). The outputs of all heads are put together and mixed by an output matrix W_O, and the result is added to the residual stream (section 13).

Why several heads? Each head can learn to look at different positions with a different pattern. Research has found heads that mostly look at the previous token, heads that help the model copy repeated patterns (induction heads), and heads that seem to track syntactic relations. But not every head has a clean, human-readable role, many look redundant, and what a head does can differ between models.

Simplification: the roles shown in the visualization are examples for intuition, not fixed roles proven for every model.

POSITION

Positional information

In more detail

Attention on its own has no sense of order. If the input tokens were permuted and nothing else changed, the outputs would simply be permuted in the same way. But order carries meaning ("the dog bit the man" is not "the man bit the dog"), so models add positional information.

  • The original 2017 Transformer added fixed sinusoidal position signals to the token embeddings.
  • GPT-2 added learned position embeddings, one learned vector for each position up to its limit of 1,024.
  • Many recent models use rotary position embeddings (RoPE), which rotate the query and key vectors by an angle that depends on position, so that attention scores depend on how far apart two tokens are.
  • Other schemes exist. The choice affects how well a model handles texts longer than those it saw during training.

In decoder-only models, the causal mask can also let the model infer some positional information implicitly. The details differ from model to model, but the shared idea is that position must be supplied, because attention does not provide it by itself.

TRANSFORMER

The transformer block

Click each block to see its explanation. Many blocks like this are stacked on top of each other.

In more detail

A transformer is a stack of identical blocks. The original 2017 design had an encoder and a decoder; GPT-style chat models use only the decoder part ("decoder-only"). Each block has two sublayers: multi-head self-attention and a feed-forward network (MLP).

  • Residual connections. The output of each sublayer is added to its input instead of replacing it. This gives every position a running vector, the residual stream, that each layer reads from and adds to. It also makes deep networks much easier to train.
  • Layer normalization. Rescales each token's vector to keep the numbers in a stable range. The 2017 design applied it after each sublayer; GPT-2 and most later models apply it before ("pre-LN"), which tends to make training more stable.
  • Attention sublayer. Moves information between positions.
  • MLP sublayer. Two linear layers with a non-linear activation between them. It first widens the vector (typically by a factor of four: 768 to 3,072 in GPT-2 small) and then narrows it again. It is applied to each position separately. Research suggests that MLP layers act partly like stores of learned associations (Geva et al., 2021), although this is an active area of research.

After the last block, a final normalization and the unembedding matrix turn the vector of the last position into one score for every token in the vocabulary (section 14). GPT-2 small has 12 blocks and about 124 million parameters; larger models have more blocks and wider vectors.

Simplification: the diagram shows the main parts. Real models differ in details such as the normalization type, activation function and position scheme.

LOGITS & SOFTMAX

How does AI choose the next word?

The model produces a number ("logit") for every possible token, then <b>softmax</b> turns them into probabilities.

Low temperature → more concentrated distribution. High temperature → more spread out / random. This doesn't make the AI "smarter" or "dumber" — it just changes the randomness of the choice.

In more detail

The final vector at the last position is multiplied by the unembedding matrix. The result is one score, called a logit, for every token in the vocabulary (50,257 in GPT-2). Logits can be any real numbers; they are not probabilities.

Softmax turns them into probabilities: p_i = e^(z_i) / Σ_j e^(z_j). All results are positive and add up to 1. Only differences between logits matter: adding the same number to all of them changes nothing.

Temperature (T) divides the logits before softmax. With T below 1 the distribution becomes sharper, so likely tokens become even more likely. With T above 1 it becomes flatter and less likely tokens get more chance. As T approaches 0, the choice approaches always taking the top token, and implementations treat T = 0 as "always pick the highest". Temperature does not change what the model knows; it changes how it samples from its own distribution. Very high temperatures often produce incoherent text.

Common sampling strategies:

  • Greedy: always take the most probable token.
  • Top-k: keep only the k most probable tokens, renormalize, and sample.
  • Top-p (nucleus) sampling: keep the smallest set of tokens whose probabilities add up to at least p, and sample from it (Holtzman et al., 2019).

Chat products usually choose such settings for you.

AUTOREGRESSIVE GENERATION

Next-token generation simulator

The model generates one token at a time, adds it to the context, and repeats. Click a candidate token to add it.

CURRENT CONTEXT
Context↓Tokenization↓Model↓Logits↓Softmax↓Choose Token↓Add To Context↻

In more detail

A language model produces text one token at a time:

  1. 1. Take the current text (the context) and run it through the model.
  2. 2. Get a probability distribution over the next token.
  3. 3. Choose a token (by sampling or by taking the most probable one).
  4. 4. Append it to the text and repeat.

Generation stops when the model produces a special end-of-sequence token or reaches a length limit. Because every token depends on the ones before it, early choices influence everything that follows, and because choosing usually involves randomness, the same prompt can give different answers.

This is also why longer answers take longer: each new token needs another pass through the model. In practice, implementations store the keys and values of earlier tokens (the KV cache, see the Advanced track) so they do not have to be recomputed each time.

Simplification: the simulator lets you pick from a few candidate tokens. A real model computes a probability for every token in its vocabulary.

CONTEXT WINDOW

How much the model can "see" at once

The model can only see a limited number of tokens at a time — the context window.

Context windows are measured in tokens and vary by model.

In more detail

The context window is the maximum number of tokens the model can take into account at once. It includes your prompt, the earlier conversation, and the model's own answer so far. GPT-2 had a window of 1,024 tokens; modern models range from thousands to hundreds of thousands of tokens or more, depending on the model.

Limits exist because attention compares each token with all the earlier ones, so its cost grows with the square of the length in a straightforward implementation, and because the stored keys and values take memory.

What happens when the text does not fit depends on the application. It may refuse, cut off the oldest messages, or summarize them. Some architectures use sliding-window attention, where each token can see only a recent window.

Two further points:

  • Fitting into the window does not guarantee that the model uses all the information equally well. Studies have found that models can be worse at using information placed in the middle of a long context (Liu et al., 2023).
  • The model does not remember earlier, separate conversations unless the application stores information and supplies it again in the context.
TRAINING

But where did all these weights come from?

Weights are learned by comparing the model's predictions with the real target and gradually adjusting.

Massive dataset↓Prediction↓Compare with target↓Loss↓Backpropagation↓Update weights↻
SIMPLIFIED EXAMPLE
Target token"cat"
Loss (simplified)—
weight0.7200
gradient—
new weight—

In more detail

The main goal in pretraining a language model is to predict the next token. The model sees a large amount of text. For each position, it receives the text before it and outputs a probability for the true next token. The loss (cross-entropy) is −log p(true token): small when the model gave the right token a high probability, large when it gave it a low one.

The loss is averaged over many positions. Backpropagation computes how the loss would change if each parameter changed slightly (the gradient), and an optimizer changes every parameter a little in the direction that lowers the loss. This is repeated for an enormous number of steps.

Notice that nothing in this objective says "be truthful" or "be helpful". A pretrained base model is a text continuer. Assistants such as ChatGPT go through further stages (section 20).

Training is the expensive part. Inference, the use of a trained model, only runs the forward pass with fixed weights. The model does not learn from your chat by changing its weights.

Simplification: the visualization updates a single weight to make the idea clear. Real training updates billions of parameters at once.

GRADIENT DESCENT

The loss landscape

Training moves the "ball" toward lower-loss regions, one step at a time.

In more detail

Imagine the loss as a function of all the parameters, a "landscape". The gradient points in the direction in which the loss increases fastest. To reduce the loss, the parameters take a small step in the opposite direction:

new value = old value − learning rate × gradient

The learning rate sets the step size: too small and training is slow; too large and it overshoots or becomes unstable.

Real training uses small random groups of examples (mini-batches, hence "stochastic" gradient descent), usually with adaptive optimizers such as Adam or AdamW and a schedule that changes the learning rate over time.

The ball rolling down a hill is a metaphor with limits. Real loss landscapes have billions of dimensions and do not look like a single smooth bowl.

PARAMETERS

What does 7B or 70B parameters mean?

A parameter ≈ one learned numerical value (a weight). More parameters means more numbers to fit — but that alone doesn't guarantee higher "intelligence".

Number of parameters1,000,000

Parameter count doesn't directly equate to intelligence — architecture, data, training method and optimization all matter too.

In more detail

Parameters are all the numbers a model learns: embedding matrices, attention matrices, MLP weights, biases and normalization scales. "7B" means about 7 billion of them.

Size has a concrete cost. If each parameter is stored in 16 bits (2 bytes), 7 billion parameters take about 14 GB and 70 billion take about 140 GB, just for the weights. Techniques such as quantization (Advanced track) reduce this.

More parameters usually give a model more capacity, but quality also depends on the amount and quality of training data, the amount of training computation, the architecture and the later training stages. Studies of scaling laws (Kaplan et al., 2020; Hoffmann et al., 2022) found that the loss falls in a predictable way as parameters, data and computation grow, and that for a fixed budget the model size and the amount of data should be increased together. Some earlier large models were trained on too little data for their size.

In mixture-of-experts models (Advanced track), the total number of parameters is larger than the number used for each token.

ASSISTANT

From text predictor to assistant

In more detail

A model that has only been pretrained continues text. It does not follow instructions reliably. Assistants are usually built in several stages:

  1. 1. Pretraining: predicting the next token on a very large collection of text. This gives the model broad knowledge of language and the world, and also its mistakes and biases.
  2. 2. Supervised fine-tuning: further training on examples of good responses to instructions or questions, usually written or curated by people.
  3. 3. Preference training: people (or models guided by rules) compare alternative answers, and the model is trained to produce the preferred kind. One approach is reinforcement learning from human feedback (RLHF): a reward model is learned from the comparisons and then used to improve the assistant (Ouyang et al., 2022). Direct preference optimization (DPO) is a simpler alternative (Rafailov et al., 2023).
  4. 4. Deployment: the application adds instructions (system prompts), safety measures and sometimes tools such as search.

The exact methods vary between companies and are not always published. These stages change behavior, such as tone, helpfulness and refusals, but they do not turn the model into a database of verified facts (section 21).

HALLUCINATIONS

Why can AI be confident and wrong?

The model generates statistically likely sequences, rather than querying a database of guaranteed facts.

QUESTION: "The capital city of the planet Mars is..."

The model can produce a confident-sounding answer even when no correct answer exists — because of limits in training data, ambiguous prompts, statistical generation, and the lack of guaranteed factual verification. This isn't simply "the AI doesn't know."

In more detail

A hallucination is fluent output that is false or unsupported by facts. The model was trained to produce plausible continuations, and nothing in the basic process checks claims against reality. When information is rare, missing or ambiguous, the model may still produce a confident-sounding guess. This is not lying: the model has no intention to deceive.

Later training stages can reduce hallucinations, but they do not remove them. A confident tone is not evidence that something is correct. Invented references and quotations are a well-known example.

What helps:

  • Ask for sources and check them, since a model can invent sources.
  • Put the relevant text in the prompt and ask the model to answer from it.
  • Use systems that retrieve information from documents (retrieval-augmented generation, RAG) or use tools such as search and calculators.
  • Verify important facts, especially in medicine, law, finance and safety.
PROMPT ENGINEERING

Write prompts that actually work

Models respond to <b>instructions + context + format</b>. Compare a vague prompt with a structured one — same task, very different results.

❌ Vague prompt

✓ Structured prompt

Scores are a teaching rubric (clarity, context, output format) — not output from a live model.

In more detail

A prompt is the text you give the model. The model does not change when you write a prompt; the prompt only changes the context it works from. Prompts that tend to work well contain:

  • A clear task: what exactly you want done.
  • Relevant context: the background the model cannot know.
  • The desired format and length: list, table, number of words, language, tone.
  • Examples when the style matters (known as few-shot prompting; Brown et al., 2020).
  • The audience: who the answer is for.

For tasks that need several steps, asking for the steps to be shown can help, although this varies between models. If the first result is not right, improve the prompt and try again. There is no universal magic wording, and results can vary between models and between runs.

Note: the scores in this lab are a teaching rubric (clarity, context, format). They are not the output of a live model.

FOLLOW ONE TOKEN

Watch a single token travel through the whole model

Pick a word below, then step through exactly what happens to it — from raw text to its contribution to the final answer.

STEP1 / 9

This journey uses simplified, illustrative numbers to make the trip easy to follow — the sequence of operations (tokenize, embed, attend, transform, predict) mirrors real models.

In more detail

This walk-through follows a single token from input to output:

  1. 1. The text is split into tokens, and each becomes an ID.
  2. 2. The ID is looked up in the embedding table to get a vector.
  3. 3. Position information is added.
  4. 4. The vector passes through the blocks. In each block, attention gathers information from earlier positions and the MLP processes it, with the results added to the residual stream.
  5. 5. A final normalization is applied, and the unembedding turns the last vector into logits.
  6. 6. Softmax gives probabilities, and one token is chosen.
  7. 7. That token is appended, and the process repeats for the next one.

Simplification: the numbers are illustrative. The order of operations matches real models.

LIVE VISUALIZATION

The Living Network — watch AI think, live, as you type

A 68-neuron network that reacts to every single keystroke in real time. Every letter you type sends a pulse of light into the network — watch it ripple, cascade and fade across the layers, exactly like the signal-passing you learned about above.

LIVE · REACTS TO YOUR TYPING
NETWORK ENERGY
0%

This is a real, tiny feed-forward simulation (fixed random weights, sigmoid-like squashing, decay over time) driven live by your keystrokes — built purely to be watched. It is not a language model and doesn't "understand" what you type; it's a window into the kind of signal-passing every real neural network does, made visible.

In more detail

This is a small simulation of a feed-forward network with fixed random weights. Each key you press sends a pulse into the network, and you can see the signal spread across the layers and fade. It shows what signal passing through connected units looks like.

It is not a language model. It does not understand your text and it does not learn. The real computations in a language model (sections 08 to 15) are more structured, and they are not what is shown here.

· COMPLETE PIPELINE

The whole journey, start to finish

Click any step to jump to its explanation.

In more detail

Here is the whole journey in order:

  1. 1. Text is split into tokens.
  2. 2. Each token becomes an ID and then an embedding vector.
  3. 3. Position information is added.
  4. 4. The vectors pass through many blocks: attention moves information between positions, and MLPs process each position, all with residual connections and normalization.
  5. 5. The last vector is turned into logits, one per vocabulary token.
  6. 6. Softmax (with temperature and a sampling method) gives a token.
  7. 7. The token is appended, and steps 4 to 6 repeat until the answer ends.

All the numbers involved, the weights, were learned earlier in training, mainly by predicting the next token, and then shaped by fine-tuning and preference training to make the model a useful assistant.

AI TIME MACHINE

Scrub through AI history

From 1950 to 2024 — the milestones from the first learnable neuron through ChatGPT and after.

2024

In more detail

  • 1943: McCulloch and Pitts publish a mathematical model of a neuron.
  • 1958: Frank Rosenblatt introduces the perceptron.
  • 1986: Rumelhart, Hinton and Williams popularize backpropagation for training multi-layer networks.
  • 1997: Hochreiter and Schmidhuber introduce the LSTM, a network for sequences.
  • 2012: AlexNet wins the ImageNet competition by a large margin, a breakthrough for deep learning in vision.
  • 2013: word2vec popularizes learned word embeddings.
  • 2017: the Transformer is introduced in "Attention Is All You Need".
  • 2018: GPT (OpenAI) and BERT (Google) show the power of pretraining transformers.
  • 2019: GPT-2 shows strong text generation from a larger model.
  • 2020: GPT-3 (175 billion parameters) shows that a large model can learn tasks from examples in the prompt.
  • 2022: InstructGPT (March) shows how human feedback makes models follow instructions; ChatGPT is released publicly (30 November).
  • 2023: GPT-4 is released (March), and open-weight models such as LLaMA spread widely.
FLASHCARDS

Drill the core vocabulary

Flip a card, test yourself, and move on. Your streak of known cards is saved in this browser.

Known this session0
DAILY CHALLENGE

One quick question. Every day.

Build a micro-habit — answer today's AI question and keep your challenge streak alive.

Challenge streak1

ACHIEVEMENTS

Collect badges as you master AI

Explore sections, keep your streak and ace the quiz to unlock them all. Badges are saved only in this browser.

LEARNING MAP

Your constellation of progress

Each dot is a section in this lab. Orange stars mean you've been there.

KNOWLEDGE CHECK

Do you understand it now?

A short 6-question check covering the key ideas. Your best score is saved in this browser.

Question1 / 6
Best score—

SOURCES

Sources

  • Vaswani et al., "Attention Is All You Need" (2017).
  • Mikolov, Yih & Zweig, "Linguistic Regularities in Continuous Space Word Representations" (2013); Mikolov et al., "Efficient Estimation of Word Representations in Vector Space" (2013).
  • Radford et al., "Language Models are Unsupervised Multitask Learners" (GPT-2, 2019).
  • Brown et al., "Language Models are Few-Shot Learners" (2020).
  • Ouyang et al., "Training language models to follow instructions with human feedback" (2022).
  • Rafailov et al., "Direct Preference Optimization" (2023).
  • Sennrich, Haddow & Birch, "Neural Machine Translation of Rare Words with Subword Units" (BPE, 2016).
  • Hendrycks & Gimpel, "Gaussian Error Linear Units (GELUs)" (2016); Shazeer, "GLU Variants Improve Transformer" (2020).
  • Su et al., "RoFormer: Enhanced Transformer with Rotary Position Embedding" (2021).
  • Xiong et al., "On Layer Normalization in the Transformer Architecture" (2020).
  • Geva et al., "Transformer Feed-Forward Layers Are Key-Value Memories" (2021).
  • Jain & Wallace, "Attention is not Explanation" (2019); Wiegreffe & Pinter, "Attention is not not Explanation" (2019).
  • Holtzman et al., "The Curious Case of Neural Text Degeneration" (2019).
  • Liu et al., "Lost in the Middle: How Language Models Use Long Contexts" (2023).
  • Kaplan et al., "Scaling Laws for Neural Language Models" (2020); Hoffmann et al., "Training Compute-Optimal Large Language Models" (2022).
  • Rumelhart, Hinton & Williams, "Learning representations by back-propagating errors" (1986).
  • Kingma & Ba, "Adam: A Method for Stochastic Optimization" (2014).
· VISUALIZATION ENGINE

One engine, many labs

Probability bars, attention heatmaps, pipeline flows, and tensor shapes — shared building blocks behind the interactive lessons you have already explored.

Softmax → probability bars

Drag temperature: sharp peaks mean the model is confident; flat bars mean many tokens are plausible.

Attention matrix

Each row is one token “looking at” the others. Brighter cells = stronger connection (toy demo, same math as the mechanistic lab).

Tensor shapes

When docs say [batch, seq, dim], they mean stacked lists of numbers — not magic boxes.

Mini pipeline

The full recap at the end of the lab uses the same flow renderer — click a stage.

You've seen what happens inside the model. Now try changing it.