Course map
Stage 1: Foundations
Stage 2: Machine Learning
Stage 3: Deep Learning
Stage 4: LLMs & Generative AI
Stage 5: Production & Specialization

Part 12 / Topic 3 of 6

Embeddings

Networks eat numbers, not words. An embedding is a learned lookup table from token id to trainable vector.

emb = nn.Embedding(num_embeddings=5000, embedding_dim=8)
emb(torch.tensor([12, 407, 12])).shape   # (3, 8); same id -> same vector
# trainable params: 40000 (5000 x 8 — the table IS the parameters)

Trained on a task, embeddings arrange themselves meaningfully: tokens used similarly end up near each other (by cosine similarity — Part 2's measure). Stage 4 builds search and RAG on exactly this property, with whole sentences as vectors.

🧪 Quick quiz

  1. What is an embedding layer, mechanically?
Show the answer

A trainable lookup table mapping each token id to a vector — 5,000 ids × 8 dims = 40,000 parameters, learned like any other weights.

Done here? The practice set for Part 12 — 4 exercises with solutions — is on the part page.

Search the guide