Transformers From Scratch: Tokens, Embedding Size, and the CLS Token
Personal study notes on transformer fundamentals: tokenization, embedding size, positional encoding, the CLS token, Q/K/V, multi-head attention, masking, residual connections, LayerNorm, feed-forward layers, logits/softmax, and what actually gets trained (backprop, loss, frozen encoders) — with a beginner glossary and a real ViT facial-emotion pipeline as the worked example.
In this article
- The problem: raw input isn't numbers a network can use
- Tokens
- Embeddings & embedding size
- Positional encoding
- The CLS token
- Why plain embeddings aren't enough
- Query, Key, and Value, worked through camera + text
- Multi-head attention & masking
- Residuals, LayerNorm & the feed-forward layer
- From CLS output to a prediction: logits & softmax
- What actually gets trained, and how
- Mistakes I made learning this
- Glossary