I've been watching a few lectures on transformers, especially for language translation, though it seemingly becomes more confusing the more I watch.

In this lecture, there seems to be two conflicting views of self-attention. First, there's an Iron Man example (at around 44:25) where the lecturer claims that self-attention helps identify the important aspects of the input, but she details the math in which a "self-attention heat map", which is the dot product of the query and key matrices, is multiplied by a value matrix giving an output, which I assume is an attention head. It seems like this attention head just encodes how words are related to each other (the map) and the words themselves (the value).

I don't understand how this extracts the important information, or why you only want the important information anyways for translation. Is it extracting the important relationships between words, because that would make more sense, but in what way does that relate to her Iron Man example then? What's the relationship of Iron Man to himself? Also, would each attention head contain its own set of three matrices? Is the idea perhaps that words that more words depend on are important? But wouldn't that simply remove single words that still are important for translation?

TLDR: Essentially, how does the idea of relationships between words translate to selecting important words in a sentence (if this is even what self-attention does).

  • $\begingroup$ Seems multiple questions here and not sure what's the most pertinent one for your understanding. One common difficulty facing NLP and translation is poly-semantic indeterminacy even for some word (not to mention the sense of whole sentence or paragraph), so self-attended multiple heads of words relations could often help to fix such indeterminacy issues such as the ubiquitous "it", "this", "that" in a parallel fashion. The Iron Man case using image to illustrate the same idea to perhaps help fix the caption or title of such image. Another attention head of spaceship may decide another caption. $\endgroup$
    – cinch
    Nov 27, 2022 at 3:58

2 Answers 2


First of all, I totally agree that the Iron Man example is a little off the topic and not really clear to explain the concept of self-attention.

But she had a point there. Just like what you said, the self-attention mechanism extracts the relationships between words and then after being scaled down and multiply with the value tensor, it makes more sense for what are the important keys that need to be attended by the model.

Now let's get back to the Iron Man example. I think the idea is that our brains can immediately know which parts are the important part of the image to focus on because we all have that attention filter that is always turning on.

It's different from the CNN or the RNN model, which needs to know the feature first (feature extraction). The self-attention calculates the relationship between each token and the importance on the whole image first and then can use that information to focus on feature extraction on those really important parts.


One way to think about this is that self-attention does a summary of what is going on, either in text or images. But rather than creating a new representation for the summary, the summary is represented by assigning weights to units of the original content it's summarizing.

Somewhat like instead of reading the whole paragraph above, or summarizing, you just read what's written in bold.

When it comes to text, that weight is given to the most "representative" words within the sentence, in pictures you can think of an heat map perhaps indeed.

To determine what units (say words) could be most representative, you look at the data itself, and see what words have stronger relationships with others. This is the same philosophy behind search and the page rank algorithm

Lastly to clarify a remark the OP made: this is not the only information an ML model (say a Transformer) would look at. But it is an approach the model uses to extract some meaningful information (i.e. create some meaningful features), which is then further processed by other parts of the model.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .