<?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: Ravindranath Guptha K</title>
    <description>The latest articles on DEV Community by Ravindranath Guptha K (@ravindranath_k).</description>
    <link>https://dev.to/ravindranath_k</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%2F4078514%2Fc4081e20-e741-42a8-ab1b-640c01e42a43.png</url>
      <title>DEV Community: Ravindranath Guptha K</title>
      <link>https://dev.to/ravindranath_k</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ravindranath_k"/>
    <language>en</language>
    <item>
      <title>"How Does LLM Actually Work? From Prompt to Prediction"</title>
      <dc:creator>Ravindranath Guptha K</dc:creator>
      <pubDate>Sat, 15 Aug 2026 06:19:13 +0000</pubDate>
      <link>https://dev.to/ravindranath_k/how-does-llm-actually-work-from-prompt-to-prediction-1a21</link>
      <guid>https://dev.to/ravindranath_k/how-does-llm-actually-work-from-prompt-to-prediction-1a21</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Large Language Models have quickly become part of everyday software development.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;We ask them to explain code, debug errors, generate tests, write Python scripts, summarize documentation, or help us understand an unfamiliar codebase.&lt;/p&gt;

&lt;p&gt;Within seconds, we get a response that can feel surprisingly natural.&lt;/p&gt;

&lt;p&gt;But what actually happens during those few seconds?&lt;/p&gt;

&lt;p&gt;Suppose you type:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is a build system?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The model doesn't simply search through a database for a stored answer, and it doesn't generate the entire response in one shot.&lt;/p&gt;

&lt;p&gt;At the heart of an autoregressive LLM is a deceptively simple task:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Given the tokens I've seen so far, what token should come next?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Getting to that prediction, however, involves several layers of computation.&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;Prompt
   ↓
Tokens
   ↓
Embeddings
   ↓
Transformer
   ↓
Logits
   ↓
Next Token
   ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's follow that journey.&lt;/p&gt;




&lt;h2&gt;
  
  
  1. Everything Starts With the Prompt
&lt;/h2&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is a build system?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Humans immediately recognize the words and their meaning.&lt;/p&gt;

&lt;p&gt;A neural network needs numbers.&lt;/p&gt;

&lt;p&gt;Before the model can process the question, the text passes through a &lt;strong&gt;tokenizer&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  2. Tokenization: Breaking Text Into Pieces
&lt;/h2&gt;

&lt;p&gt;A tokenizer divides text into smaller units called &lt;strong&gt;tokens&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Conceptually, our prompt might become:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;["What", " is", " a", " build", " system", "?"]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is only an illustration. Actual tokenization depends on the tokenizer used by the model.&lt;/p&gt;

&lt;p&gt;A token isn't necessarily a complete word. It might represent:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;a complete 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 combined with text&lt;/li&gt;
&lt;li&gt;a number&lt;/li&gt;
&lt;li&gt;part of an identifier&lt;/li&gt;
&lt;li&gt;a programming-language symbol&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each token is mapped to an integer called a &lt;strong&gt;token ID&lt;/strong&gt;.&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;["What", " is", " a", " build", " system", "?"]

                 ↓

[3923, 374, 264, 1975, 1887, 30]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The IDs above are illustrative.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Human-readable text has become a sequence of numbers the model can process.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But token IDs themselves don't capture useful semantic relationships.&lt;/p&gt;

&lt;p&gt;The number &lt;code&gt;1975&lt;/code&gt;, for example, doesn't inherently explain what &lt;strong&gt;build&lt;/strong&gt; means.&lt;/p&gt;

&lt;p&gt;That's where embeddings enter the picture.&lt;/p&gt;




&lt;h2&gt;
  
  
  3. Embeddings: Turning Tokens Into Vectors
&lt;/h2&gt;

&lt;p&gt;Each token is mapped to an &lt;strong&gt;embedding&lt;/strong&gt;—a high-dimensional vector of numbers.&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;build → [0.12, -0.47, 0.83, 0.21, ...]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These useful representations are learned during model training rather than manually assigned by engineers.&lt;/p&gt;

&lt;p&gt;Embeddings give the neural network much richer representations to work with.&lt;/p&gt;

&lt;p&gt;But language depends heavily on &lt;strong&gt;context&lt;/strong&gt;.&lt;/p&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The developer restarted the build because it failed.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;What does &lt;strong&gt;it&lt;/strong&gt; refer to?&lt;/p&gt;

