<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mahmud Jarman on Medium]]></title>
        <description><![CDATA[Stories by Mahmud Jarman on Medium]]></description>
        <link>https://medium.com/@boundlessmahmudjarman?source=rss-7e0add56bff------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*aKM0Av7E803-p1E3.</url>
            <title>Stories by Mahmud Jarman on Medium</title>
            <link>https://medium.com/@boundlessmahmudjarman?source=rss-7e0add56bff------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 22 Nov 2026 06:30:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@boundlessmahmudjarman/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Beyond the “Brain”: Deconstructing How LLMs Predict and Adapt — Understanding Large Language Model]]></title>
            <link>https://medium.com/@boundlessmahmudjarman/beyond-the-brain-deconstructing-how-llms-predict-and-adapt-understanding-large-language-model-128ff17cf68a?source=rss-7e0add56bff------2</link>
            <guid isPermaLink="false">https://medium.com/p/128ff17cf68a</guid>
            <category><![CDATA[large-language-models]]></category>
            <category><![CDATA[transformers]]></category>
            <category><![CDATA[llm]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[feed-forward-networks]]></category>
            <dc:creator><![CDATA[Mahmud Jarman]]></dc:creator>
            <pubDate>Thu, 04 Jun 2026 19:34:08 GMT</pubDate>
            <atom:updated>2026-06-04T20:54:50.089Z</atom:updated>
            <content:encoded><![CDATA[<p><strong><em>From a simple sentence to the intricate dance of numbers, attention, and probability that makes AI speak.</em></strong></p><p>We’ve all seen it: a Large Language Model flawlessly completing a sentence, writing poetry, or even debugging code. It feels like magic. But what happens when you give it something deceptively simple, like “My son loves to play Jenga in…”?</p><h3>Intuition</h3><p>A human might guess:</p><ul><li>“the house”</li><li>“his room”</li><li>“the living room”</li></ul><p>Because:</p><ul><li><em>Jenga</em> is a physical indoor game</li><li>The sentence implies a <strong>location</strong></li></ul><p>I asked modern LLMs like ChatGPT for the next word — and instead of answering directly, the model seemed to <em>seek more context</em>, almost like it was asking for the “vibe” of the sentence.</p><p>That raised a question:</p><blockquote><em>Why does context matter so much? Why not just give the most likely word from its statistical world?</em></blockquote><p>So I pushed back. I restarted the chat and asked the same question again — this time insisting on an answer without additional context.</p><p>And something surprising happened.</p><p>In a fresh conversation forcing to answer by not giving more context, the model almost always answered:</p><blockquote><em>“the living room”</em></blockquote><p>But within the same conversation, each repeated attempt produced <em>different</em> answers:</p><ul><li>“the house”</li><li>“his room”</li><li>“the park”</li></ul><p>Same prompt. Different outputs.</p><p>That’s when it hit me:</p><blockquote><em>Why does the same model behave so differently across sessions?<br>Why is it consistent in a new chat, but variable within an ongoing one?<br>What is actually changing under the hood?</em></blockquote><p>This isn’t randomness in the usual sense — but it is <strong>controlled randomness and </strong>it’s a direct consequence of how modern language models use <strong>context, attention, probability and sampling</strong>.</p><p>Let’s dive a bit deeper — just enough — into the world of artificial intelligence to understand why this happens.</p><h3>Numbers Numbers Numbers!!!</h3><p>At their core, AI models — especially large language models (LLMs) — don’t “understand” words the way humans do. They convert everything into numbers, operate in that numerical space, and use statistical patterns to estimate what the next word (more precisely, the next <strong>token</strong>) should be.</p><p>A <strong>token</strong> is a small unit of text — sometimes a whole word, sometimes just part of one — that the model processes as a number. Modern large language models can handle anywhere from a few thousand to <strong>hundreds of thousands of tokens</strong> in a single context window, depending on the architecture. During training, large models are exposed to <strong>trillions of tokens of text data</strong>, and during use they are limited by a <strong>context window.</strong></p><p>To make this intuitive, lets go back to my son:</p><blockquote><em>“My son loves to play Jenga in the living room.”</em></blockquote><p>Instead of seeing it as words, the model sees something closer to:</p><blockquote><em>1542, 873, 91, 402, 778, 65, 1205, 9…</em></blockquote><p>Each number represents a token in a massive dictionary. The model’s job is not to “understand” the sentence, but to calculate:</p><blockquote><em>given these numbers, what number is most likely to come next?</em></blockquote><p>In short, LLMs don’t read Shakespeare. They don’t “get” jokes. They don’t picture your living room.</p><p>They just do one thing extremely well:</p><blockquote><strong><em>Numberify the world… and guess what number comes next.</em></strong></blockquote><h3>Numberify the world!</h3><p>Before the network can perform any math, it converts the text into a numerical format. Lets assume that in our tiny world we only know a few words that our network can learn. We create a <strong>Vocabulary (V)</strong>, which is a list of all unique words the model will know (our simplest vocabulary).</p><p>Let,</p><p>V={“My”, “son”, “loves”, “to”, “play”, “jenga”, “in”, “the”, “room”, “yard”}</p><p>The size of our vocabulary, ∣V∣, is 10. Each word in our sentence can be represented as a <strong>One-Hot Vector (X<em>word​</em>)</strong>. This is a vector of length ∣V∣ where every entry is 0 except at the index of the word, which is 1.</p><p><strong><em>Calculation:</em></strong><em> If “jenga” is index 5 in our vocabulary:</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/1*BxkcVpI7KSDuQJNueRQZRA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4c2RGR7ByJOKMplMhzvv1Q.jpeg" /><figcaption><em>A horizontal flowchart showing how words are indexed and converted into sparse one-hot vectors. It will go from 0 to 9 (only 0 to 6 shown)</em></figcaption></figure><p>In the real world, vocabulary is <em>massive</em> — we’re talking tens of thousands to hundreds of thousands of words. If we tried to represent each word using a one-hot vector, it would look like a giant spreadsheet with almost all zeros… which is both memory-heavy and computationally wasteful.</p><p>So instead of doing that, we introduce a smarter trick: the <strong>Embedding Matrix (E)</strong>. This matrix takes those giant sparse one-hot vectors and compresses them into something much more useful — a <strong>dense, lower-dimensional representation</strong> that still preserves meaning. Let’s say we choose an embedding dimension:</p><p>d=3d =3</p><p>That means every word will now live in a 3D space (like coordinates in a tiny semantic universe). Now the embedding matrix becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/286/1*6DtMtX3WRc9nIOySKouqEA.png" /><figcaption>R represents set of real numbers</figcaption></figure><p>So if our vocabulary has 10 words, then:</p><ul><li>E has <strong>3 columns</strong> (the embedding dimensions)</li><li>and <strong>10 rows</strong> (one for each word)</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*wqVn7Zvcjz15dsiDHZDMCw.png" /></figure><p>Each dimension is basically a word’s “personality profile” in number form. So instead of a word being a boring one-hot spike like:</p><blockquote><em>[0, 0, 0, 0, 1, 0, 0, 0, 0, 0]</em></blockquote><p>It becomes something like:</p><blockquote><em>[0.82, -0.13, 0.47]</em></blockquote><p>Now the magic starts happening: words with similar meanings end up with similar coordinates in this 3D space — like “park”, “yard”, and “field” clustering together, while “kitchen”, “room”, and “house” form another group.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*ukKOVS8X3aTnmORTs8gebA.jpeg" /></figure><p>The “size” of the embedding/<strong>dimension</strong> — d determines how “smart” or nuanced the AI’s understanding is. Modern LLMs such as <strong>Word2Vec (Classic) uses </strong>300 dimensions, <strong>GPT-2 uses </strong>768 dimensions <strong>GPT-3 / GPT-4 uses </strong>1,536 to 3,072 dimensions and <strong>Gemini u</strong>ses high-dimensional embeddings (often 768, 1024, or more) to capture the subtle difference between a son playing Jenga in a “living room” versus playing it in “absolute silence.”</p><p>In short:</p><blockquote><em>One-hot encoding is like shouting one word in a giant empty stadium.<br>Embeddings are like placing each word in a meaningful 3D map of language.</em></blockquote><h4>The Math</h4><p>To find the embedding vector <em>e</em> for a word:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/262/1*lHRQHLvJKFlDXmisjkGrKQ.png" /></figure><p>Since xword is one-hot, this multiplication effectively “grabs” the i-th column of E. So instead of doing a full matrix multiplication, we’re effectively <strong>selecting column 5</strong>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/234/1*LBNrblck7tBOqIF_P5frDw.png" /></figure><p>This is why in real implementations, embeddings are just <strong>lookup tables</strong>, not actual multiplications.</p><p>Lets assume that in our small world, for our tiny model of ten words, E is-</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CWinHjyNTYzRSmgFlWqFYQ.png" /></figure><h3>But what are those “bizarre” or magical numbers inside the embedding matrix E and where did they come from?</h3><p>Those “bizarre” numbers inside the embedding matrix E didn’t come from any human-designed rule or dictionary — they are <strong>learned from data</strong>. The whole learning process happens inside a neural engine called the <strong>Feed Forward Network (FFN)</strong>. For simplicity, Lets discuss a traditional FFN alone to exclude the complexity of modern LLM architecture. A traditional FFN can be thought of as a pipeline with three main stages:</p><p>Input Layer → Hidden Layers → Output Layer</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*skOXkPPNHSX96ayxcWTklA.png" /></figure><p>🔢 <strong>Input Layer — Starting from Random Meaning</strong></p><p>At the very beginning — E is filled with <strong>random numbers</strong>, typically:</p><ul><li>Small Gaussian values/random numbers : N(0,0.01), or</li><li>Uniform values: [−0.1,0.1][-0.1, 0.1][−0.1,0.1]</li></ul><p>So initially:</p><p>👉 “jenga”, “park”, and “son” are basically meaningless random vectors and goes to input neurons.</p><h4>🧠 <strong>Hidden Layers — Where Learning Actually Happens</strong></h4><p>The input vectors are then passed into <strong>hidden layers</strong>, which form the core of the FFN. This is where the real transformation happens.</p><p>Each hidden layer:</p><ul><li>connects to every neuron in the previous layer (fully connected)</li><li>mixes and transforms all input signals</li><li>searches for patterns across dimensions</li><li>gradually builds higher-level meaning</li></ul><p>Instead of reading words, they are looking into every possible combinations to find pattern.</p><p>Each layer refines the representation further by using activation functions like <strong>ReLU. </strong>Activation function’s role is simple but powerful.</p><blockquote><em>They decide which signals to keep and which to suppress.</em></blockquote><ul><li><em>Strong signals are passed forward</em></li><li><em>Weak or irrelevant signals are removed</em></li></ul><p>This creates a filtering effect, allowing only useful patterns to survive.</p><p>As data passes through multiple hidden layers:</p><ul><li><em>Early layers detect simple patterns</em></li><li><em>Middle layers combine patterns</em></li><li><em>Deeper layers form abstract concepts</em></li></ul><p>So the model gradually moves from:</p><blockquote><em>raw numbers → patterns → meaning → prediction logic</em></blockquote><p>🎯 <strong>Output Layer — Predicting the Next Word</strong></p><p>At the final stage, the output layer collects all refined signals and tries to predict the next word.</p><p>It produces a score for each possible word:</p><ul><li><em>“room” → high score</em></li><li><em>“kitchen” → medium score</em></li><li><em>“park” → low score</em></li></ul><p>Then these scores are converted into probabilities.</p><h4>🔁 It gets punished(Loss Function &amp; Back-propagation )</h4><p>When the prediction is wrong, the model calculates its error. Then it uses <strong>back-propagation</strong> to send that error backward through the network.</p><ul><li><em>“backyard” instead of “the” → high loss</em></li><li><em>“the” correctly → low loss</em></li></ul><p>This process identifies which connections contributed to the mistake then slightly adjusts weights in the FFN and finally updates the embedding vectors involved in the input using <strong>gradient descent</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/346/1*_k5WIVwE3J5jUIazpObmmg.png" /></figure><p>Where:</p><ul><li>η = learning rate</li><li>L = Loss</li></ul><p>So the full cycle looks like this:</p><pre>Random Embeddings<br>        ↓<br>FFN Input Layer<br>        ↓<br>Hidden Layers (pattern discovery)<br>        ↓<br>Output Prediction<br>        ↓<br>Error Calculation (loss)<br>        ↓<br>Backpropagation<br>        ↓<br>Updated Embeddings + Weights</pre><h4>Repeat billions of times</h4><p>After seeing billions of sentences, trillions of tokens and endless contexts the random numbers slowly reshape themselves into a structure. They stop being random and start encoding relationships like:</p><ul><li>“park”, “yard”, “field”<br> → their embeddings move closer together</li><li>“eat”, “cook”, “serve”<br> → cluster in a different region</li></ul><p>So the embedding space quietly organizes itself into a kind of <strong>meaning geometry</strong>. Eventually, E organizes into a semantic space where:</p><ul><li>Distance ≈ similarity</li><li>Directions encode relationships</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MbUIkTI1_uHYo7L-z64phw.png" /></figure><h3>We are not done yet!</h3><p>So far, our tiny AI has learned something important:</p><p>👉Words become vectors.<br>👉Vectors become patterns.<br>👉Patterns become predictions.</p><p>But there is still a massive problem. When the model reads- <em>“My son loves to play Jenga in the…”</em></p><blockquote>How does it know which earlier words matter most?</blockquote><p>Should it focus on: <strong>“son”</strong>? <strong>“play”</strong>? <strong>“Jenga”</strong>? <strong>“in”</strong>?</p><p>Clearly, not every word is equally important. This is where one of the biggest breakthroughs in modern AI appears. It knows where to pay attention.</p><h3>⚡ Attention! Attention! Attention!</h3><p>Attention is the mechanism that allows the model to dynamically decide: <em>Which previous words should I pay attention to right now?” </em>Instead of treating all earlier words equally, the model learns to assign <strong>importance scores</strong>. For our sentence:</p><blockquote><em>“My son loves to play Jenga in the…”</em></blockquote><p>the model may internally decide something like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oYw3clFhCSyhMuCrjDos3A.png" /></figure><p>Notice what happened ? The word <strong>“Jenga”</strong> dominates. So the model heavily focuses on it while predicting the next token. This is why modern AI feels <em>context-aware</em>. The model is not just remembering words. It is continuously asking:</p><blockquote><em>“Which earlier parts of this sentence are most relevant for predicting the next thing?”</em></blockquote><p>Older neural networks struggled with long sentences. Traditional models often “forgot” important earlier words by the time they reached the end. Attention solved this beautifully. Instead of compressing everything into one fading memory, attention allows the model to directly “look back” at all previous tokens whenever needed. It is almost like giving the AI selective memory retrieval. This idea became so powerful that researchers built an entire architecture around it and it is called The Transformer.</p><h3>The Transformer</h3><p>First Introduced in the famous 2017 paper- “Attention Is All You Need” replaced older sequence models and became the foundation for the prominent models:</p><ul><li><a href="https://openai.com/?utm_source=chatgpt.com"><strong>OpenAI GPT models</strong></a></li><li><a href="https://gemini.google.com/?utm_source=chatgpt.com"><strong>Google Gemini</strong></a></li><li><a href="https://www.anthropic.com/?utm_source=chatgpt.com"><strong>Anthropic Claude</strong></a></li></ul><p>The key insight was shocking:</p><blockquote><em>Maybe language understanding mostly comes from attention itself.</em></blockquote><p>And remarkably… it worked!</p><p>Under the hood, every token generates three vectors:</p><ul><li><strong>Query (Q)</strong> → What am I looking for?</li><li><strong>Key (K)</strong> → What information do I contain?</li><li><strong>Value (V)</strong> → What information should I pass forward?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*jGg2rjQk6V5YKm-RooN9ig.png" /></figure><p>When predicting the next word, the model compares Queries against Keys. If two vectors match strongly, attention becomes high. That terrifying equation basically means:</p><ol><li>Compare words with each other</li><li>Compute relevance scores</li><li>Normalize into probabilities</li><li>Blend useful information together</li></ol><p>So when the model sees: <em>“play Jenga in the…” </em>the Query may strongly match the Key associated with:</p><ul><li>“Jenga”</li><li>“play”</li></ul><p>which increases attention toward indoor-location words like:</p><ul><li>room</li><li>house</li><li>basement</li><li>living room</li></ul><h3>Lets understand the whole process</h3><p>Earlier we built embedding matrix E where each column corresponds to dimension (word personality) and each row corresponds to a word. For the transformer, our sentence: <em>“My son loves to play Jenga in” </em>becomes X which comes from our E.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/372/1*EIAtKKQ-HB4ht6pwUY9Aog.png" /></figure><p>This matrix X is now the actual input to the transformer or attention layer. The embedding vectors contain raw semantic meaning. But attention needs specialized versions of those meanings:</p><ul><li>one for searching (Query)</li><li>one for matching (Key)</li><li>one for information passing (Value)</li></ul><p>So the transformer creates transformed copies of the embeddings.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*pLFmsuVUDSm5mhRKCpTHPw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Z-RSWWZ8zqDmZ5JUVKQLqQ.png" /></figure><p>Where Do These Weights Come From? These are trainable parameters. They are learned during training just like embeddings. Same old cycle-</p><blockquote>Initially Random-&gt;Model Trained-&gt;loss increases-&gt;gradients are computed-&gt;backpropagation updates the weights</blockquote><p>The overall flow is:</p><pre>Tokens<br>   ↓<br>Embedding Lookup (using E)<br>   ↓<br>Transformer Layers (Q,K,V attention + FFN)<br>   ↓<br>Prediction<br>   ↓<br>Loss Calculation<br>   ↓<br>Backpropagation<br>   ↓<br>Update EVERYTHING together:<br>   - Embeddings E<br>   - Q/K/V matrices<br>   - FFN weights<br>   - Output weights</pre><p>Unlike older NLP Systems, the embedding matrix and transformer weights co-evolve during training. The embeddings learns semantic meaning and similarity structure. Meanwhile attention learns how to compare words and what relationships matter and FFNs learns higher-level transformations. Everything improves together. The embedding matrix itself becomes specialized for attention. So embeddings evolve to become attention-friendly representations. That is why modern embeddings are incredibly rich.</p><h3>The Math(Skip if you want)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1014/1*S3dOfsD74VpxBiBl6j6RUg.png" /></figure><p>We are predicting the next token after:</p><blockquote><em>“in”</em></blockquote><p>So the Query vector we care about is:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/126/1*zqJq8lt9PDwU3Vbah9PLKQ.png" /></figure><p>This Query asks:</p><blockquote><em>“What previous words are important for predicting what comes next?”</em></blockquote><p>Now the transformer computes similarity scores. It compares: Qin against every previous Key:</p><p>K_{My}, K_{son}, K_{play}, K_{Jenga}, … using dot products.</p><p>Large vector dimensions create huge dot products. So transformers stabilize them by dividing by square root of dk:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*s5qgkCj661nLaNsKqpdFWg.png" /><figcaption>dk = key dimension</figcaption></figure><p>Suppose after stabilization it becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2bA5UwZTejImC_QyaMOceA.png" /></figure><p>Notice something fascinating:</p><ul><li>“Jenga” gets the highest score</li><li>“play” also matters</li><li>“My” barely matters</li></ul><p>The model has mathematically discovered:</p><blockquote>If someone is playing Jenga somewhere… the location probably depends on the game itself.</blockquote><p>But these scores are still raw numbers. We now need to transform them into probabilities. It uses Softmax function to turn scores into Attention Probabilities.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GreIVf_IzUsEPvWtugKbag.png" /></figure><p>Suppose, after applying, softmax it becomes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*e4dciqE8atIOYbKZWYBw3Q.png" /></figure><p>Which means 52% attention goes to &quot;Jenga&quot; 17% goes to &quot;in&quot; 13% goes to &quot;play&quot;.Everything else becomes less important.</p><p>But transformers go even further. They don’t use just <strong>one</strong> attention system. They use <strong>many simultaneously</strong>. This is called Multi-Head Attention.</p><h3>Multi-Head Attention</h3><p>But transformers go even further. They don’t use just one attention system; they employ many simultaneously. This revolutionary concept is called <strong>Multi-Head Attention</strong>.</p><p>Think of it like assembling a diverse team of specialized experts to analyze a problem. Instead of one generalist trying to understand everything, <strong>each “head” is a distinct attention mechanism</strong>, trained to focus on a particular aspect or type of relationship within the input sequence.</p><p>One head might diligently track: <strong>GRAMMAR</strong> (e.g., subject-verb agreement).<br> Another might zoom in on: <strong>PHYSICAL OBJECTS</strong> and their properties.<br> A third could be dedicated to: <strong>LOCATION</strong> and spatial relationships.<br> Yet another might detect: <strong>EMOTIONAL TONE</strong> or sentiment.</p><p>So, when processing “My son loves to play Jenga in the…”, different heads independently discover and emphasize different insights:</p><ul><li><strong>Head 1:</strong> Might heavily weight “Jenga” and understand it as a <em>game</em>.</li><li><strong>Head 2:</strong> Could connect “play” to “Jenga,” grasping the <em>activity</em>.</li><li><strong>Head 3:</strong> Focuses on “in,” identifying its role as a <em>preposition introducing location</em>.</li><li><strong>Head 4:</strong> Might even consider “son” and infer a <em>familiar or domestic context</em>.</li></ul><p>Crucially, after each head has computed its own set of attention weights and generated its unique “perspective” on the context (a weighted sum of Value vectors), <strong>all these diverse insights are then concatenated (joined together) and linearly transformed</strong>. This means the model doesn’t just pick one “best” perspective; it harmoniously blends the wisdom from all its specialists. It’s like having a committee meeting where every expert offers their unique take, and then all those perspectives are integrated into a single, comprehensive understanding.</p><p>This multi-faceted approach is a core reason why modern LLMs feel astonishingly flexible and nuanced. They aren’t relying on a single, rigid train of thought. Instead, they are running many parallel pattern detectors at once, building an incredibly rich and comprehensive contextual understanding. This allows them to capture a vast array of linguistic dependencies — from short-range grammatical links to long-range semantic relationships — all contributing to a more robust and informed prediction.</p><h3>Contextual Meaning Emerges</h3><p>Using transformer architecture, now the model has created a new vector representing:</p><pre>&quot;playing an indoor game at some location&quot;</pre><p>Notice something profound:</p><p>The word &quot;in&quot; by itself has little meaning. But after attention- its representation becomes context-aware. This is the key breakthrough of transformers. Words dynamically change meaning depending on surrounding words.</p><h3>Predict the Next Token</h3><p>The final contextual vector is passed through:</p><ul><li>feed-forward layers</li><li>output projection</li><li>softmax over the vocabulary</li></ul><p>The model computes probability of next word given the input sentence- <em>“My son loves to play Jenga </em><strong><em>in …</em></strong><em>”</em>:</p><p>Output: the — 58%, his — 17%, our — 9%, a — 8%, park — 4%</p><p>Then sampling chooses:</p><blockquote><em>“the”</em></blockquote><h3>Then the Entire Process Repeats</h3><p>Now input becomes:</p><blockquote><em>“My son loves to play Jenga in </em><strong><em>the</em></strong><em>…”</em></blockquote><p>Attention recalculates AGAIN.</p><p>This time:</p><ul><li>Query comes from &quot;the&quot;</li><li>attention shifts slightly</li><li>probabilities change</li></ul><p>Now predictions may become: living — 42% , house — 24%, basement — 10%, kitchen — 9%</p><p>And the model continues generating token-by-token.</p><pre>Tokens<br>   ↓<br>Embeddings from E<br>   ↓<br>Q, K, V projections<br>   ↓<br>Similarity scores<br>   ↓<br>Attention weights<br>   ↓<br>Weighted contextual meaning<br>   ↓<br>Next-token probabilities<br>   ↓<br>Prediction</pre><h3>The “Temperature” Factor</h3><p>When the model calculates the probabilities for the next word (e.g., “living room” — 42%, “house” — 24%, “basement” — 10%, “kitchen” — 9%), it usually doesn’t just pick the absolute highest one every single time. That would make the model very predictable and often boring. This is where the <strong>temperature</strong> parameter comes in.</p><p>Temperature is a hyperparameter that directly influences the “spikiness” or “flatness” of the probability distribution from which the next token is sampled.</p><ul><li><strong>Low Temperature (e.g., 0.1–0.5):</strong> The probability distribution becomes sharper. The highest probability words are even more likely to be chosen, and lower probability words are almost never selected. This makes the model more deterministic, factual, and less prone to “hallucinations” or creative leaps. It’s like heavily loading a dice so it almost always lands on the highest number. As a result — You’ll almost always get “living room” if it’s the top probability.</li><li><strong>High Temperature (e.g., 0.7–1.0+):</strong> The probability distribution becomes flatter. The difference between high and low probability words shrinks, meaning even words with relatively low probabilities have a reasonable chance of being selected. This leads to more diverse, creative, and sometimes surprising outputs, but also increases the risk of nonsensical or less coherent responses. It’s like using a perfectly balanced dice, where every face has a fair chance. As a result — You might get “living room,” “house,” “basement,” or even “park” or “thunderstorm” if its probability isn’t completely zero, depending on the roll of the dice.</li></ul><p>This explains why, when I asked the LLM repeatedly within the same conversation, I got different answers (“the house,” “his room,” “the park”). The model wasn’t necessarily changing its “mind” about the probabilities; rather, it was using a non-zero temperature, which introduced a controlled element of randomness into the selection process each time it generated a word. Each time I asked same question in the same conversation it was changing the overall context too. The underlying probabilities for “living room” might still have been the highest, but with a sufficiently high temperature and a slightly changed context, “his room” or “the park” could also be sampled.</p><p>When I started a fresh conversation, the prompt “My son loves to play Jenga in…” is the <em>entire</em> context. The model processed this specific, unchanging input. If the temperature is low, or if the highest probability is overwhelmingly dominant, I am more likely to get the single most probable answer consistently (“the living room”). The “vibe” is clear and fixed.</p><h3>Conclusion: The Symphony of Numbers, Context, and Controlled Chance</h3><p>From the initial curiosity sparked by a simple sentence — “My son loves to play Jenga in…” — we’ve journeyed deep into the numerical heart of Large Language Models. What emerges is not human-like understanding, but a meticulously engineered <strong>mathematical tapestry</strong> woven from countless calculations, probabilities, and dynamic adjustments.</p><p>We began by questioning why an LLM would seem to “seek context” and why its outputs could be both surprisingly consistent and wildly variable. The answer, as we’ve seen, lies in the elegant interplay of several core components:</p><ul><li><strong>Words to Numbers (Embeddings):</strong> Every piece of language, from individual characters to entire concepts, is first transformed into a dense, multi-dimensional numerical vector. These embeddings aren’t static definitions; they are continuously refined learning representations that capture the semantic “personality” of words.</li><li><strong>The Learning Engine (FFN &amp; Backpropagation):</strong> Through billions of cycles of prediction, error calculation, and backpropagation, the neural network adjusts its weights and refines these embeddings. This is where the raw numbers slowly morph into meaningful relationships, organizing the language into a geometric space where similarity means proximity.</li><li><strong>The Maestro of Context (Attention &amp; Transformer):</strong> The groundbreaking Transformer architecture, powered by Multi-Head Attention, is the true engine of contextual understanding. It allows the model to dynamically “pay attention” to the most relevant parts of the input, weighting their importance based on the current prediction task. This means a word’s meaning is no longer fixed but <strong>fluid and context-dependent</strong>, making the LLM’s responses feel remarkably intelligent.</li><li><strong>The Predictor (Probabilities):</strong> After processing through layers of attention and transformations, the model ultimately generates a probability distribution over its entire vocabulary, indicating the likelihood of each potential next token.</li><li><strong>The Artist’s Dial (Temperature &amp; Sampling):</strong> And here’s where our initial paradox finds its resolution. The <strong>temperature</strong> parameter introduces “controlled randomness.” A low temperature guides the model to select the most probable word, leading to consistent, factual responses. A higher temperature flattens the probability distribution, allowing less probable (but often more creative or surprising) words to be sampled, explaining the variability you observed within an ongoing conversation.</li><li><strong>The Memory Keeper (Context Window):</strong> The finite nature of the context window explains the difference between sessions. A fresh chat provides a pristine, unambiguous prompt. In a prolonged dialogue, the oldest parts of the conversation are eventually truncated, altering the “memory” the model can access, leading to subtly different contextual interpretations and, thus, different predictions.</li></ul><p>Every generated token is the result of this rapid, iterative cycle: input embeddings are processed through complex attention mechanisms, refined by feed-forward networks, converted into probabilities, and then sampled based on the model’s “temperature” and the constraints of its context window.</p><p>So, when an LLM offers “the living room” or “the park,” it’s not “thinking” or “understanding” in the human sense. It’s executing an incredibly intricate, mathematical choreography. It’s identifying the numerical vectors that align best with the contextual vectors it has just computed, filtered through layers of learned relationships, and finally, sampling from a probability distribution.</p><p>The “magic” of modern LLMs isn’t in their ability to understand like us, but in their astonishing capability to <strong>numberify the world, process patterns at an incomprehensible scale, and intelligently guess what number comes next.</strong> It’s a testament to the immense power of algorithms and data, building a statistical mimicry of language so compelling that it often feels like true intelligence.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=128ff17cf68a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>