Module 2 · Inside the block

From the final vector to a score for every word

In this lesson

  • 8 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 8 of 10 in this chapter

This chapter’s goalImplement single-head attention from scratch in NumPy, explain which half of a block holds most of the parameters and which half moves information between positions, and predict how grouped-query attention, key-value caching and a mixture-of-experts design each change memory and speed.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 7Free · no account needed
Lesson steps

The last operation in the stack

After the final block, the vector at the last position is one list of, say, 4,096 numbers. It has to become a score for each of 128,256 possible next tokens. That happens with a single matrix multiplication against the unembedding matrix (one row per vocabulary entry) producing one number per entry.

Python
logits = final_vector @ W_unembed.T      # (4096,) @ (4096, 128256) -> (128256,)

Each logit is a dot product: how well does the final vector align with this token’s direction? Highest alignment, highest score.

Two consequences worth noticing. This one operation costs about 525 million multiply-adds in an 8B model, comparable to a whole layer, which is why large vocabularies are not free. And because it is a linear comparison against fixed directions, the geometry of the embedding space directly determines which tokens can be strongly preferred at all.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the AI, Actually Explained exam.

Stuck on something?Ask Anjali, your AI tutor

How to cite: Addaly (2026) ‘From the final vector to a score for every word’, in How a Language Model Actually Works. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/how-llms-work/from-final-vector-to-logits (Accessed: 29 November 2026).