&lt;p&gt;A human reader can connect it with &lt;strong&gt;the build&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The model needs a mechanism for modeling relationships between tokens as well.&lt;/p&gt;

&lt;p&gt;That's where &lt;strong&gt;self-attention&lt;/strong&gt; becomes important.&lt;/p&gt;




&lt;h2&gt;
  
  
  4. Self-Attention: Which Other Tokens Matter?
&lt;/h2&gt;

&lt;p&gt;Self-attention is one of the core ideas behind the Transformer architecture.&lt;/p&gt;

&lt;p&gt;Instead of treating every token independently, attention allows each token's representation to incorporate information from other relevant tokens in the context.&lt;/p&gt;

&lt;p&gt;A useful mental model is that each token is asking:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Which other tokens should influence my representation right now?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Under the hood, tokens are projected into three important vectors:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Query (Q)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Key (K)&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Value (V)&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;An intuitive way to think about them is:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Query:&lt;/strong&gt; What information am I looking for?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key:&lt;/strong&gt; What information might I match with?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Value:&lt;/strong&gt; What information should I contribute if I'm relevant?&lt;/p&gt;

&lt;p&gt;The standard scaled dot-product attention operation is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Attention(Q, K, V) = softmax(QKᵀ / √dₖ)V
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll explore the mathematics more deeply in a later article.&lt;/p&gt;

&lt;p&gt;For now, the key idea is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Attention allows the representation of a token to depend on its surrounding context.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Transformers also use multiple attention heads, allowing different kinds of relationships to be modeled in parallel.&lt;/p&gt;




&lt;h2&gt;
  
  
  5. Through the Transformer
&lt;/h2&gt;

&lt;p&gt;Self-attention is part of the larger &lt;strong&gt;Transformer architecture&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Token representations pass through a stack of Transformer layers.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Token Embeddings
       ↓
Self-Attention
       ↓
Feed-Forward Network
       ↓
Next Transformer Layer
       ↓
Self-Attention
       ↓
Feed-Forward Network
       ↓
      ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Real Transformer blocks also contain mechanisms such as residual connections and normalization.&lt;/p&gt;

&lt;p&gt;As the representations move through these layers, they become increasingly contextualized.&lt;/p&gt;

&lt;p&gt;The representation associated with &lt;strong&gt;build&lt;/strong&gt;, for example, is no longer simply a static representation of that token.&lt;/p&gt;

&lt;p&gt;It now incorporates information about how &lt;strong&gt;build&lt;/strong&gt; is being used in this particular context.&lt;/p&gt;

&lt;p&gt;Eventually, the model reaches the central question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What token should come next?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  6. From Transformer Output to Logits
&lt;/h2&gt;

&lt;p&gt;After processing the context, the model produces scores for possible next tokens.&lt;/p&gt;

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

&lt;p&gt;Imagine a tiny example:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Possible Token&lt;/th&gt;
&lt;th&gt;Logit&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;7.2&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The&lt;/td&gt;
&lt;td&gt;5.8&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build&lt;/td&gt;
&lt;td&gt;3.4&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Software&lt;/td&gt;
&lt;td&gt;2.7&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Banana&lt;/td&gt;
&lt;td&gt;-4.1&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A real model may have a vocabulary containing tens or hundreds of thousands of tokens.&lt;/p&gt;

&lt;p&gt;That means the model produces a large vector of scores at every generation step.&lt;/p&gt;

&lt;p&gt;Higher logits generally indicate more plausible next tokens.&lt;/p&gt;

&lt;p&gt;These scores can then be converted into a probability distribution using &lt;strong&gt;softmax&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Token&lt;/th&gt;
&lt;th&gt;Probability&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;A&lt;/td&gt;
&lt;td&gt;55%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The&lt;/td&gt;
&lt;td&gt;25%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Build&lt;/td&gt;
&lt;td&gt;10%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Software&lt;/td&gt;
&lt;td&gt;7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Everything else&lt;/td&gt;
&lt;td&gt;3%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Again, these numbers are illustrative.&lt;/p&gt;

&lt;p&gt;Now the model has possible continuations and their relative likelihoods.&lt;/p&gt;




&lt;h2&gt;
  
  
  7. Choosing the Next Token
&lt;/h2&gt;

&lt;p&gt;How the next token is chosen depends on the decoding strategy.&lt;/p&gt;

&lt;p&gt;Generation can be influenced by techniques such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;temperature&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;top-k sampling&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;top-p sampling&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;greedy or other decoding strategies&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Suppose the model selects:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The sequence now becomes:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is a build system? A&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The model isn't finished.&lt;/p&gt;

