<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Understand Transformers]]></title><description><![CDATA[This blog series aims to provide a starting point for working with Generative AI. Reading the entire series will equip you to begin experimenting and integratin]]></description><link>https://gen-ai-transformers.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Tue, 13 Oct 2026 14:55:07 GMT</lastBuildDate><atom:link href="https://gen-ai-transformers.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[🧠Attention Made simple]]></title><description><![CDATA[Let’s break down a key concept behind models like GPT: Attention — the secret sauce that helps models understand words in context.
What is Attention?
Think of attention as spotlighting the right words in a sentence.For example, take this sentence:

"...]]></description><link>https://gen-ai-transformers.hashnode.dev/attention-made-simple</link><guid isPermaLink="true">https://gen-ai-transformers.hashnode.dev/attention-made-simple</guid><category><![CDATA[AI]]></category><category><![CDATA[DeepLearning]]></category><category><![CDATA[Transformers in LLM]]></category><category><![CDATA[transformers]]></category><category><![CDATA[GPT 4]]></category><category><![CDATA[nlp]]></category><category><![CDATA[generative ai]]></category><category><![CDATA[Build In Public]]></category><category><![CDATA[#LearninPublic]]></category><dc:creator><![CDATA[Immanuel Dsouza]]></dc:creator><pubDate>Wed, 23 Jul 2025 17:04:46 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1753290157493/dbb4be07-ac1c-4b22-89f7-39695aa0ad87.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Let’s break down a key concept behind models like GPT: <strong>Attention</strong> — the secret sauce that helps models understand words in context.</p>
<h2 id="heading-what-is-attention">What is Attention?</h2>
<p>Think of attention as <strong>spotlighting the right words</strong> in a sentence.<br />For example, take this sentence:</p>
<blockquote>
<p><em>"The cat was being chased by the dogs."</em></p>
</blockquote>
<p>If someone asks: <strong>"Who was chasing?"</strong><br />You instantly focus on <strong>“dogs”</strong>. That’s attention — focusing on the <strong>relevant part</strong> of the sentence to make sense of it.</p>
<p>Attention uses 3 characters to compute the “attention” sort thing. Those 3 things are Queries, Values , Keys</p>
<ul>
<li><p>Query (Q) - Its like a question each word asks as in “Who should I pay more attention to understand myself better ?“</p>
</li>
<li><p>Key (K) - Its like a tag each word carries about what it offers , per say “Here is the info i hold.”</p>
</li>
<li><p>Value (V) - Its like the actual information that can be shared as in “Here’s my content, if u need it”</p>
</li>
</ul>
<h2 id="heading-explained-here-with-a-simple-example">Explained here with a simple Example !</h2>
<p>Let’s use the sentence:</p>
<blockquote>
<p><em>“The cat sat on the mat.”</em></p>
</blockquote>
<p>Focus on the word <strong>“sat”</strong>.<br />Now imagine <strong>“sat”</strong> becomes a <strong>Query</strong>. It asks,</p>
<blockquote>
<p><em>“Who can help me understand what I mean here?”</em></p>
</blockquote>
<p>All the other words — “The”, “cat”, “on”, “the”, “mat” — are turned into <strong>Key + Value</strong> pairs.</p>
<p>Now, “sat” will:</p>
<ol>
<li><p><strong>Compare its Query</strong> with the Keys of all other words (using <strong>dot product</strong>).</p>
</li>
<li><p>Get <strong>attention scores</strong>: Higher if the Key matches the Query.</p>
</li>
<li><p>Pass the scores through <strong>Softmax</strong> — to turn them into weights like:</p>
</li>
<li><p>Use these weights to mix the <strong>Values</strong> of those words — giving “sat” a context-aware meaning.</p>
</li>
</ol>
<pre><code class="lang-plaintext">cat -&gt; 70%
mat -&gt; 20%
others -&gt; 10%
</code></pre>
<h2 id="heading-why-is-it-called-self-attention">Why is it called Self-Attention ?</h2>
<p>Because every other word goes through this process - comparing itself with all others (including itself). This mutual attention gives the model a deep layered understanding of how words relate.</p>
<p>That’s the core idea behind <strong>self-attention</strong> — the building block of Transformers.</p>
]]></content:encoded></item><item><title><![CDATA[✨Why GPT needs Positional Encoding]]></title><description><![CDATA[When we type something to GPT , have u ever wonder “How does the model understand what comes after what or who is going to whom ?”  
After all language is more than just words, right !Its also about structure, order and context. That’s where the Posi...]]></description><link>https://gen-ai-transformers.hashnode.dev/why-gpt-needs-positional-encoding</link><guid isPermaLink="true">https://gen-ai-transformers.hashnode.dev/why-gpt-needs-positional-encoding</guid><category><![CDATA[General Programming]]></category><category><![CDATA[gen ai]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[llm]]></category><category><![CDATA[gpt]]></category><category><![CDATA[transformers]]></category><category><![CDATA[positional encoding]]></category><dc:creator><![CDATA[Immanuel Dsouza]]></dc:creator><pubDate>Mon, 14 Jul 2025 12:17:17 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752495309890/a73a6990-c557-4ffa-9ca8-57ceed2293a0.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>When we type something to GPT , have u ever wonder “How does the model understand what comes after what or who is going to whom ?”  </p>
<p>After all language is more than just words, right !<br />Its also about structure, order and context. That’s where the <strong>Positional Encoding</strong> comes in.  </p>
<h2 id="heading-why-transformers-need-positional-encoding">🧠Why Transformers need Positional Encoding</h2>
<p>Transformers are designed to look up at all words at once. This makes it incredibly powerful and but also makes them blind to word order unless we do something about it.  </p>
<p>Imagine this sentence below  </p>
<blockquote>
<p>The cat chased the mouse</p>
</blockquote>
<p>Now scramble the words</p>
<blockquote>
<p>Mouse the cat chased the</p>
</blockquote>
<p>Both sentences are created via same words , but one is meaningful and other one is meaningless and makes no sense .<br />Without knowing who comes first ,the model won’t understand the message.  </p>
<h2 id="heading-what-is-positional-encoding">🧩What is Positional Encoding</h2>
<p>Positional encoding is technique to inject order while processing text in parallel by model.<br />Its like whispering to the model :  </p>
<blockquote>
<p>“Hey, this word is the <strong>first</strong>, this one’s the <strong>second</strong>, this one’s <strong>near the verb</strong>, and this one’s <strong>at the end</strong>.”</p>
</blockquote>
<p>It does not change the words, just adds the <mark>sense of position</mark> to each one.</p>
<h2 id="heading-lets-talk-about-context">Let’s talk about Context</h2>
<p>Consider the word “bank”.</p>
<ul>
<li><p>He sat by the <mark>bank </mark> and watched the sunset.</p>
</li>
<li><p>He deposited his cash at the <mark>bank</mark>.</p>
</li>
</ul>
<p>Same word ,but different meaning right !  </p>
<h3 id="heading-how-does-the-model-figure-this-out">How does the model figure this out ?</h3>
<p>The word bank in each sentence is surrounded by different neighboring words, in different positions. Positional encoding helps GPT combine :</p>
<ul>
<li><p>Where the word is</p>
</li>
<li><p>What’s around it</p>
</li>
</ul>
<p>This gives the contextual meaning to the model.</p>
<h2 id="heading-types-of-positional-encoding-no-math-promise">📦Types of Positional Encoding (No Math, Promise)</h2>
<ul>
<li><p>Sinusoidal Encoding : Adds a <strong>pattern</strong> to each word based on its position — kind of like each word dancing to a different rhythm. This helps the model to feel the “beat” of every sentence.</p>
</li>
<li><p>Learnable Encoding : The model learns what position feels like. (Used in modern models)  </p>
</li>
</ul>
<h2 id="heading-final-takeaway">🧠Final Takeaway</h2>
<p>Positional Encoding gives words a <strong>sense of place</strong> — like a tag saying “I’m first,” “I come after the subject,” or “I’m the closing word.”</p>
]]></content:encoded></item><item><title><![CDATA[🧠 How GPT Understands Your Prompt — From Text to Tokens to Meaning]]></title><description><![CDATA[GPT models operate under the hood using Transformers — a powerful neural architecture designed for understanding sequences like text. Contrary to what we might think, these models don’t work directly with human-readable characters or words. Instead, ...]]></description><link>https://gen-ai-transformers.hashnode.dev/how-gpt-understands-your-prompt-from-text-to-tokens-to-meaning</link><guid isPermaLink="true">https://gen-ai-transformers.hashnode.dev/how-gpt-understands-your-prompt-from-text-to-tokens-to-meaning</guid><category><![CDATA[generative ai]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[transformers]]></category><category><![CDATA[GPT 3]]></category><category><![CDATA[claude.ai]]></category><category><![CDATA[gemini]]></category><category><![CDATA[DeepLearning]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[genai]]></category><category><![CDATA[software development]]></category><category><![CDATA[Software Engineering]]></category><dc:creator><![CDATA[Immanuel Dsouza]]></dc:creator><pubDate>Thu, 10 Jul 2025 16:06:36 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1752163474348/c7391186-8dc7-4982-beda-804ec947dc4a.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>GPT models operate under the hood using <strong>Transformers</strong> — a powerful neural architecture designed for understanding sequences like text. Contrary to what we might think, these models don’t work directly with human-readable characters or words. Instead, there's a fascinating pipeline that transforms your prompt into a format the model can process.</p>
<h2 id="heading-step-1-breaking-down-the-prompt">🧩 Step 1: Breaking Down the Prompt</h2>
<p>When you type a prompt, the first thing that happens is the text is broken into smaller pieces. This isn't just for fun — it helps the model:</p>
<ul>
<li><p>Handle <strong>longer</strong> inputs</p>
</li>
<li><p>Understand <strong>unseen</strong> or <strong>misspelled</strong> words</p>
</li>
<li><p>Maintain flexibility with <strong>different word forms</strong></p>
</li>
</ul>
<p>These smaller units are called <strong>tokens</strong>, or more technically, <strong>subword units</strong>. This tokenization step is handled by a separate program called a <strong>tokenizer</strong>, which uses a variety of algorithms to break down words based on different rules and contexts.</p>
<p>If you're curious about how tokenizers work in detail, here’s a great resource by HuggingFace given below:</p>
<p><a target="_blank" href="https://huggingface.co/docs/transformers/en/tokenizer_summary">Tokenizer in Transformers</a></p>
<h2 id="heading-step-2-tokens-ids-embeddings">🔄 Step 2: Tokens → IDs → Embeddings</h2>
<p>Once the text is tokenized, each token is mapped to a unique number called a <strong>token ID</strong>, based on the model’s internal <strong>vocabulary</strong>.<br />You can think of this vocabulary as a giant lookup table that maps each known token to a number.</p>
<p>These token IDs are then converted into <strong>high-dimensional vectors</strong> using something called an <strong>embedding matrix</strong>. These vectors — called <strong>embeddings</strong> — represent the tokens in a format that the neural network can understand and work with.</p>
<h2 id="heading-step-3-from-generic-to-contextual-meaning">🧠 Step 3: From Generic to Contextual Meaning</h2>
<p>nitially, token embeddings are context-independent — they mean the same across different sentences. For example:</p>
<ul>
<li><p>S1: <em>Bird flies high</em></p>
</li>
<li><p>S2: <em>I am high</em></p>
</li>
</ul>
<p>The word “high” would have the <strong>same embedding</strong> in both cases, even though the meaning clearly changes based on context.</p>
<p>That’s where the real magic begins.</p>
<p>Through <strong>self-attention</strong> and <strong>feedforward layers</strong> techniques inside the Transformer, the model begins to <strong>refine</strong> these embeddings. It learns how each token relates to others in the sentence — and updates the embeddings to reflect the <strong>true, contextual meaning</strong>.</p>
<h2 id="heading-step-4-deep-understanding">🧬 Step 4: Deep Understanding</h2>
<p>These refined embeddings are passed through <strong>multiple layers of the neural network</strong>, each extracting increasingly complex and abstract features. As the data flows through the layers, the model uncovers:</p>
<ul>
<li><p>Sentence structure (syntax)</p>
</li>
<li><p>Emotions or tone (sentiment)</p>
</li>
<li><p>Intent, reasoning, and relationships</p>
</li>
</ul>
<p>All of this happens in a fraction of a second — resulting in the model generating coherent and meaningful responses.</p>
<h3 id="heading-wrapping-up">🔚 Wrapping Up</h3>
<p>So next time you enter a prompt, remember: behind the scenes, it's not just "text in, text out."</p>
<p>What starts as a simple sentence turns into a rich, high-dimensional representation that lets GPT understand you with remarkable intelligence.</p>
<p>Stay tuned for my next blog on <strong>Positional Encoding</strong> — how Transformers keep track of word order without using recurrence.</p>
<h3 id="heading-ia"> </h3>
<p>Until then, take care and peace ✌️</p>
]]></content:encoded></item><item><title><![CDATA[Why need of Transformers]]></title><description><![CDATA[What was going wrong with LSTM/RNN ?
LSTM / RNN are good in processing text word-to-word .They carry information about past words through hidden state(memory slot). Just to provide brief, “hidden state” stores information about the position, order an...]]></description><link>https://gen-ai-transformers.hashnode.dev/why-need-of-transformers</link><guid isPermaLink="true">https://gen-ai-transformers.hashnode.dev/why-need-of-transformers</guid><category><![CDATA[generative ai]]></category><category><![CDATA[transformers]]></category><category><![CDATA[gpt]]></category><category><![CDATA[Artificial Intelligence]]></category><category><![CDATA[llm]]></category><category><![CDATA[genai]]></category><dc:creator><![CDATA[Immanuel Dsouza]]></dc:creator><pubDate>Tue, 08 Jul 2025 15:34:32 GMT</pubDate><content:encoded><![CDATA[<h2 id="heading-what-was-going-wrong-with-lstmrnn">What was going wrong with LSTM/RNN ?</h2>
<p>LSTM / RNN are good in processing text word-to-word .They carry information about past words through hidden state(memory slot). Just to provide brief, “hidden state” stores information about the position, order and other info about input tokens. All this info are compressed in hidden state.  </p>
<p>Alright, coming back to our discussion. Now everything was going well until LSTM / RNN took toll on its performance, when it started to process very long sentences. These LSTM / RNN networks performed poor to retain relevant information while processing longer sentences. Not only that, it did not understand the proper relationship between distant words in longer sentences.</p>
<blockquote>
<p>Note : Tokens are meaningful machine code which are well understood by LLMs. I will talk about this tokens in my next upcoming blog.</p>
</blockquote>
<p>Also ,LSTM / RNN are slow to train because the tokens are processed sequentially and demands higher computational complexity.</p>
<p>LSTM / RNN do struggle with vanishing / exploding gradient.</p>
<p>Thus contributing to poor long memory and slow training.</p>
<hr />
<h2 id="heading-how-transformer-solve-this-problem">How Transformer solve this problem ?</h2>
<p>Transformer something called “Attention” approach. A very smart approach, the Google AI researchers came up with.</p>
<ul>
<li><h3 id="heading-solution-to-forgetfulness">Solution to Forgetfulness</h3>
</li>
</ul>
<p>Attention makes the model to focus on relevant parts of input. When processing any word, the model can look back at all other words in sentence and assign important-scores. This direct connection eliminates long range memory problem.</p>
<ul>
<li><h3 id="heading-solution-to-slowness">Solution to Slowness</h3>
</li>
</ul>
<p>The Attention allows the model to concurrently calculate the “important-scores” for all words(tokens) , the entire sequence can be processed in parallel fashion. This drastically improves speed.</p>
<hr />
<p>That’s it for today. This was all about How the transformers are better than LSTM/ RNN. I wanted to keep this short for less than 3-5mins read.  </p>
<p>For a more visual and comprehensive understanding of the 'Attention is All You Need' paper – the foundation of modern LLMs – I highly recommend watching this video</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://youtu.be/iDulhoQ2pro?si=hbfDecr_NxR1tNdc">https://youtu.be/iDulhoQ2pro?si=hbfDecr_NxR1tNdc</a></div>
]]></content:encoded></item></channel></rss>