techtree / Attention / ← prev 22 of 26 next →

Multi-head attention

Run several small attentions side by side and combine them.

55 seconds

Transcript

In one attention, each token gets one set of weights, so it blends in one way. But a word relates to the others in more than one way.

Here, draws looks to robot, to find who is drawing. It also looks to circles, to find what is drawn.

So the model runs several attentions side by side. Each one is called a head. Each head has its own query, key, and value matrices, so each can look for something different.

The heads work with shorter vectors, so together they cost about as much as one big attention.

Each head gives each token a short new vector. Set them end to end, into one long vector. Then one more matrix mixes them together.

Real models use a dozen heads or more. Several ways of looking, combined into one vector.