&lt;p&gt;It predicts again.&lt;/p&gt;




&lt;h2&gt;
  
  
  8. The Answer Grows One Token at a Time
&lt;/h2&gt;

&lt;p&gt;The model now has:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is a build system? A&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It predicts another token.&lt;/p&gt;

&lt;p&gt;Perhaps:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;build&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What is a build system? A build&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;system&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;is&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Then:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;a&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The process continues until a stopping condition is reached.&lt;/p&gt;

&lt;p&gt;Eventually, we might get:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A build system is software that automates the process of compiling, linking, testing, and packaging software.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

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

&lt;p&gt;At each step:&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
      ↓
Next-Token Distribution
      ↓
Select Token
      ↓
Append Token
      ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is one of the most important ideas for understanding LLMs:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The answer isn't normally generated all at once. It grows token by token.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  9. What Happens When an LLM Generates Code?
&lt;/h2&gt;

&lt;p&gt;The same basic process applies when an LLM generates software.&lt;/p&gt;

&lt;p&gt;Suppose we ask:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Write a C++ function that returns the larger of two integers.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The model might produce:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;maxValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt; &lt;span class="o"&gt;?&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From our perspective, it looks as though the model understood the requirement and produced a complete C++ function.&lt;/p&gt;

&lt;p&gt;But the fundamental generation mechanism hasn't changed.&lt;/p&gt;

&lt;p&gt;The output is still produced as a sequence of 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;int
 → maxValue
 → (
 → int
 → a
 → ,
 → int
 → b
 → )
 → {
 → return
 → a
 → &amp;gt;
 → b
 → ?
 → a
 → :
 → b
 → ;
 → }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The actual token boundaries depend on the tokenizer.&lt;/p&gt;

&lt;p&gt;What's interesting is how the &lt;strong&gt;existing context changes what becomes likely next&lt;/strong&gt;.&lt;/p&gt;

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

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;maxValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;tokens associated with a C++ function signature become plausible.&lt;/p&gt;

&lt;p&gt;Later, after:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight cpp"&gt;&lt;code&gt;&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="n"&gt;a&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the prompt, previously generated code, and patterns learned during training make certain continuations more plausible than unrelated ones.&lt;/p&gt;

&lt;p&gt;The model doesn't suddenly switch to a dedicated C++ code-generation engine.&lt;/p&gt;

&lt;p&gt;The same fundamental loop continues:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt + Generated Code
          ↓
      Transformer
          ↓
Next-Token Distribution
          ↓
     Select Token
          ↓
     Append Token
          ↓
        Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same principle applies to Python, Rust, Java, SQL, shell scripts, and other programming languages.&lt;/p&gt;

&lt;p&gt;Of course, generating a small function is much easier than generating or modifying a large software component.&lt;/p&gt;

&lt;p&gt;For larger tasks, the model may need to maintain relationships involving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;function signatures&lt;/li&gt;
&lt;li&gt;types&lt;/li&gt;
&lt;li&gt;variable names&lt;/li&gt;
&lt;li&gt;APIs&lt;/li&gt;
&lt;li&gt;control flow&lt;/li&gt;
&lt;li&gt;previously generated code&lt;/li&gt;
&lt;li&gt;programming-language syntax&lt;/li&gt;
&lt;li&gt;user requirements&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;across a much larger context.&lt;/p&gt;

&lt;p&gt;That raises an interesting question:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;If an LLM generates code token by token, how can it produce syntactically and sometimes logically consistent programs?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's a topic worth exploring separately.&lt;/p&gt;

&lt;p&gt;For now, the important takeaway is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Natural language and source code look very different to us, but to an LLM they ultimately become sequences of tokens to be modeled and predicted.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  10. Doesn't Repeating the Transformer Get Expensive?
&lt;/h2&gt;

&lt;p&gt;Yes.&lt;/p&gt;

&lt;p&gt;Suppose the model has already processed a long prompt and generated hundreds of tokens.&lt;/p&gt;

&lt;p&gt;Recalculating all of the attention information for every previous token from scratch for each new token would involve substantial redundant computation.&lt;/p&gt;

&lt;p&gt;One important optimization is the &lt;strong&gt;KV cache&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;During self-attention, the model computes Key and Value representations for tokens it has already processed.&lt;/p&gt;

&lt;p&gt;During autoregressive decoding, those representations can be cached and reused.&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;Without KV Cache

Recompute previous K/V
        ↓
