<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Adham Hewala</title>
    <description>The latest articles on DEV Community by Adham Hewala (@adhamhe6).</description>
    <link>https://dev.to/adhamhe6</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1157230%2Fa5ff860c-f520-413d-bf9a-2b86405f7e0c.jpeg</url>
      <title>DEV Community: Adham Hewala</title>
      <link>https://dev.to/adhamhe6</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adhamhe6"/>
    <language>en</language>
    <item>
      <title>Transformers Explained: Encoder, Decoder, and How GPT Generates Text</title>
      <dc:creator>Adham Hewala</dc:creator>
      <pubDate>Sat, 05 Sep 2026 11:27:36 +0000</pubDate>
      <link>https://dev.to/adhamhe6/transformers-explained-encoder-decoder-and-how-gpt-generates-text-3glp</link>
      <guid>https://dev.to/adhamhe6/transformers-explained-encoder-decoder-and-how-gpt-generates-text-3glp</guid>
      <description>&lt;p&gt;The Transformer diagram looks simple until you try to follow what actually happens to one token inside it.&lt;/p&gt;

&lt;p&gt;You see embeddings, attention, Q, K, V, Add &amp;amp; Norm, FFN, another attention block, logits, and finally some probabilities.&lt;/p&gt;

&lt;p&gt;Then you look at GPT and notice something even more confusing:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Where is the Encoder?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The original Transformer has an Encoder and a Decoder.&lt;/p&gt;

&lt;p&gt;GPT doesn't.&lt;/p&gt;

&lt;p&gt;Yet GPT is built on the Transformer architecture.&lt;/p&gt;

&lt;p&gt;So rather than treating these as separate topics, it makes more sense to follow the architecture from the bottom up and see how the pieces connect.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. The Original Transformer: Encoder + Decoder
&lt;/h2&gt;

&lt;p&gt;The Transformer was introduced in the 2017 paper &lt;strong&gt;"Attention Is All You Need."&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The original architecture was designed for sequence-to-sequence tasks such as translation.&lt;/p&gt;

&lt;p&gt;At a high level:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input sequence
      ↓
   Encoder
      ↓
Encoded representation
      ↓
   Decoder
      ↓
Output sequence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"I love programming."
          ↓
       Encoder
          ↓
   contextual representation
          ↓
       Decoder
          ↓
"J'aime programmer."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Encoder's job is to process the input and build useful contextual representations.&lt;/p&gt;

&lt;p&gt;The Decoder's job is to use those representations to generate the output.&lt;/p&gt;

&lt;p&gt;This distinction matters because modern Transformer models don't all use both sides.&lt;/p&gt;

&lt;p&gt;There are three common configurations:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encoder-only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used primarily for understanding or representation.&lt;/p&gt;

&lt;p&gt;Example: &lt;strong&gt;BERT&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encoder–Decoder&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used for transforming one sequence into another.&lt;/p&gt;

&lt;p&gt;Examples: the original Transformer, &lt;strong&gt;T5&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decoder-only&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Used primarily for autoregressive generation.&lt;/p&gt;

&lt;p&gt;Examples: &lt;strong&gt;GPT-style models&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So "Transformer" describes the architecture family, not one fixed model design.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Text Becomes Tokens, Then Vectors
&lt;/h2&gt;

&lt;p&gt;Before the Encoder or Decoder can do anything, text has to become numerical data.&lt;/p&gt;

&lt;p&gt;Suppose the input is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Translate this sentence into French."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A tokenizer breaks it into tokens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["Translate", " this", " sentence", " into", " French", "."]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact tokenization depends on the tokenizer.&lt;/p&gt;

&lt;p&gt;A token can be a complete word, part of a word, punctuation, or another frequently occurring piece of text.&lt;/p&gt;

&lt;p&gt;Those tokens are then mapped to integer IDs:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[18472, 351, 9281, 417, 6321, 13]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But the IDs themselves don't contain meaning.&lt;/p&gt;

&lt;p&gt;They're simply indexes into the model's vocabulary.&lt;/p&gt;

&lt;p&gt;So we need another step:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Token ID
   ↓
Embedding
   ↓
