<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged head</title>
<link>https://coderlegion.com/tag/head</link>
<description>Powered by Question2Answer</description>
<item>
<title>Attention Is All You Need - Part 5</title>
<link>https://coderlegion.com/18995/attention-is-all-you-need-part-5</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on GitHub. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In previous article we discussed about step 2 of transformer model, i.e. position encoding.&lt;/p&gt;

&lt;p&gt;In this article we will discuss step 3 of transformer model, i.e. Multi-Head Attention.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Traditional RNN model didn't work for long sentences?
&lt;/h2&gt;

&lt;p&gt;Before 2017, we were using LSTM and RNN models for NLP tasks. &lt;/p&gt;

&lt;p&gt;Basicaly as the input of words and processing and context was very less.&lt;/p&gt;

&lt;p&gt;For Example let's assume there are 3 words model processes words 1 by 1.&lt;/p&gt;

&lt;p&gt;So, first sentence it was taking about river bank.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight plaintext&quot;&gt;&lt;code&gt;The river bank.
The United Bank
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptr448fmwumrgszmvto7.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fptr448fmwumrgszmvto7.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;381&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next it is about united bank which is has no related data but as we did embeding and positonal encodings we have very low probablity of understanding the context.&lt;/p&gt;

&lt;p&gt;Here is the example of how it vector might look like.&lt;br&gt;
&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4ineg0vl9p7r4sjye47.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fo4ineg0vl9p7r4sjye47.png&quot; alt=&quot;&quot; width=&quot;800&quot; height=&quot;845&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How Single Attention Head works?
&lt;/h2&gt;

&lt;p&gt;A single attention head works by determining how much focus a specific token (word) in a sequence should place on other tokens to better understand its own context.&lt;/p&gt;

&lt;p&gt;Let's take example: &quot;The cat sat on the mat.&quot;&lt;/p&gt;

&lt;p&gt;For the token &quot;sat&quot;, the attention head might learn to pay high attention to &quot;cat&quot; and &quot;mat&quot; because they are directly related to &quot;sat&quot;.&lt;/p&gt;

&lt;p&gt;Let's get understanding these in details in next article by actual implementing it.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/18995/attention-is-all-you-need-part-5</guid>
<pubDate>Tue, 02 Jun 2026 00:46:42 +0000</pubDate>
</item>
<item>
<title>Attention Is All You Need - Part 6</title>
<link>https://coderlegion.com/18994/attention-is-all-you-need-part-6</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In previous article we discussed about why traditional RNN model didn't work for long sentences.&lt;/p&gt;

&lt;p&gt;In this article we will discuss about, how single attention head works?&lt;/p&gt;

&lt;h2&gt;
  
  
  Why Single Attention Head is not enough?
&lt;/h2&gt;

&lt;p&gt;In single attention head, context of word is maintained and relates word/ token to each other.&lt;/p&gt;

&lt;p&gt;But this also comes with a limitation of contextual understanding.&lt;/p&gt;

&lt;p&gt;For Example:&lt;/p&gt;

&lt;p&gt;If the sentence had multiple meanings, single attention head will focus on one.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight plaintext&quot;&gt;&lt;code&gt;In 5 Coach long train, in first coach the man was sleeping in 2nd coach the man was standing in 3rd coach the man was playing and in 4th coach the man was eating food.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, for contextual understanding of &lt;code&gt;man&lt;/code&gt; in above example needed and that is where single attention head fails.&lt;/p&gt;

&lt;p&gt;To Solve this, multi head attention is introduced.&lt;/p&gt;

&lt;h2&gt;
  
  
  Multi Attention Head
&lt;/h2&gt;

&lt;p&gt;Multi Attention Head works parallelly and independently. So, it captures contextual understanding of word/ token.&lt;/p&gt;

&lt;p&gt;&lt;a rel=&quot;nofollow&quot; href=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wk0koo8gt3x8yvc8ejd.png&quot; class=&quot;article-body-image-wrapper&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F4wk0koo8gt3x8yvc8ejd.png&quot; alt=&quot;&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  What next?
&lt;/h2&gt;

&lt;p&gt;Finaly we got some idea on what end all happening under this.&lt;/p&gt;

&lt;p&gt;I just want to hold upcomming exploration.&lt;/p&gt;

&lt;p&gt;Just by getting into surface level I learned many things. But detailing i couldn't learn.&lt;/p&gt;

&lt;p&gt;I think by 2 weeks I will explore those field and share my learning.&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href=&quot;https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://proceedings.neurips.cc/paper_files/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/18994/attention-is-all-you-need-part-6</guid>
<pubDate>Mon, 01 Jun 2026 09:29:27 +0000</pubDate>
</item>
</channel>
</rss>