Process next token
        ↓
Generate
        ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With caching:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;With KV Cache

Reuse previous K/V
        ↓
Compute K/V for new token
        ↓
Generate
        ↓
Repeat
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This reduces redundant computation during generation, although the growing cache also consumes memory as the context becomes longer.&lt;/p&gt;

&lt;p&gt;KV caching deserves its own deeper discussion later.&lt;/p&gt;




&lt;h2&gt;
  
  
  11. From Prompt to Prediction
&lt;/h2&gt;

&lt;p&gt;We can now put the complete journey together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;User Prompt
     ↓
Tokenization
     ↓
Token IDs
     ↓
Embeddings
     ↓
Transformer Layers
     ↓
Self-Attention
     ↓
Contextual Representations
     ↓
Logits
     ↓
Next-Token Distribution
     ↓
Token Selection
     ↓
Append Token
     ↓
Repeat
     ↓
Final Response
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From the user's perspective, the interaction looks incredibly simple:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Ask a question → Get an answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Behind that interaction is a repeated sequence of numerical transformations and next-token predictions.&lt;/p&gt;




&lt;h2&gt;
  
  
  12. Is an LLM Really "Just a Next-Token Predictor"?
&lt;/h2&gt;

&lt;p&gt;You've probably heard this description:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;LLMs are just next-token predictors.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is an important truth behind it.&lt;/p&gt;

&lt;p&gt;Next-token prediction is central to the training objective of many autoregressive LLMs, and autoregressive generation produces output by repeatedly predicting subsequent tokens.&lt;/p&gt;

&lt;p&gt;But the word &lt;strong&gt;just&lt;/strong&gt; hides most of what makes these systems interesting.&lt;/p&gt;

&lt;p&gt;Predicting what follows:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;The sky is...&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;may seem straightforward.&lt;/p&gt;

&lt;p&gt;Now consider asking the same model to:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;explain an algorithm&lt;/li&gt;
&lt;li&gt;generate a C++ implementation&lt;/li&gt;
&lt;li&gt;translate Python into Rust&lt;/li&gt;
&lt;li&gt;summarize a technical document&lt;/li&gt;
&lt;li&gt;analyze an error message&lt;/li&gt;
&lt;li&gt;reason about unfamiliar code&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output still emerges token by token.&lt;/p&gt;

&lt;p&gt;But producing useful next-token distributions requires a sophisticated learned representation of the context.&lt;/p&gt;

&lt;p&gt;The simple question is:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;What should come next?&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The complicated part is the enormous learned system answering it.&lt;/p&gt;

&lt;p&gt;Transformer layers, attention mechanisms, embeddings, billions of learned parameters, and highly optimized inference infrastructure all contribute to those predictions.&lt;/p&gt;

&lt;p&gt;Then the model does it again.&lt;/p&gt;

&lt;p&gt;And again.&lt;/p&gt;

&lt;p&gt;And again.&lt;/p&gt;




&lt;h2&gt;
  
  
  Final Thoughts
&lt;/h2&gt;

&lt;p&gt;An LLM can seem mysterious when all we see is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Prompt → Answer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But once we look inside, the process becomes easier to reason about.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Text becomes tokens.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tokens become numerical representations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Transformers use attention to build contextual representations.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Those representations produce scores for possible next tokens.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A token is selected.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Then the process repeats.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;That basic loop is the foundation for much of what we experience when interacting with modern language models.&lt;/p&gt;

&lt;p&gt;Once these pieces become familiar, an LLM starts looking less like a mysterious black box and more like something engineers are used to understanding:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;A very large system built from smaller, understandable components.&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  What's Next?
&lt;/h2&gt;

&lt;p&gt;We've followed an LLM from the moment a prompt enters the system to the point where a response emerges, one token at a time.&lt;/p&gt;

&lt;p&gt;But we moved quickly through the very first step: &lt;strong&gt;tokenization&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;How does an LLM decide where one token ends and another begins? Why can a single word become multiple tokens? And what happens when the input is source code rather than ordinary English?&lt;/p&gt;

&lt;p&gt;In the next article in this &lt;strong&gt;LLM Internals&lt;/strong&gt; series, we'll take a closer look at:&lt;/p&gt;

&lt;h3&gt;
  
  
  Tokenization: How LLMs Break Text and Source Code Into Tokens
&lt;/h3&gt;

&lt;p&gt;Once we understand that first transformation, we'll be ready to move deeper into what happens inside the model.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>machinelearning</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