Vector
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A token such as &lt;code&gt;"cat"&lt;/code&gt; might become a vector like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[0.21, -0.73, 0.42, 0.18, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In a real model, that vector can contain hundreds or thousands of values.&lt;/p&gt;

&lt;p&gt;This is the point where the model stops dealing with discrete symbols and starts working with continuous numerical representations.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Position Matters
&lt;/h2&gt;

&lt;p&gt;There's another problem.&lt;/p&gt;

&lt;p&gt;A Transformer needs to know the order of the tokens.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Dog bites man.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Man bites dog.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same basic words are present, but the meaning is obviously different.&lt;/p&gt;

&lt;p&gt;Attention alone doesn't inherently tell the model that one token came before another.&lt;/p&gt;

&lt;p&gt;That's why Transformers use &lt;strong&gt;positional information&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In the original Transformer, this was done with sinusoidal positional encodings.&lt;/p&gt;

&lt;p&gt;Modern architectures often use other approaches, such as &lt;strong&gt;Rotary Positional Embeddings (RoPE)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The exact implementation can vary, but the purpose is the same:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Give the model information about where tokens occur and how their positions relate to one another.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Token embedding
      +
Position information
      ↓
Position-aware representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the sequence is ready to enter the Transformer blocks.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Self-Attention
&lt;/h2&gt;

&lt;p&gt;Now we get to the part that made Transformers such a big deal.&lt;/p&gt;

&lt;p&gt;Consider:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The animal didn't cross the road because it was tired."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;When the model processes &lt;strong&gt;"it"&lt;/strong&gt;, information about &lt;strong&gt;"animal"&lt;/strong&gt; may be useful.&lt;/p&gt;

&lt;p&gt;The model needs a way to decide which other tokens matter to the current token.&lt;/p&gt;

&lt;p&gt;That's what &lt;strong&gt;self-attention&lt;/strong&gt; does.&lt;/p&gt;

&lt;p&gt;A useful mental model is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Each token can look at the other tokens in the sequence and determine which ones are relevant to its current representation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And this is where &lt;strong&gt;Query, Key, and Value&lt;/strong&gt; come in.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Query, Key, and Value
&lt;/h2&gt;

&lt;p&gt;The names sound more complicated than they really are.&lt;/p&gt;

&lt;p&gt;Suppose the input representations are stored in a matrix:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;X
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model uses three learned weight matrices:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;W_Q
W_K
W_V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;to calculate:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q = XW_Q
K = XW_K
V = XW_V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So Q, K, and V aren't three magical objects attached to every word.&lt;/p&gt;

&lt;p&gt;They're learned projections of the current token representations.&lt;/p&gt;

&lt;p&gt;A useful intuition is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What information am I looking for?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Key&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What information do I contain?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Value&lt;/strong&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What information should I provide if I'm relevant?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That gives us a way to compare a token with the rest of the sequence.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. Attention Scores
&lt;/h2&gt;

&lt;p&gt;Now we need to measure how strongly tokens should interact.&lt;/p&gt;

&lt;p&gt;This starts with:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdckggapl78thlq5ryryv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fdckggapl78thlq5ryryv.png" alt="QKᵀ" width="38" height="19"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The dot product between a Query and a Key gives us a compatibility score.&lt;/p&gt;

&lt;p&gt;A larger score means the two representations are more aligned.&lt;/p&gt;

&lt;p&gt;A smaller score means they are less aligned.&lt;/p&gt;

&lt;p&gt;You can think of it conceptually as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Current token
     ↓
   Query
     ↓
compare with
     ↓
Keys from other tokens
     ↓
attention scores
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suppose a token produces scores like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The      → 0.2
animal   → 2.4
road     → 0.7
tired    → 1.1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At this stage, these are just raw scores.&lt;/p&gt;

&lt;p&gt;We still need to turn them into useful weights.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Scaling Before Softmax
&lt;/h2&gt;

&lt;p&gt;The full scaled dot-product attention equation is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbd8y4rft887vye9r3wcr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbd8y4rft887vye9r3wcr.png" alt="Attention Equation" width="331" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That division by:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnao9trwqlpu9hw6hkhue.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fnao9trwqlpu9hw6hkhue.png" alt="Square Root Of d_k" width="33" height="22"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;isn't there for decoration.&lt;/p&gt;

&lt;p&gt;As the dimensionality of the vectors grows, the dot products can also grow in magnitude.&lt;/p&gt;

&lt;p&gt;Very large values can make Softmax extremely sharp, which can make optimization difficult.&lt;/p&gt;

&lt;p&gt;Scaling keeps the scores in a more useful numerical range before Softmax is applied.&lt;/p&gt;

&lt;p&gt;So the pipeline is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;QKᵀ
 ↓
Scale
 ↓
Softmax
 ↓
Attention weights
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each step exists for a reason.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. Softmax Turns Scores Into Weights
&lt;/h2&gt;

&lt;p&gt;Softmax converts the attention scores into a normalized distribution.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The      → 0.06
animal   → 0.60
road     → 0.11
tired    → 0.23
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The values sum to approximately 1.&lt;/p&gt;

&lt;p&gt;Now we can use them as weights when combining the Value vectors.&lt;/p&gt;

&lt;p&gt;So the model is effectively giving different amounts of influence to different tokens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The      → small influence
animal   → large influence
road     → small influence
tired    → moderate influence
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a useful intuition, although we shouldn't take it too literally as the model "thinking" about words.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. The Attention Output
&lt;/h2&gt;

&lt;p&gt;Once we have the attention weights, we use them to calculate a weighted combination of the Value vectors.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Attention weights
        ×
Value vectors
        ↓
New representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;"animal"&lt;/code&gt; has a large attention weight, its Value contributes more to the resulting representation.&lt;/p&gt;

&lt;p&gt;The result is a new representation that contains information gathered from the surrounding tokens.&lt;/p&gt;

&lt;p&gt;That is the important idea behind self-attention:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A token can build a new representation using information from other tokens.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  10. Multi-Head Attention
&lt;/h2&gt;

&lt;p&gt;One attention mechanism gives the model one learned way to look at relationships.&lt;/p&gt;

&lt;p&gt;Transformers use &lt;strong&gt;Multi-Head Attention&lt;/strong&gt;, which runs several attention mechanisms in parallel.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 Input
                   │
       ┌───────────┼───────────┐
       ↓           ↓           ↓
     Head 1      Head 2      Head 3   ...
       ↓           ↓           ↓
       └───────────┼───────────┘
                   ↓
              Concatenate
                   ↓
               Projection
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each head has its own learned projections.&lt;/p&gt;

&lt;p&gt;We don't manually tell one head:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"You are responsible for grammar."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and another:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"You are responsible for pronouns."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The model learns useful patterns during training.&lt;/p&gt;

&lt;p&gt;Different heads can capture different relationships in the sequence.&lt;/p&gt;

&lt;p&gt;Afterward, the outputs are concatenated and passed through a learned &lt;strong&gt;output projection&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. What Does Projection Mean?
&lt;/h2&gt;

&lt;p&gt;You'll see the word &lt;strong&gt;projection&lt;/strong&gt; constantly in Transformer implementations.&lt;/p&gt;

&lt;p&gt;In this context, it usually means applying a learned linear transformation.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; X
 ↓
W_Q
 ↓
 Q
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;is a projection.&lt;/p&gt;

&lt;p&gt;Likewise, after multiple attention heads:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Head outputs
      ↓
Concatenate
      ↓
Output projection
      ↓
Updated representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And later:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hidden representation
      ↓
Vocabulary projection
      ↓
Logits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So "projection" sounds more exotic than it really is.&lt;/p&gt;

&lt;p&gt;A lot of Transformer computation is ultimately learned matrix multiplication.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. Residual Connections
&lt;/h2&gt;

&lt;p&gt;Attention produces a transformed representation.&lt;/p&gt;

&lt;p&gt;But the Transformer doesn't simply throw away the original input.&lt;/p&gt;

&lt;p&gt;It uses &lt;strong&gt;residual connections&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Mathematically:&lt;/p&gt;

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

&lt;p&gt;The original representation is added back to the transformed representation.&lt;/p&gt;

&lt;p&gt;Why?&lt;/p&gt;

&lt;p&gt;Because Transformers can contain many layers.&lt;/p&gt;

&lt;p&gt;Residual connections give information and gradients a shorter path through the network, which makes deep networks much easier to optimize.&lt;/p&gt;

&lt;p&gt;A useful intuition is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Keep what we already have, then add what this layer learned.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  13. Layer Normalization and Add &amp;amp; Norm
&lt;/h2&gt;

&lt;p&gt;You'll often see Transformer diagrams containing:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Add &amp;amp; Norm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is shorthand for a residual addition together with &lt;strong&gt;Layer Normalization&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A simplified flow is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  │
  ├──→ Attention ──┐
  │                ↓
  └──────────────→ Add
                    ↓
                   Norm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Layer Normalization helps keep the numerical activations in a more stable range as the representation passes through many transformations.&lt;/p&gt;

&lt;h3&gt;
  
  
  Pre-LN vs Post-LN
&lt;/h3&gt;

&lt;p&gt;The exact placement of LayerNorm can differ between Transformer architectures. Two common arrangements are Post-LN and Pre-LN.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Post-LN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Post-LN, the sublayer runs first, the residual connection is added, and LayerNorm is applied afterward:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x → Attention → Add → LayerNorm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or more explicitly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x + Attention(x)
        ↓
    LayerNorm
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Pre-LN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In Pre-LN, LayerNorm is applied before the sublayer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x → LayerNorm → Attention → Add
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;x
↓
LayerNorm
↓
Attention
↓
+ x
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same ordering applies to the FFN (Feed-Forward Network) sublayer as well.&lt;/p&gt;

&lt;p&gt;The distinction matters because the placement of normalization affects how easily the Transformer can be optimized. Pre-LN is common in many modern Transformer architectures because it tends to make optimization easier, especially for deeper models.&lt;/p&gt;

&lt;p&gt;So when you see:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Attention → Add → Norm&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;versus:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Norm → Attention → Add&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;you're not looking at two completely different ideas.&lt;br&gt;
They're simply two different ways of arranging the same basic components.&lt;/p&gt;

&lt;p&gt;The important part is understanding the roles:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Residual connection&lt;/strong&gt; → preserve a direct path through the network.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer normalization&lt;/strong&gt; → stabilize the representations.&lt;/p&gt;


&lt;h2&gt;
  
  
  14. The Feed-Forward Network
&lt;/h2&gt;

&lt;p&gt;Attention isn't the entire Transformer block.&lt;/p&gt;

&lt;p&gt;After attention, the representation goes through a &lt;strong&gt;Feed-Forward Network (FFN)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A simplified version looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Representation
      ↓
Linear transformation
      ↓
Non-linear activation
      ↓
Linear transformation
      ↓
New representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mathematically, something like:&lt;/p&gt;

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

&lt;p&gt;A useful distinction is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt; lets tokens exchange information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FFN&lt;/strong&gt; transforms each token's representation using learned nonlinear transformations.&lt;/p&gt;

&lt;p&gt;So conceptually:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Attention asks, "What information from elsewhere matters?"&lt;/p&gt;

&lt;p&gt;FFN asks, "Given that information, how should this representation change?"&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  15. One Transformer Block
&lt;/h2&gt;

&lt;p&gt;Now we can finally put the pieces together.&lt;/p&gt;

&lt;p&gt;A simplified Transformer block looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Self-Attention
  ↓
Residual + Norm
  ↓
FFN
  ↓
Residual + Norm
  ↓
Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact ordering varies between implementations, but the major components remain recognizable.&lt;/p&gt;

&lt;p&gt;And one block isn't enough.&lt;/p&gt;




&lt;h2&gt;
  
  
  16. Stacking Transformer Blocks
&lt;/h2&gt;

&lt;p&gt;A Transformer stacks many blocks:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Transformer Block 1
  ↓
Transformer Block 2
  ↓
Transformer Block 3
  ↓
...
  ↓
Transformer Block N
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The representation is repeatedly transformed.&lt;/p&gt;

&lt;p&gt;It's tempting to say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"The first layer learns grammar, the next layer learns facts, and the next layer learns reasoning."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's too simplistic.&lt;/p&gt;

&lt;p&gt;The model's learned information is distributed across many layers and parameters.&lt;/p&gt;

&lt;p&gt;A better way to think about it is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Each layer repeatedly transforms the representations, allowing increasingly useful and contextual patterns to emerge.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  17. The Encoder
&lt;/h2&gt;

&lt;p&gt;Now we can look at the Encoder itself.&lt;/p&gt;

&lt;p&gt;In the original Encoder–Decoder Transformer, the Encoder is a stack of Transformer blocks using &lt;strong&gt;self-attention without a causal restriction&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If the input is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"The cat is sitting on the mat."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the Encoder can allow every input token to attend to the other input tokens.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"The" ↔ "cat" ↔ "is" ↔ "sitting" ↔ ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is often described as &lt;strong&gt;bidirectional self-attention&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The Encoder can see the complete input because its job isn't to generate the output token by token.&lt;/p&gt;

&lt;p&gt;Its job is to build rich contextual representations of the input.&lt;/p&gt;

&lt;p&gt;So the Encoder is roughly:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input tokens
     ↓
Embeddings + positional information
     ↓
Transformer blocks
     ↓
Contextual representations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  18. The Decoder
&lt;/h2&gt;

&lt;p&gt;The Decoder has a different problem.&lt;/p&gt;

&lt;p&gt;It is responsible for generating the output sequence.&lt;/p&gt;

&lt;p&gt;And generation is autoregressive.&lt;/p&gt;

&lt;p&gt;That means the Decoder can't simply look at everything in the target sequence, because future tokens don't exist yet during generation.&lt;/p&gt;

&lt;p&gt;So the Decoder uses &lt;strong&gt;masked self-attention&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Suppose we're generating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;The cat sat on the mat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When predicting &lt;code&gt;"mat"&lt;/code&gt;, the model must not be allowed to use &lt;code&gt;"mat"&lt;/code&gt; itself or anything after it.&lt;/p&gt;

&lt;p&gt;The attention pattern is therefore causal:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;      T1  T2  T3  T4
T1    ✓   ✗   ✗   ✗
T2    ✓   ✓   ✗   ✗
T3    ✓   ✓   ✓   ✗
T4    ✓   ✓   ✓   ✓
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each token can attend to itself and previous tokens, but not future tokens.&lt;/p&gt;

&lt;p&gt;That's why this is called &lt;strong&gt;causal masking&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  19. The Decoder Has Two Different Attention Mechanisms
&lt;/h2&gt;

&lt;p&gt;This is the part that makes the Encoder–Decoder architecture much easier to understand.&lt;/p&gt;

&lt;p&gt;The Decoder needs to use:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Its own previously generated tokens.&lt;/li&gt;
&lt;li&gt;The information produced by the Encoder.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The first is handled by:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Masked Self-Attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The second is handled by:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So a simplified Decoder block looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Previous output tokens
          ↓
Masked Self-Attention
          ↓
Cross-Attention ← Encoder output
          ↓
FFN
          ↓
Output representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These two attention mechanisms have different jobs.&lt;/p&gt;




&lt;h2&gt;
  
  
  20. Self-Attention vs Cross-Attention
&lt;/h2&gt;

&lt;p&gt;For &lt;strong&gt;self-attention&lt;/strong&gt;, Q, K, and V come from the same sequence.&lt;/p&gt;

&lt;p&gt;In Encoder self-attention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q ← Encoder representations
K ← Encoder representations
V ← Encoder representations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In Decoder self-attention:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q ← Decoder representations
K ← Decoder representations
V ← Decoder representations
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Decoder's self-attention is masked, so it can only use previous positions.&lt;/p&gt;

&lt;p&gt;Cross-attention is different:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Q ← Decoder representation

K ← Encoder output
V ← Encoder output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means the Decoder is effectively asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Given what I have generated so far, which parts of the encoded input should influence my next prediction?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is the bridge between the Encoder and Decoder.&lt;/p&gt;




&lt;h2&gt;
  
  
  21. Translation Makes the Difference Obvious
&lt;/h2&gt;

&lt;p&gt;Take:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I love programming."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and translate it into French.&lt;/p&gt;

&lt;p&gt;The Encoder reads the whole English sentence:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"I"   "love"   "programming"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and produces contextual representations.&lt;/p&gt;

&lt;p&gt;The Decoder then starts with a special beginning-of-sequence token and begins generating:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;START&amp;gt;
   ↓
J'aime
   ↓
programmer
   ↓
&amp;lt;END&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;At every step, the Decoder can use two sources of information.&lt;/p&gt;

&lt;p&gt;Its previously generated tokens:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;masked self-attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and the original English input:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;cross-attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So while generating &lt;code&gt;"programmer"&lt;/code&gt;, the Decoder isn't working from the word &lt;code&gt;"programmer"&lt;/code&gt; out of nowhere.&lt;/p&gt;

&lt;p&gt;It can use the Encoder's representation of the original input.&lt;/p&gt;

&lt;p&gt;That's the purpose of the Encoder–Decoder design.&lt;/p&gt;




&lt;h2&gt;
  
  
  22. Training With Teacher Forcing
&lt;/h2&gt;

&lt;p&gt;Now we need to separate training from generation.&lt;/p&gt;

&lt;p&gt;During training, we already know the correct output.&lt;/p&gt;

&lt;p&gt;Suppose the target is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"I love programming."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Decoder can be trained with the correct previous tokens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;BOS&amp;gt;          → I
&amp;lt;BOS&amp;gt; I        → love
&amp;lt;BOS&amp;gt; I love   → programming
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is called &lt;strong&gt;teacher forcing&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Instead of feeding the model its own prediction at every step during training, we give it the correct previous token and ask it to predict the next one.&lt;/p&gt;

&lt;p&gt;That makes training much more manageable.&lt;/p&gt;

&lt;p&gt;Without teacher forcing, one early incorrect prediction could become part of the next input and cause the errors to compound.&lt;/p&gt;




&lt;h2&gt;
  
  
  23. Training: Prediction, Loss, and Backpropagation
&lt;/h2&gt;

&lt;p&gt;During training, the model makes a prediction for the next token.&lt;/p&gt;

&lt;p&gt;We already know what the correct token should have been.&lt;/p&gt;

&lt;p&gt;So we compare the prediction with the target using a loss function such as &lt;strong&gt;cross-entropy&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Suppose the correct token is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Paris
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but the model predicts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Paris   → 0.20
London  → 0.30
Rome    → 0.10
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model should increase the probability of &lt;code&gt;"Paris"&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Cross-entropy gives us a way to measure how bad the prediction was.&lt;/p&gt;

&lt;p&gt;For a single target token, a simplified form is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F766n2gd8agfmo7dv9hxq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F766n2gd8agfmo7dv9hxq.png" alt="Loss Value" width="204" height="18"&gt;&lt;/a&gt;&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;P(correct) = 0.90
→ small loss

P(correct) = 0.01
→ large loss
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That loss is then used by &lt;strong&gt;backpropagation&lt;/strong&gt; to calculate gradients.&lt;/p&gt;

&lt;p&gt;The gradients tell the optimizer how the model's parameters should change.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prediction
    ↓
Loss
    ↓
Backpropagation
    ↓
Gradients
    ↓
Update parameters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This happens through the entire network.&lt;/p&gt;

&lt;p&gt;The goal is to make future predictions better.&lt;/p&gt;




&lt;h2&gt;
  
  
  24. Training vs Inference
&lt;/h2&gt;

&lt;p&gt;This distinction is worth keeping clear.&lt;/p&gt;

&lt;h3&gt;
  
  
  Training
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input + target
      ↓
Prediction
      ↓
Cross-entropy loss
      ↓
Backpropagation
      ↓
Update parameters
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The weights change.&lt;/p&gt;

&lt;h3&gt;
  
  
  Inference
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Transformer
  ↓
Logits
  ↓
Probabilities
  ↓
Choose token
  ↓
Append token
  ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The learned weights are being used.&lt;/p&gt;

&lt;p&gt;The model isn't learning new weights from your prompt during normal inference.&lt;/p&gt;

&lt;p&gt;It's using what it already learned.&lt;/p&gt;




&lt;h2&gt;
  
  
  25. From Hidden Representation to Logits
&lt;/h2&gt;

&lt;p&gt;After the Decoder processes the current context, we still don't have a word or token.&lt;/p&gt;

&lt;p&gt;We have a hidden representation.&lt;/p&gt;

&lt;p&gt;The model applies a final learned projection into the vocabulary space.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Hidden representation
        ↓
Vocabulary projection
        ↓
Logits
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the vocabulary contains 100,000 tokens, the model can produce roughly 100,000 logits for the next token.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"the"        → 8.2
"program"    → 7.4
"Python"     → 6.9
"banana"     → 0.7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are raw scores.&lt;/p&gt;

&lt;p&gt;They're not probabilities yet.&lt;/p&gt;




&lt;h2&gt;
  
  
  26. Logits Become Probabilities
&lt;/h2&gt;

&lt;p&gt;We apply Softmax:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ci0v5mlk8zyofnsm98k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F1ci0v5mlk8zyofnsm98k.png" alt="Softmax Equation" width="173" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now the scores become a probability distribution.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"the"        → 0.42
"program"    → 0.28
"Python"     → 0.19
"banana"     → 0.01
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model has now produced a probability distribution over possible next tokens.&lt;/p&gt;

&lt;p&gt;Then the decoding process chooses one.&lt;/p&gt;

&lt;p&gt;And this takes us directly to autoregressive generation.&lt;/p&gt;




&lt;h2&gt;
  
  
  27. Autoregressive Generation
&lt;/h2&gt;

&lt;p&gt;Suppose GPT receives:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Python is"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It predicts a probability distribution for the next token.&lt;/p&gt;

&lt;p&gt;Maybe the selected token is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;" a"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the context becomes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Python is a"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The model runs again.&lt;/p&gt;

&lt;p&gt;Maybe it predicts:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;" programming"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Python is a programming"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And so on.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Current context
      ↓
Transformer
      ↓
Logits
      ↓
Probabilities
      ↓
Choose next token
      ↓
Append token
      ↓
New context
      ↓
Transformer again
      ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is &lt;strong&gt;autoregressive generation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The model doesn't generate the entire paragraph in one step.&lt;/p&gt;

&lt;p&gt;It generates one token, adds it to the context, and predicts the next token.&lt;/p&gt;




&lt;h2&gt;
  
  
  28. Temperature and Sampling
&lt;/h2&gt;

&lt;p&gt;One final part of the generation process is &lt;strong&gt;sampling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Temperature is not part of the Transformer architecture itself.&lt;/p&gt;

&lt;p&gt;It is part of the decoding process.&lt;/p&gt;

&lt;p&gt;Suppose the model produces logits:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;A → 8.0
B → 7.0
C → 5.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Changing the temperature changes how concentrated the resulting distribution becomes.&lt;/p&gt;

&lt;p&gt;Lower temperature generally produces a sharper, more predictable distribution.&lt;/p&gt;

&lt;p&gt;Higher temperature generally produces a flatter distribution and allows more variation.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Low temperature
      ↓
Sharper distribution
      ↓
More predictable choices


High temperature
      ↓
Flatter distribution
      ↓
More variation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So temperature doesn't teach the model anything.&lt;/p&gt;

&lt;p&gt;It changes how we sample from the model's predictions.&lt;/p&gt;




&lt;h2&gt;
  
  
  29. Where GPT Fits
&lt;/h2&gt;

&lt;p&gt;Now the original question becomes much easier to answer.&lt;/p&gt;

&lt;p&gt;The original Transformer was:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Encoder
   ↓
Decoder
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;GPT-style models are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Decoder-only
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That means GPT does &lt;strong&gt;not&lt;/strong&gt; have a separate Encoder stack.&lt;/p&gt;

&lt;p&gt;It also does not need the Encoder-to-Decoder cross-attention used in the classic Encoder–Decoder Transformer.&lt;/p&gt;

&lt;p&gt;Instead, the prompt goes directly through a stack of decoder-style Transformer blocks using causal self-attention.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt
  ↓
Tokenization
  ↓
Embeddings + positional information
  ↓
Causal Self-Attention
  ↓
FFN
  ↓
Transformer block
  ↓
Transformer block
  ↓
...
  ↓
Logits
  ↓
Probabilities
  ↓
Next token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then that token is appended to the sequence and the process repeats.&lt;/p&gt;




&lt;h2&gt;
  
  
  30. GPT vs the Original Encoder–Decoder Transformer
&lt;/h2&gt;

&lt;p&gt;The difference can be summarized very simply.&lt;/p&gt;

&lt;h3&gt;
  
  
  Original Transformer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Encoder
  ↓
Encoder representations
  ↓
Decoder
  ↓
Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The Decoder uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;masked self-attention&lt;/li&gt;
&lt;li&gt;cross-attention to the Encoder&lt;/li&gt;
&lt;li&gt;FFN&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  GPT-style Transformer
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt
  ↓
Decoder-style blocks
  ↓
Logits
  ↓
Next token
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It uses:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;causal self-attention&lt;/li&gt;
&lt;li&gt;FFN&lt;/li&gt;
&lt;li&gt;residual connections&lt;/li&gt;
&lt;li&gt;normalization&lt;/li&gt;
&lt;li&gt;stacked Transformer blocks&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;but there is no separate Encoder and no Encoder-to-Decoder cross-attention.&lt;/p&gt;

&lt;p&gt;That's why GPT is called &lt;strong&gt;decoder-only&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  31. The Three Transformer Configurations
&lt;/h2&gt;

&lt;p&gt;At this point, the three major configurations are easier to remember.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encoder-only
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Encoder
  ↓
Representation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mental model:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understand the input.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;BERT is a well-known example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Encoder–Decoder
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Encoder
  ↓
Representation
  ↓
Decoder
  ↓
Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mental model:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transform one sequence into another.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;T5 is a well-known example.&lt;/p&gt;

&lt;h3&gt;
  
  
  Decoder-only
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt
  ↓
Decoder-style blocks
  ↓
Next token
  ↓
Next token
  ↓
Next token
  ↓
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Mental model:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Continue the sequence.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;GPT-style models belong here.&lt;/p&gt;

&lt;p&gt;These are not the only possible ways to use Transformers, but they're three important architectural patterns to recognize.&lt;/p&gt;




&lt;h2&gt;
  
  
  32. The Complete Picture
&lt;/h2&gt;

&lt;p&gt;At this point, the pieces fit together into one pipeline.&lt;/p&gt;

&lt;p&gt;For a classic Encoder–Decoder Transformer:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text
 ↓
Tokens
 ↓
Embeddings
 ↓
Positional Information
 ↓
Encoder
 ├── Self-Attention
 ├── Add + Norm
 ├── FFN
 └── repeated × N
 ↓
Encoded representation
 ↓
Decoder
 ├── Masked Self-Attention
 ├── Cross-Attention
 ├── FFN
 └── repeated × N
 ↓
Projection
 ↓
Logits
 ↓
Softmax
 ↓
Probabilities
 ↓
Next token
 ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And for GPT-style decoder-only models:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Text
 ↓
Tokens
 ↓
Embeddings
 ↓
Positional Information
 ↓
Causal Self-Attention
 ↓
FFN
 ↓
Transformer Block × N
 ↓
Projection
 ↓
Logits
 ↓
Softmax / Decoding
 ↓
Next token
 ↓
Append token
 ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The architecture becomes much easier to reason about once each component has a specific job.&lt;/p&gt;




&lt;h2&gt;
  
  
  33. The Part That Matters When Reading Transformer Diagrams
&lt;/h2&gt;

&lt;p&gt;There are a lot of names to remember:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q, K, V&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Softmax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Masking&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Head Attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Projection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Residual Connections&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Layer Normalization&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FFN&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Attention&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logits&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Entropy&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Teacher Forcing&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Autoregressive Generation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first, they look like unrelated pieces of terminology.&lt;/p&gt;

&lt;p&gt;They aren't.&lt;/p&gt;

&lt;p&gt;They form a pipeline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tokenization&lt;/strong&gt; gives us discrete pieces of text.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Embeddings&lt;/strong&gt; turn those pieces into vectors.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Positional information&lt;/strong&gt; tells the model where those tokens occur.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q, K, and V&lt;/strong&gt; create learned views of those representations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Attention&lt;/strong&gt; allows tokens to exchange information.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Masking&lt;/strong&gt; controls which tokens are allowed to interact during generation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Multi-Head Attention&lt;/strong&gt; gives the model multiple learned ways to inspect relationships.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Residual Connections and Layer Normalization&lt;/strong&gt; help those transformations work across deep networks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;FFNs&lt;/strong&gt; further transform the resulting representations.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Encoder layers&lt;/strong&gt; build contextual representations of an input.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Decoder layers&lt;/strong&gt; use previous output tokens to generate the next ones.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Attention&lt;/strong&gt; lets an Encoder–Decoder model connect those two sides.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Projection&lt;/strong&gt; maps the hidden representation into the vocabulary space.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Logits&lt;/strong&gt; give a score to every possible next token.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Softmax&lt;/strong&gt; converts those scores into probabilities.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Cross-Entropy&lt;/strong&gt; measures how well the model predicted the correct token during training.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Backpropagation&lt;/strong&gt; computes how the parameters should change.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Teacher Forcing&lt;/strong&gt; makes supervised sequence training practical.&lt;/p&gt;

&lt;p&gt;And finally:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Autoregressive generation&lt;/strong&gt; turns one predicted token into the context for the next prediction.&lt;/p&gt;

&lt;p&gt;That's the Transformer.&lt;/p&gt;

&lt;p&gt;Not one mysterious box.&lt;/p&gt;

&lt;p&gt;Not a collection of AI buzzwords.&lt;/p&gt;

&lt;p&gt;A sequence of numerical transformations where each component has a specific role.&lt;/p&gt;

&lt;p&gt;And once that structure is clear, GPT stops looking like something completely different from the original Transformer.&lt;/p&gt;

&lt;p&gt;It becomes what it actually is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;a decoder-only Transformer architecture built around causal self-attention and autoregressive next-token prediction.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>gpt3</category>
      <category>llm</category>
      <category>deeplearning</category>
    </item>
    <item>
      <title>LLMs Finally Made Sense to Me: A Software Engineer’s Mental Model</title>
      <dc:creator>Adham Hewala</dc:creator>
      <pubDate>Sat, 15 Aug 2026 19:49:51 +0000</pubDate>
      <link>https://dev.to/adhamhe6/llms-finally-made-sense-to-me-a-software-engineers-mental-model-ala</link>
      <guid>https://dev.to/adhamhe6/llms-finally-made-sense-to-me-a-software-engineers-mental-model-ala</guid>
      <description>&lt;p&gt;A few weeks ago, I started seriously learning how Large Language Models actually work.&lt;/p&gt;

&lt;p&gt;Not how to &lt;em&gt;use&lt;/em&gt; ChatGPT.&lt;/p&gt;

&lt;p&gt;Not how to write better prompts.&lt;/p&gt;

&lt;p&gt;Not how to call an LLM API from Python.&lt;/p&gt;

&lt;p&gt;I mean what actually happens &lt;strong&gt;after I press Enter&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;At first, it felt like opening a completely different field of computer science.&lt;/p&gt;

&lt;p&gt;I kept running into terms like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;tokens, embeddings, attention, transformers, logits, softmax, temperature, context windows, fine-tuning, RLHF, RAG, vector databases, tool calling, agents, mixture of experts...&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I understood each term individually.&lt;/p&gt;

&lt;p&gt;But I didn't understand how they connected.&lt;/p&gt;

&lt;p&gt;And I think that's the hardest part of getting into AI today.&lt;/p&gt;

&lt;p&gt;There is no shortage of explanations for individual concepts.&lt;/p&gt;

&lt;p&gt;What's missing, at least for me, was a &lt;strong&gt;mental model that connected everything together&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So I decided to build one.&lt;/p&gt;

&lt;p&gt;This article is my attempt to explain it from the perspective of a software engineer who is learning LLMs, without starting with complicated research papers or assuming you're already an ML expert.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why should software engineers understand this?
&lt;/h2&gt;

&lt;p&gt;There's a practical reason I wanted to learn this.&lt;/p&gt;

&lt;p&gt;Look at software engineering job descriptions today and you'll increasingly see things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;LLM integration&lt;/li&gt;
&lt;li&gt;RAG&lt;/li&gt;
&lt;li&gt;Embeddings&lt;/li&gt;
&lt;li&gt;Vector databases&lt;/li&gt;
&lt;li&gt;AI agents&lt;/li&gt;
&lt;li&gt;Prompt engineering&lt;/li&gt;
&lt;li&gt;Generative AI&lt;/li&gt;
&lt;li&gt;Tool calling&lt;/li&gt;
&lt;li&gt;AI/ML APIs&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI is becoming another layer of the software stack.&lt;/p&gt;

&lt;p&gt;And I don't think every software engineer needs to become an ML researcher.&lt;/p&gt;

&lt;p&gt;But I do think we should understand &lt;strong&gt;what we're actually building with&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If I'm integrating an LLM into a backend service, I don't necessarily need to know every detail of the model's training infrastructure.&lt;/p&gt;

&lt;p&gt;But I should understand enough to answer questions like:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;What exactly is a token?&lt;/p&gt;

&lt;p&gt;Why does the model have a context window?&lt;/p&gt;

&lt;p&gt;What is an embedding?&lt;/p&gt;

&lt;p&gt;Why does attention matter?&lt;/p&gt;

&lt;p&gt;Why does the model sometimes produce different answers?&lt;/p&gt;

&lt;p&gt;Why would I need RAG?&lt;/p&gt;

&lt;p&gt;What actually happens when an LLM calls a tool?&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once those questions start making sense, the rest of the ecosystem becomes much easier to navigate.&lt;/p&gt;




&lt;h2&gt;
  
  
  Let's start with the simplest possible question
&lt;/h2&gt;

&lt;h2&gt;
  
  
  What happens when I send text to an LLM?
&lt;/h2&gt;

&lt;p&gt;Suppose I send:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;"Explain Docker to me."&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a human, I see a sentence.&lt;/p&gt;

&lt;p&gt;The model doesn't.&lt;/p&gt;

&lt;p&gt;The first thing that happens is &lt;strong&gt;tokenization&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Text → Tokens
&lt;/h2&gt;

&lt;p&gt;Neural networks don't operate directly on strings like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Explain Docker to me."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;They operate on numerical representations.&lt;/p&gt;

&lt;p&gt;So the text is broken into &lt;strong&gt;tokens&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;A token isn't necessarily a word.&lt;/p&gt;

&lt;p&gt;Depending on the tokenizer, it could be:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a whole word&lt;/li&gt;
&lt;li&gt;part of a word&lt;/li&gt;
&lt;li&gt;punctuation&lt;/li&gt;
&lt;li&gt;whitespace&lt;/li&gt;
&lt;li&gt;or another small piece of text&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, conceptually:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"unbelievable"
        ↓
["un", "believ", "able"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact split depends on the tokenizer.&lt;/p&gt;

&lt;p&gt;Each token is then mapped to an integer ID:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["un", "believ", "able"]
        ↓
[1254, 8271, 394]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we have something a neural network can process.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why do we tokenize this way?
&lt;/h3&gt;

&lt;p&gt;Because language is messy.&lt;/p&gt;

&lt;p&gt;If we created one token for every possible word, we'd need an enormous vocabulary.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;run
runs
running
runner
runners
rerunning
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A subword tokenizer can reuse pieces of words instead of storing every possible variation as a completely independent token.&lt;/p&gt;

&lt;p&gt;One famous approach is &lt;strong&gt;Byte Pair Encoding (BPE)&lt;/strong&gt;, which builds a vocabulary by repeatedly merging frequently occurring sequences.&lt;/p&gt;

&lt;p&gt;So the first mental model is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;LLMs don't read text directly. They process token representations.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  2. Context Windows: The Model Can't See Everything
&lt;/h2&gt;

&lt;p&gt;Now imagine sending a huge document to an LLM.&lt;/p&gt;

&lt;p&gt;There is a limit to how much information can participate in a single model invocation.&lt;/p&gt;

&lt;p&gt;That's the &lt;strong&gt;context window&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;You might see models advertised with context sizes such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8K
32K
128K
1M+
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These refer to the amount of tokenized context the model can handle.&lt;/p&gt;

&lt;p&gt;Think of it as the model's &lt;strong&gt;working context for a particular inference request&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;This is important because it explains why applications often need techniques such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;chunking&lt;/li&gt;
&lt;li&gt;summarization&lt;/li&gt;
&lt;li&gt;retrieval&lt;/li&gt;
&lt;li&gt;conversation memory&lt;/li&gt;
&lt;li&gt;RAG&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you understand context windows, a lot of modern LLM application architecture starts making more sense.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Token IDs → Vectors
&lt;/h2&gt;

&lt;p&gt;We now have something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[1254, 8271, 394]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But these integers are just IDs.&lt;/p&gt;

&lt;p&gt;There's nothing inherently meaningful about the number &lt;code&gt;8271&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;So we need another transformation.&lt;/p&gt;

&lt;p&gt;Each token ID is mapped to a vector of floating-point numbers.&lt;/p&gt;

&lt;p&gt;Something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;8271
 ↓
[0.12, -0.43, 0.87, 0.04, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is an &lt;strong&gt;embedding&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And this is one of the concepts that completely changed how I think about machine learning.&lt;/p&gt;

&lt;p&gt;Instead of representing information as a label, we represent it as a position in a high-dimensional mathematical space.&lt;/p&gt;

&lt;p&gt;The model can learn useful relationships between these representations.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Embeddings Are More Than "Meaning = A Vector"
&lt;/h2&gt;

&lt;p&gt;You'll often hear:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Embeddings represent the meaning of words."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's a useful beginner intuition, but it's an oversimplification.&lt;/p&gt;

&lt;p&gt;Modern neural representations are distributed and contextual.&lt;/p&gt;

&lt;p&gt;There isn't necessarily one dimension that means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"This number represents happiness."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, meaning and useful linguistic patterns are distributed across many dimensions.&lt;/p&gt;

&lt;p&gt;The model learns these representations because they're useful for predicting and processing language.&lt;/p&gt;

&lt;p&gt;And this idea existed long before today's LLMs.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Word2Vec: An Early Glimpse of What Was Possible
&lt;/h2&gt;

&lt;p&gt;One of the famous milestones in NLP was &lt;strong&gt;Word2Vec&lt;/strong&gt;, introduced in 2013.&lt;/p&gt;

&lt;p&gt;It demonstrated that words appearing in similar contexts could develop similar vector representations.&lt;/p&gt;

&lt;p&gt;One famous example is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;King - Man + Woman ≈ Queen
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The important part isn't that this equation is some universal law of language.&lt;/p&gt;

&lt;p&gt;The important part is what it demonstrated:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Relationships between linguistic concepts can emerge in vector space.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That idea became incredibly important for modern NLP.&lt;/p&gt;




&lt;h2&gt;
  
  
  6. So How Does the Model Understand Context?
&lt;/h2&gt;

&lt;p&gt;This is where we reach the Transformer.&lt;/p&gt;

&lt;p&gt;In 2017, researchers published the paper:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Attention Is All You Need&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It introduced the Transformer architecture.&lt;/p&gt;

&lt;p&gt;Transformers eventually became the foundation of modern LLMs.&lt;/p&gt;

&lt;p&gt;And the most famous part of the Transformer is:&lt;/p&gt;

&lt;h3&gt;
  
  
  Attention
&lt;/h3&gt;

&lt;p&gt;Consider these two sentences:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I went to the bank to deposit money.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;and:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;I sat beside the bank of the river.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The word &lt;strong&gt;bank&lt;/strong&gt; is the same.&lt;/p&gt;

&lt;p&gt;But its meaning depends heavily on the surrounding words.&lt;/p&gt;

&lt;p&gt;This is where attention becomes important.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Attention: Which Tokens Matter Right Now?
&lt;/h2&gt;

&lt;p&gt;A simplified way to think about attention is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Each token can look at other tokens and determine which ones are relevant to its current representation.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"The animal didn't cross the road because it was tired."
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To understand "it", the model needs to consider other parts of the sentence.&lt;/p&gt;

&lt;p&gt;Attention provides a mechanism for modeling those relationships.&lt;/p&gt;

&lt;p&gt;Under the hood, this involves:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query (Q)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key (K)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value (V)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;and a calculation commonly expressed as:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc9pkc0dwzsfjjz2h7rpu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fc9pkc0dwzsfjjz2h7rpu.png" alt="The scaled dot-product attention formula: Attention of Q, K, and V equals the softmax of the product of Q and K transpose divided by the square root of d_k, multiplied by V." width="323" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You don't need to memorize this equation to understand the big picture.&lt;/p&gt;

&lt;p&gt;The important idea is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Attention allows the model to dynamically determine which parts of the context should influence each token's representation.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And that's a huge part of why Transformers work so well with language.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. A Transformer Is More Than Attention
&lt;/h2&gt;

&lt;p&gt;A Transformer block isn't just attention.&lt;/p&gt;

&lt;p&gt;A simplified view looks something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input
  ↓
Self-Attention
  ↓
Feed-Forward Network
  ↓
Output
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real Transformer architectures also include things like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;residual connections&lt;/li&gt;
&lt;li&gt;normalization&lt;/li&gt;
&lt;li&gt;positional information&lt;/li&gt;
&lt;li&gt;masking, depending on the architecture&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And an LLM doesn't have just one Transformer block.&lt;/p&gt;

&lt;p&gt;It stacks many of them.&lt;/p&gt;

&lt;p&gt;The output of one layer becomes the input to the next.&lt;/p&gt;

&lt;p&gt;Layer after layer, the model transforms the representation.&lt;/p&gt;




&lt;h2&gt;
  
  
  9. Then Comes the Part That Surprised Me
&lt;/h2&gt;

&lt;p&gt;After all of that processing, the model doesn't output:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hello, here is your answer."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Instead, it produces &lt;strong&gt;scores for possible next tokens&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;These raw scores are called &lt;strong&gt;logits&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Imagine the model has a vocabulary containing thousands of possible tokens.&lt;/p&gt;

&lt;p&gt;For the next token, it might produce something conceptually like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"the"       → 8.2
"container" → 7.4
"Docker"    → 6.9
"database"  → 4.1
"banana"    → 0.7
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Those aren't probabilities yet.&lt;/p&gt;

&lt;p&gt;They're logits.&lt;/p&gt;




&lt;h2&gt;
  
  
  10. Logits → Probabilities
&lt;/h2&gt;

&lt;p&gt;To turn those scores into a probability distribution, we can apply &lt;strong&gt;Softmax&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknwki85177tiqwsiyu3p.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fknwki85177tiqwsiyu3p.png" alt="The softmax formula for a component x sub i: Softmax of x sub i equals e to the power of x sub i divided by the sum over j of e to the power of x sub j." width="165" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we might have:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"the"       → 0.42
"container" → 0.28
"Docker"    → 0.19
"database"  → 0.08
"banana"    → 0.01
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The exact values are illustrative, but the idea is important.&lt;/p&gt;

&lt;p&gt;The model has effectively produced a probability distribution over possible next tokens.&lt;/p&gt;

&lt;p&gt;And now comes something even more important:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The model chooses a token.&lt;/strong&gt;&lt;/p&gt;




&lt;h2&gt;
  
  
  11. The Model Generates One Token at a Time
&lt;/h2&gt;

&lt;p&gt;This was probably the most important thing for me to understand.&lt;/p&gt;

&lt;p&gt;When ChatGPT gives you a paragraph, the model isn't necessarily generating the whole paragraph in one shot.&lt;/p&gt;

&lt;p&gt;It's generating tokens sequentially.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Input:
"Explain Docker"

        ↓

"Explain Docker is"

        ↓

"Explain Docker is a"

        ↓

"Explain Docker is a platform"

        ↓

"Explain Docker is a platform for"

        ↓

...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each generated token becomes part of the context used to generate the next token.&lt;/p&gt;

&lt;p&gt;This is called &lt;strong&gt;autoregressive generation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So the basic inference loop is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Tokenize
   ↓
Represent tokens
   ↓
Transformer
   ↓
Logits
   ↓
Probabilities
   ↓
Choose next token
   ↓
Append token
   ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Over and over.&lt;/p&gt;

&lt;p&gt;Until the generation stops.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. Why Doesn't It Always Give the Same Answer?
&lt;/h2&gt;

&lt;p&gt;If the model always selected the highest-probability token, its output would be much more deterministic.&lt;/p&gt;

&lt;p&gt;Instead, generation can involve &lt;strong&gt;sampling&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Two parameters you'll often encounter are:&lt;/p&gt;

&lt;h2&gt;
  
  
  Temperature
&lt;/h2&gt;

&lt;p&gt;Temperature controls how concentrated or spread out the probability distribution becomes.&lt;/p&gt;

&lt;p&gt;Lower temperature generally means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;More predictable output.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Higher temperature generally means:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;More variation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Top-p
&lt;/h2&gt;

&lt;p&gt;Top-p, or nucleus sampling, limits sampling to a subset of tokens whose cumulative probability reaches a specified threshold.&lt;/p&gt;

&lt;p&gt;So:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Temperature changes the shape of the distribution.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Top-p limits the candidate pool.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is one reason the same prompt can produce different answers.&lt;/p&gt;




&lt;h2&gt;
  
  
  13. But Where Did the Model Learn All of This?
&lt;/h2&gt;

&lt;p&gt;This brings us to training.&lt;/p&gt;

&lt;p&gt;And there's an important distinction:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;An LLM doesn't start life as a helpful chatbot.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A simplified training lifecycle looks something like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Massive Dataset
      ↓
Pretraining
      ↓
Base Model
      ↓
Supervised Fine-Tuning
      ↓
Preference / Alignment Training
      ↓
Assistant
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's unpack that.&lt;/p&gt;




&lt;h2&gt;
  
  
  14. Pretraining: Learn to Predict What Comes Next
&lt;/h2&gt;

&lt;p&gt;The basic objective during language-model pretraining is surprisingly simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Predict the next token.&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"The capital of France is"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the model should assign high probability to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"Paris"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Do this over an enormous amount of data, with enormous models and compute, and something interesting happens.&lt;/p&gt;

&lt;p&gt;The model doesn't just memorize a list of sentences.&lt;/p&gt;

&lt;p&gt;It learns statistical structures and representations that support language prediction.&lt;/p&gt;

&lt;p&gt;It can learn patterns involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;syntax&lt;/li&gt;
&lt;li&gt;programming&lt;/li&gt;
&lt;li&gt;facts&lt;/li&gt;
&lt;li&gt;concepts&lt;/li&gt;
&lt;li&gt;styles&lt;/li&gt;
&lt;li&gt;relationships&lt;/li&gt;
&lt;li&gt;reasoning-like patterns&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is a &lt;strong&gt;base language model&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;But a base model isn't necessarily optimized to be a great assistant.&lt;/p&gt;




&lt;h2&gt;
  
  
  15. Supervised Fine-Tuning
&lt;/h2&gt;

&lt;p&gt;Now imagine giving the model examples like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User:
What is an API?

Assistant:
An API is...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and many other high-quality examples.&lt;/p&gt;

&lt;p&gt;The model can be trained to follow this conversational format.&lt;/p&gt;

&lt;p&gt;This is commonly called:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SFT — Supervised Fine-Tuning.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It helps transform the raw language model into something much closer to an assistant.&lt;/p&gt;




&lt;h2&gt;
  
  
  16. Preference Training and RLHF
&lt;/h2&gt;

&lt;p&gt;But there's another problem.&lt;/p&gt;

&lt;p&gt;Suppose the model gives three answers.&lt;/p&gt;

&lt;p&gt;One is:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;correct&lt;/li&gt;
&lt;li&gt;clear&lt;/li&gt;
&lt;li&gt;safe&lt;/li&gt;
&lt;li&gt;helpful&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Another is technically correct but confusing.&lt;/p&gt;

&lt;p&gt;The third is simply wrong.&lt;/p&gt;

&lt;p&gt;We need a way to teach the model which behaviors humans prefer.&lt;/p&gt;

&lt;p&gt;One historically important approach is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RLHF — Reinforcement Learning from Human Feedback.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Humans provide preference signals, and the training process uses those signals to encourage desirable behavior.&lt;/p&gt;

&lt;p&gt;Modern models use a broader range of techniques for alignment and preference optimization, but the central idea remains:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The model isn't only trained to predict text. It is also optimized to produce useful behavior.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  17. Now We Reach the Part Software Engineers Care About
&lt;/h2&gt;

&lt;p&gt;Understanding how the model works is useful.&lt;/p&gt;

&lt;p&gt;But the really exciting part is what happens when we put an LLM inside a software system.&lt;/p&gt;

&lt;p&gt;This is where terms like:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RAG&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Vector databases&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tool calling&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Agents&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;start appearing.&lt;/p&gt;

&lt;p&gt;And suddenly, all the concepts we've discussed begin connecting.&lt;/p&gt;




&lt;h2&gt;
  
  
  18. Embeddings + Vector Databases + RAG
&lt;/h2&gt;

&lt;p&gt;Imagine you're building an internal company assistant.&lt;/p&gt;

&lt;p&gt;You want it to answer questions about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;company policies&lt;/li&gt;
&lt;li&gt;technical documentation&lt;/li&gt;
&lt;li&gt;product manuals&lt;/li&gt;
&lt;li&gt;internal knowledge&lt;/li&gt;
&lt;li&gt;recent documents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can't simply expect the model to magically know your private documents.&lt;/p&gt;

&lt;p&gt;And retraining the entire model every time a document changes isn't practical.&lt;/p&gt;

&lt;p&gt;So we can use &lt;strong&gt;Retrieval-Augmented Generation (RAG).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A simplified pipeline:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Documents
    ↓
Chunking
    ↓
Embeddings
    ↓
Vector Database
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then when a user asks:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"What is our vacation policy?"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;the system can do:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Question
   ↓
Embedding
   ↓
Vector Search
   ↓
Relevant Documents
   ↓
LLM + Retrieved Context
   ↓
Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now the model isn't responsible for remembering everything.&lt;/p&gt;

&lt;p&gt;Your application retrieves the relevant information and gives it to the model as context.&lt;/p&gt;

&lt;p&gt;This is a perfect example of where traditional software engineering and LLMs meet.&lt;/p&gt;




&lt;h2&gt;
  
  
  19. Tool Calling: When the LLM Needs Software
&lt;/h2&gt;

&lt;p&gt;An LLM can generate text.&lt;/p&gt;

&lt;p&gt;But your application can do much more.&lt;/p&gt;

&lt;p&gt;Your backend can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;query a database&lt;/li&gt;
&lt;li&gt;call an API&lt;/li&gt;
&lt;li&gt;perform calculations&lt;/li&gt;
&lt;li&gt;search documents&lt;/li&gt;
&lt;li&gt;send an email&lt;/li&gt;
&lt;li&gt;create an order&lt;/li&gt;
&lt;li&gt;retrieve weather information&lt;/li&gt;
&lt;li&gt;interact with another service&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So why not let the model decide when one of these capabilities is needed?&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;tool calling&lt;/strong&gt; comes in.&lt;/p&gt;

&lt;p&gt;A simplified flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User
 ↓
LLM
 ↓
"I need the weather tool"
 ↓
Tool Call
 ↓
Your Backend
 ↓
Weather API
 ↓
Tool Result
 ↓
LLM
 ↓
Final Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The LLM isn't directly performing the API request.&lt;/p&gt;

&lt;p&gt;Your application executes the tool.&lt;/p&gt;

&lt;p&gt;The model receives the result and continues.&lt;/p&gt;

&lt;p&gt;This distinction is extremely important.&lt;/p&gt;

&lt;p&gt;The LLM becomes a &lt;strong&gt;reasoning and language interface around actual software capabilities&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  20. And That's Where Agents Come From
&lt;/h2&gt;

&lt;p&gt;Once you combine:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM + tools + state + an execution loop&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;you can start building systems that behave more like agents.&lt;/p&gt;

&lt;p&gt;For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Goal
 ↓
LLM decides what to do
 ↓
Call Tool A
 ↓
Observe Result
 ↓
Decide next action
 ↓
Call Tool B
 ↓
Observe Result
 ↓
Final Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is why I think it's more useful to understand the underlying pieces than to simply memorize:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Agent = AI that does things."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The interesting engineering questions are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What tools does it have?&lt;/li&gt;
&lt;li&gt;How does it select them?&lt;/li&gt;
&lt;li&gt;What state does it maintain?&lt;/li&gt;
&lt;li&gt;How do we control its actions?&lt;/li&gt;
&lt;li&gt;What happens when a tool fails?&lt;/li&gt;
&lt;li&gt;How do we prevent unwanted actions?&lt;/li&gt;
&lt;li&gt;How do we evaluate it?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now we're back in familiar software engineering territory.&lt;/p&gt;




&lt;h2&gt;
  
  
  21. Mixture of Experts
&lt;/h2&gt;

&lt;p&gt;Another term you'll encounter when exploring modern LLM architectures is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mixture of Experts (MoE).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The basic idea is that instead of having every part of a huge network process every token, the model can contain multiple expert components.&lt;/p&gt;

&lt;p&gt;A router decides which experts should process a token.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  ┌── Expert A
                  │
Token → Router ───┼── Expert B
                  │
                  └── Expert C
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Only a subset of experts may be activated for each token.&lt;/p&gt;

&lt;p&gt;This can make it possible to build models with very large total parameter counts while controlling the amount of computation used per token.&lt;/p&gt;

&lt;p&gt;Again, the important thing isn't memorizing the architecture.&lt;/p&gt;

&lt;p&gt;It's understanding &lt;strong&gt;why the technique exists&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  22. What About Models That "Think"?
&lt;/h2&gt;

&lt;p&gt;This is another area where terminology can become confusing.&lt;/p&gt;

&lt;p&gt;You may hear:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;reasoning models&lt;/li&gt;
&lt;li&gt;thinking models&lt;/li&gt;
&lt;li&gt;chain-of-thought&lt;/li&gt;
&lt;li&gt;extended thinking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The core intuition is that some tasks benefit from giving the model additional computation before producing the final answer.&lt;/p&gt;

&lt;p&gt;Because these models generate sequentially, intermediate reasoning or computation can provide additional steps for solving a difficult problem.&lt;/p&gt;

&lt;p&gt;But there's an important distinction:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;"Chain-of-thought" does not simply mean showing the user the model's private reasoning.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Modern systems may use internal reasoning processes that are not exposed verbatim.&lt;/p&gt;

&lt;p&gt;From an engineering perspective, the important idea is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Inference can involve additional computation, not just one immediate prediction.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  23. How Do We Know an LLM Is Actually Good?
&lt;/h2&gt;

&lt;p&gt;Here's where my software-engineering brain immediately kicks in.&lt;/p&gt;

&lt;p&gt;We test it.&lt;/p&gt;

&lt;p&gt;You wouldn't deploy a backend service and say:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"It seems to work."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You'd write tests.&lt;/p&gt;

&lt;p&gt;You'd monitor it.&lt;/p&gt;

&lt;p&gt;You'd measure performance.&lt;/p&gt;

&lt;p&gt;The same philosophy applies to LLM applications.&lt;/p&gt;

&lt;p&gt;Models can be evaluated against benchmarks and task-specific datasets.&lt;/p&gt;

&lt;p&gt;There are also evaluation frameworks and "evaluation harnesses" that automate running models against collections of standardized tests.&lt;/p&gt;

&lt;p&gt;And for production applications, the most important evaluation is often even more specific:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Does the model perform well on the tasks my users actually care about?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A model can perform extremely well on a benchmark and still perform badly in your specific application.&lt;/p&gt;

&lt;p&gt;That's why evaluation is becoming a major part of AI engineering.&lt;/p&gt;




&lt;h2&gt;
  
  
  24. The Mental Model That Finally Made Everything Click
&lt;/h2&gt;

&lt;p&gt;After going through all of this, I now visualize an LLM roughly like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                    USER INPUT
                        │
                        ▼
                   TOKENIZATION
                        │
                        ▼
                    TOKEN IDs
                        │
                        ▼
                    EMBEDDINGS
                        │
                        ▼
                TRANSFORMER LAYERS
              ┌─────────┴─────────┐
              ▼                   ▼
          ATTENTION               FFN
              │                   │
              └─────────┬─────────┘
                        ▼
                     LOGITS
                        │
                        ▼
                     SOFTMAX
                        │
                        ▼
                  PROBABILITIES
                        │
                        ▼
                    SAMPLING
                        │
                        ▼
                   NEXT TOKEN
                        │
                        └──────────────┐
                                       │
                                       ▼
                              REPEAT THE LOOP
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And around the model, we can build:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  ┌──────────────┐
                  │     LLM      │
                  └──────┬───────┘
                         │
             ┌───────────┼───────────┐
             ▼           ▼           ▼
            RAG        Tools       Memory
             │           │
             ▼           ▼
       Vector DBs      APIs
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's the mental model I'm keeping.&lt;/p&gt;




&lt;h2&gt;
  
  
  25. The Part I Find Most Exciting
&lt;/h2&gt;

&lt;p&gt;Here's what surprised me most.&lt;/p&gt;

&lt;p&gt;The more I learned about LLMs, the less they felt like something completely separate from software engineering.&lt;/p&gt;

&lt;p&gt;They started looking like &lt;strong&gt;another component in a software architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Think about a traditional backend:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend
   ↓
  API
   ↓
Business Logic
   ↓
Database
   ↓
External Services
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now imagine adding an LLM:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Frontend
   ↓
API
   ↓
LLM
   ├── RAG → Vector Database
   ├── Tools → External APIs
   ├── Memory → Database
   └── Guardrails / Evaluation
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Suddenly, the skills you already have become relevant.&lt;/p&gt;

&lt;p&gt;APIs.&lt;/p&gt;

&lt;p&gt;Authentication.&lt;/p&gt;

&lt;p&gt;Databases.&lt;/p&gt;

&lt;p&gt;Caching.&lt;/p&gt;

&lt;p&gt;Queues.&lt;/p&gt;

&lt;p&gt;Observability.&lt;/p&gt;

&lt;p&gt;Error handling.&lt;/p&gt;

&lt;p&gt;Testing.&lt;/p&gt;

&lt;p&gt;Cloud infrastructure.&lt;/p&gt;

&lt;p&gt;Distributed systems.&lt;/p&gt;

&lt;p&gt;The LLM is only one piece.&lt;/p&gt;

&lt;p&gt;And I think that's a very important realization for software engineers trying to enter AI.&lt;/p&gt;




&lt;h2&gt;
  
  
  26. You Don't Need to Become an AI Researcher to Start
&lt;/h2&gt;

&lt;p&gt;If you're a software engineer who wants to get into AI, I don't think the first step should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I need to learn every mathematical detail of neural networks."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And I don't think it should be:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"I'll just learn how to call OpenAI's API."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is a middle ground.&lt;/p&gt;

&lt;p&gt;Understand the architecture first.&lt;/p&gt;

&lt;p&gt;Understand the vocabulary.&lt;/p&gt;

&lt;p&gt;Understand the flow.&lt;/p&gt;

&lt;p&gt;Then start building.&lt;/p&gt;

&lt;p&gt;For example, build a simple application that:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Accepts a user's question.&lt;/li&gt;
&lt;li&gt;Calls an LLM.&lt;/li&gt;
&lt;li&gt;Stores conversations.&lt;/li&gt;
&lt;li&gt;Retrieves relevant documents.&lt;/li&gt;
&lt;li&gt;Uses embeddings.&lt;/li&gt;
&lt;li&gt;Performs vector search.&lt;/li&gt;
&lt;li&gt;Calls external tools.&lt;/li&gt;
&lt;li&gt;Evaluates the generated answers.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;At that point, concepts that looked abstract start becoming practical.&lt;/p&gt;




&lt;h2&gt;
  
  
  27. If I Had to Reduce Everything to One Diagram
&lt;/h2&gt;

&lt;p&gt;This is probably the diagram I'd keep if I forgot everything else:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                 ┌────────────────────┐
                 │      YOUR APP      │
                 └─────────┬──────────┘
                           │
                           ▼
                    ┌─────────────┐
                    │    INPUT    │
                    └──────┬──────┘
                           │
                           ▼
                       TOKENIZER
                           │
                           ▼
                        TOKENS
                           │
                           ▼
                      EMBEDDINGS
                           │
                           ▼
                  ┌─────────────────┐
                  │   TRANSFORMER   │
                  │                 │
                  │ Attention + FFN │
                  │       × N       │
                  └────────┬────────┘
                           │
                           ▼
                        LOGITS
                           │
                           ▼
                        SOFTMAX
                           │
                           ▼
                      NEXT TOKEN
                           │
                           ▼
                     REPEAT / LOOP
                           │
                           ▼
                       RESPONSE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And around that core:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;       RAG ───────&amp;gt; External Knowledge
       Tools ─────&amp;gt; External Actions
       Memory ────&amp;gt; Persistent State
       Evaluation → Quality Measurement
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That, for me, is the foundation.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;I'm still learning.&lt;/p&gt;

&lt;p&gt;There are many things I haven't covered here: positional encodings, KV caching, quantization, distributed training, inference optimization, LoRA, multimodal models, RL techniques, model architectures, serving infrastructure, and much more.&lt;/p&gt;

&lt;p&gt;But I don't think you need to understand everything before you start building.&lt;/p&gt;

&lt;p&gt;What helped me most was going one layer at a time:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text → Tokens → Vectors → Attention → Transformer → Logits → Probabilities → Next Token&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Pretraining → Fine-tuning → Alignment&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;And finally:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LLM → RAG → Tools → Agents → Production AI Systems&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you see those connections, the endless stream of AI terminology becomes much less intimidating.&lt;/p&gt;

&lt;p&gt;You stop seeing "RAG", "embeddings", "tool calling", and "agents" as completely separate technologies.&lt;/p&gt;

&lt;p&gt;You start seeing them as pieces of a larger system.&lt;/p&gt;

&lt;p&gt;And perhaps that's the most useful lesson I've taken from learning LLMs so far:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;You don't need to understand every detail of AI before you start building with it.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But you should understand the foundations well enough to know what is happening underneath the abstraction.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's the point where AI stops feeling like magic.&lt;/p&gt;

&lt;p&gt;And starts feeling like engineering.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;If you're a software engineer starting your own journey into LLMs, I hope this mental model saves you some of the confusion I had when I started.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;There's a lot more to learn.&lt;/p&gt;

&lt;p&gt;But now I finally feel like I know where the pieces belong.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>machinelearning</category>
      <category>llm</category>
      <category>softwareengineering</category>
    </item>
    <item>
      <title>Pokémon Info Retriever: A Fun and Educational Project</title>
      <dc:creator>Adham Hewala</dc:creator>
      <pubDate>Mon, 28 Oct 2024 17:15:27 +0000</pubDate>
      <link>https://dev.to/adhamhe6/pokemon-info-retriever-a-fun-and-educational-project-58jj</link>
      <guid>https://dev.to/adhamhe6/pokemon-info-retriever-a-fun-and-educational-project-58jj</guid>
      <description>&lt;p&gt;As a passionate software developer, I've embarked on an exciting journey to create a Pokémon Info Retriever application. This project combines multiple technologies to provide users with a seamless way to access detailed Pokémon information using the PokeAPI. In this post, I will share the development process, the technologies I used, and some lessons learned along the way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project Overview
&lt;/h2&gt;

&lt;p&gt;The Pokémon Info Retriever consists of three main components:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;FastAPI Backend: This is the core of the application, responsible for handling requests and retrieving Pokémon data from the PokeAPI.&lt;/li&gt;
&lt;li&gt;Python Desktop GUI: A user-friendly desktop application that allows users to input a Pokémon's name and receive its information.&lt;/li&gt;
&lt;li&gt;HTML Web Interface: A simple web interface that allows users to access the Pokémon data through a browser.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Key Technologies Used
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;FastAPI: A modern web framework for building APIs with Python 3. It allows for rapid development and easy handling of asynchronous requests. FastAPI's automatic generation of OpenAPI documentation is a significant advantage.&lt;/li&gt;
&lt;li&gt;PokeAPI: A RESTful API that provides access to a vast amount of Pokémon data, including abilities, types, and stats.&lt;/li&gt;
&lt;li&gt;Tkinter: The standard GUI toolkit for Python, used to create the desktop application. It's lightweight and allows for quick development of simple user interfaces.&lt;/li&gt;
&lt;li&gt;HTML/CSS: Used for the web interface, enabling access to Pokémon data through any web browser.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Development Process
&lt;/h2&gt;

&lt;p&gt;Step 1: Setting Up the FastAPI Backend&lt;br&gt;
I started by setting up the FastAPI backend, which involved defining routes for fetching Pokémon data. The backend handles requests and interacts with the PokeAPI to retrieve relevant information based on user input.&lt;/p&gt;

&lt;p&gt;Step 2: Creating the Desktop GUI&lt;br&gt;
Using Tkinter, I designed a simple yet effective GUI. The GUI prompts users to enter a Pokémon name and displays relevant data upon clicking the retrieve button.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Fb92icsj1djvhj6g1nx44.png" class="article-body-image-wrapper"&gt;&lt;img src="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%2Fb92icsj1djvhj6g1nx44.png" alt="Pokemon GUI" width="800" height="459"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Step 3: Building the HTML Interface&lt;br&gt;
The HTML template serves as an accessible front-end option, allowing users to interact with the API directly through their browsers.&lt;/p&gt;

&lt;p&gt;&lt;a href="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%2Fc2v8nrsngdkrp0nu42rq.png" class="article-body-image-wrapper"&gt;&lt;img src="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%2Fc2v8nrsngdkrp0nu42rq.png" alt="Pokemon Template" width="800" height="499"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Challenges Faced
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Error Handling: One of the challenges was ensuring proper error handling when users entered invalid Pokémon names. I implemented comprehensive exception handling to provide user-friendly error messages.&lt;/li&gt;
&lt;li&gt;Cross-Origin Resource Sharing (CORS): Configuring CORS in FastAPI was essential to allow requests from the front-end applications. I learned how to set this up efficiently.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Future Improvements
&lt;/h2&gt;

&lt;p&gt;I plan to enhance the application further by:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Adding more detailed Pokémon stats, including evolutions and habitats.&lt;/li&gt;
&lt;li&gt;Implementing user authentication for personalized experiences.&lt;/li&gt;
&lt;li&gt;Improving the GUI design for better aesthetics and user experience.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Useful Links
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can find more about the Pokémon data and endpoints in the &lt;a href="https://pokeapi.co/docs/v2" rel="noopener noreferrer"&gt;PokeAPI Documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;For detailed information on how to get started with FastAPI, check out the &lt;a href="https://fastapi.tiangolo.com/" rel="noopener noreferrer"&gt;FastAPI Documentation&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;The complete code for the Pokémon Info Retriever project can be found in my GitHub repository: &lt;a href="https://github.com/adhamhe6/Pokemon-Info-Retriever" rel="noopener noreferrer"&gt;GitHub - Pokémon Info Retriever&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This project was a fantastic learning experience, allowing me to delve into FastAPI, GUI development, and API integration. I encourage anyone interested in similar projects to give it a try!&lt;/p&gt;

</description>
      <category>python</category>
      <category>fastapi</category>
      <category>webdev</category>
      <category>pokémon</category>
    </item>
  </channel>
</rss>
