TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 05 of 62 · Inside the Transformer block

Encoder and decoder stacks

Easy

What do the encoder and decoder of the original Transformer each do, and which parts do modern LLMs keep?

1 · Start with the intuition

The original Transformer was built for translation. Picture two towers. The encoder tower reads the whole source sentence at once and produces one context-aware vector per source token. The decoder tower writes the translation one token at a time: at each step it looks at what it has written so far and at the encoder’s vectors, then predicts the next token. Each tower is a stack of identical layers (six in the paper) that have the same structure but their own weights. An encoder layer has two parts: self-attention, then a feed-forward network. A decoder layer has three: masked self-attention, attention over the encoder output, then a feed-forward network. The rest of this stage opens those boxes one at a time.

2 · How the mechanism works

Mechanism step 1 of 4 · no question to answer

Embed the tokens

Each token becomes a vector of width d_model (512 in the base model). Only the bottom layer sees embeddings; every other layer receives the output of the layer below it.

Next, we will look at: Encode the source. Move on when this operation makes sense.

Visualizing the behavior

Two stacks: the encoder reads the source, the decoder writes the output

Illustrative
layers 2–5layers 2–5encoder outputSource sentenceLe chat dort ici .Embedding + positionEncoder layer 1self-attn → FFNEncoder layer 6self-attn → FFNOutput so farThe catEmbedding + positionDecoder layer 1self-attn → enc-dec attn → FFNDecoder layer 6self-attn → enc-dec attn → FFNLinear + softmaxnext token: sleeps
  • Encoder layers
  • Decoder layers
  • Encoder output
Read from the bottom up. The encoder runs once over the whole source. Its top layer’s output, one vector per source token, is fed to every decoder layer (two of the six arrows are drawn). The decoder runs once per new output token. The words are simplified labels, not real tokenizer output.

Inside one layer of each stack

from top encoder layerEncoderlayer inSelf-attentionall positions+ NormFeed-forwardper position+ NormDecoderlayer inSelf-attentionmasked+ NormAttentionover encoder+ NormFeed-forwardper position+ Norm
Top row: an encoder layer has two sub-layers. Bottom row: a decoder layer has three; the extra one attends over the encoder output. “+ Norm” means the sub-layer’s input is added back to its output (the residual connection) and the sum is layer-normalized. A decoder-only model keeps the bottom row without the middle attention box.