DeepLLM Quiz
Neural Network Architectures

Attention: building each output as a weighted mix of the inputs

10 questions on attention weights, why they depend on the input, soft versus hard attention, queries, keys and values, and dot-product self-attention.

  • 10 questions
  • Stopwatch
  • Instant feedback

Shown publicly with your score. Don’t use your full real name.

Sample questions

Play now ↑

Answers stay hidden. Start the quiz to play them.

  1. Sample 1

    Four attention weights for one output token must add up to one. Three of them are 0.5, 0.3 and 0.1. What is the fourth?

    • 0.3
    • 0.2
    • 0.1

How it works

  • One question per screen. An answer is final once sent.
  • You see right away whether you were right, with a short explanation.
  • The stopwatch runs: on equal scores, the faster player ranks first.
  • Only your best attempt counts, so replaying is never risky.

About this quiz

Read the sentence "He swung the bat and it flew out of the park" and the word bat means one thing. Read "A bat flew out of the cave at dusk" and the same word means another. To work out which, you glance at the neighbouring words: swung and park in one case, cave and dusk in the other. You do not give every word in the sentence equal weight, and which words matter depends on the sentence you are reading. Attention is the mechanism that lets a neural network do the same. It sits at the heart of the transformer, the architecture behind today's language models.

This quiz introduces attention from the ground up. You will see how a transformer treats its input as a set of tokens, each a vector of features, arranged in a table with one row per token, and how a layer turns that table into another table of the same shape. You will see that each output token is a blend of all the input tokens, with attention weights saying how much each contributes, and you will find out why those weights must be positive and must add up to one. You will meet the vocabulary borrowed from information retrieval, query, key and value, and the contrast between hard attention, which picks a single item, and soft attention, which blends them all.

The key point is that the weights are computed from the data. A standard network multiplies its inputs by weights that are fixed once training is over. In attention, how much one token influences another is decided afresh for each input, by comparing tokens with a dot product and passing the comparisons through a softmax. The questions use small numbers, such as a set of weights with one missing, so that you can check your understanding.

A few ideas are commonly muddled. Attention weights are not probabilities in any statistical sense, even though they look like them. A token can attend to itself. And the basic mechanism, as presented here, has no learnable parameters at all, which is what the next quizzes remedy.

The quiz suits learners who have met neural networks and want to understand the idea behind transformers, and practitioners who use language models and want to know what attention means. It needs only simple arithmetic. There are 10 questions, each with an explanation, and it takes about four minutes. Attention is worth understanding well because it is the one idea that nearly every modern language, image and speech model shares. Once you see that a layer simply recomputes, for every token, a mixture of all the tokens with weights chosen from the data, the rest of the architecture, queries and keys, several heads, stacked layers and position codes, falls into place as refinements. The mechanism also explains many behaviours of language models, from the way they resolve ambiguous words to the way their cost grows with the length of the text, so a clear picture of it pays off repeatedly.

Questions and answers

›How long does the quiz take?

About 3 to 4 minutes for 10 questions, at roughly 20 seconds each. An explanation follows each answer, so the ideas build up gradually.

›Do I need to know how language models work?

No. The quiz starts from the basic idea and uses sentences as examples. You should know that a neural network turns input vectors into output vectors, and that words can be represented as vectors, which the quiz on word embeddings explains in detail.

›What is attention?

It is a way of building the representation of each item in a sequence from the other items, giving more weight to those that matter more for the item in question. In a sentence, the meaning of an ambiguous word is settled by the words around it. Attention lets a network rely more heavily on particular words from the rest of the sequence.

›What is a token?

It is one element of the input, expressed as a vector of numbers called features. A token might be a word in a sentence, a patch of an image or an amino acid in a protein. Because everything is turned into tokens, the same architecture can handle different kinds of data, and even mixtures of them, without being redesigned.

›Why do attention weights have to be non-negative and add up to one?

Non-negative weights prevent one large positive weight from being cancelled by a large negative one. Adding up to one means that paying more attention to one input necessarily means paying less to the others. Together the two conditions make the weights a partition of unity, so that each output is a genuine blend of the inputs.

›How do attention weights differ from ordinary network weights?

In an ordinary network, the weights that multiply the inputs are fixed once training has finished. In attention, the weighting factors are computed from the specific input data, so the same trained network pays attention to different places for different inputs. A weight near zero for one input switches off that signal path for that input only.

›What are queries, keys and values?

The terms come from information retrieval. A key describes an item, a value is the item itself, and a query describes what the user wants. A system compares the query with all the keys and returns the best-matching value. Soft attention generalises this by blending all the values according to how well each key matches the query.

›What is self-attention?

It is attention in which the queries, keys and values all come from the same sequence. Each token is compared with every token, itself included, using a dot product as the measure of similarity. A softmax turns the comparisons into weights, and the output for each token is the weighted sum of the values.

More quizzes