Answers.Body: <p>One way to think about this is that self-attention does a <strong>summary of what is going on</strong>, either in text or images. But rather than creating a new representation for the summary, the summary is represented <strong>by assigning weights to units of the original content</strong> it's summarizing.</p>
  <p>Somewhat like instead of reading the whole paragraph above, or summarizing, you just read what's written in bold.</p>
  <p>When it comes to text, that weight is given to the most &quot;representative&quot; words within the sentence, in pictures you can think of an heat map perhaps indeed.</p>
  <p>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 <a href="https://en.wikipedia.org/wiki/PageRank" rel="nofollow noreferrer">page rank algorithm</a></p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2024-02-23T09:18:02.563Z
Answers.LastActivityDate: 2024-02-23T09:18:02.563Z
Answers.UserDisplayName: drewlr
Answers.Body: <p>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.</p>
  <p>But she had a point there. Just like what you said, the self-attention mechanism extracts the <strong>relationships between words</strong> and then after being scaled down and multiply with the value tensor, it makes more sense for what are <strong>the important keys</strong> that need to be attended by the model.</p>
  <p>Now let's get back to the Iron Man example. I think the idea is that our brains can immediately know <strong>which parts are the important part of the image to focus on</strong> because we all have that <strong>attention filter that is always turning on</strong>.</p>
  <p>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.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-11-23T10:58:32.133Z
Answers.LastActivityDate: 2022-12-29T10:21:35.813Z
Answers.LastEditDate: 2022-12-29T10:21:35.813Z
Answers.UserDisplayName: GunFire
Body: <p>I've been watching a few lectures on transformers, especially for language translation, though it seemingly becomes more confusing the more I watch.</p>
  <p>In <a href="https://www.youtube.com/watch?v=QvkQ1B3FBqA&amp;list=PLtBw6njQRU-rwp5__7C0oIVt26ZgjG9NI&amp;index=2" rel="nofollow noreferrer">this lecture</a>, 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 &quot;self-attention heat map&quot;, 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).</p>
  <p>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 <strong>relationships between words</strong>, 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?</p>
  <p>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).</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-11-27T03:58:02.437Z
Comments.Text: 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.
Comments.UserDisplayName: cinch
Tags: <neural-networks><transformer><attention>
Title: What is the intuition behind self-attention?
UserDisplayName: User
ThreadText: # What is the intuition behind self-attention?
  
  (Asked by: username_0 on 2022-11-23)
  
  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](https://www.youtube.com/watch?v=QvkQ1B3FBqA&list=PLtBw6njQRU-rwp5__7C0oIVt26ZgjG9NI&index=2), 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).
  
  **Tags:** neural-networks, transformer, attention
  
  > **Comments:**
  > **username_1**: 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.  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2022-11-23. Score: 3 | Accepted answer
  
  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.
  
  
  ---
  
  ### Answer by username_2 on 2024-02-23. Score: 0
  
  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](https://en.wikipedia.org/wiki/PageRank)
  
  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.
  
  
  ---
  
  