Skip to content
Learn Motion
ExploreHow it worksMembership
Log in
Learn Motion

How Large Language Models Work: From Tokens to Inference

1From Text to Tokens2Embeddings: Turning Tokens into Vectors3The Transformer Block: Attention and Feed-Forward Processing4Stacking Blocks into a Language Model5Training: How the Model Learns to Predict6From Pretraining to Instruction Following7Inference: Generating Text Token by Token
Stacking Blocks into a Language Model

Where Position Comes From and Why Blocks Repeat

1 / 2
Start with the embedding lookup you already have: it gives each token a vector but says nothing about order. Attention is a weighted sum, and a weighted sum does not care about the order of its terms, so two sentences with the same words in different orders would look identical. Positional encoding fixes this by producing a vector for each position index, added element-wise to the token embedding before the first block. Now look at the stack: every block takes a sequence of vectors and returns a sequence of the same shape, so the output of one block is a valid input to the next. The blocks share an architecture but not their weights, and each one refines what the previous block produced. Residual connections and layer normalization are what keep that repeated refinement stable as depth grows.
0:00 / 0:00

The embedding lookup from the previous chapter maps each token ID to a vector, but that lookup has no notion of order: the same token produces the same vector whether it appears first or fiftieth. Self-attention inherits this blindness because it computes a weighted sum over positions, and a weighted sum does not care about the order of its terms. Positional encoding solves this by producing a vector for each position index, and that vector is added element-wise to the token embedding before the first block. The result is a single input vector per position that carries both what the token is and where it sits.

Once position is encoded, the same block can be applied repeatedly. Each block takes a sequence of vectors and returns a sequence of vectors of the same shape, so the output of one block is a valid input to the next. Stacking increases capacity because each block refines the representation the previous block produced: early blocks tend to capture local patterns, later blocks can combine those into longer-range structure. The blocks are not identical in their learned weights; they share an architecture but each has its own parameters. Residual connections and layer normalization, established in the previous chapter, are what keep the signal stable across depth so that many blocks can be trained without the activations exploding or vanishing.

Previous1 / 2Next

Learn Motion

Generate a course. Learn it properly.

Operated by Wuhan Daoyin Technology Co., Ltd.

Contact: [email protected]
Privacy PolicyTerms of Service

© 2026 Learn Motion