Deconstructing the Attention Mechanism: How Queries, Keys, and Values (Q, K, V) Work

https://hackernoon.imgix.net/images/8GXbC1DstkNBgGYHFtm5vB7ix6D3-la03bsf.jpeg

Let’s Start with Finding a Book in the Library

In the previous article, we discussed how the attention mechanism enables AI to learn “translation with reference to the source text”: for every word it writes, it looks back at the source text, assigns a “relevance score” to each word, and then integrates the information based on those scores. But how exactly is the relevance score calculated? And what does the model use to express “what information I need”?

In this post, we’ll break down this process using the three sets of vectors: Q, K, and V.

Let’s Start with Finding a Book

Suppose you’ve never written code before and want to learn Python from scratch. With that in mind, you walk into the library. You wouldn’t flip through every one of the tens of thousands of books in the library; instead, you’d head straight to the “Computing/Programming” section.

The books...

Copyright of this story solely belongs to hackernoon.com. To see the full text click HERE