LLM Fundamentals: How Large Language Models Actually Learn, Think, and Speak¶
A Step-by-Step Guide from a Child Learning Language to Transformers, Next-Token Prediction, and ChatGPT¶
"When you ask ChatGPT, Claude, or Gemini to explain a medical report, debug Python code, or translate an email from English to Hindi, it replies in seconds like a knowledgeable human friend.
Nobody sat down and typed 10 billion
if-elserules into the computer. So how did a machine made of silicon chips learn to read, reason, and write in almost any language on Earth?"
In our previous guide (From Words to Vectors), we saw how a computer chops a single sentence into Tokens and turns those tokens into coordinate numbers called Embeddings.
In this guide, we will zoom out and understand the engine itself—the Large Language Model (LLM)—in 7 clear, visual steps:
- What is an LLM? How a human child growing up mirrors how an AI model learns from text.
- Breaking Down "Large • Language • Model": What "70 Billion Parameters", Dense vs. MoE, and connection pathways actually mean in plain English.
- Decoding G - P - T: What Generative, Pre-Trained, and Transformer really do under the hood.
- Why Transformers Changed Everything: How Self-Attention solved the memory bottleneck of older AI models.
- How an LLM Speaks: The Next-Token Prediction Loop and the Temperature Dial.
- How a Raw Model Becomes a Helpful Assistant: The 3 stages of training (Pre-Training ➔ SFT ➔ RLHF) inside AI labs before release.
- Two Golden Rules When Using LLMs: Why models Hallucinate (and how RAG fixes it) and how the Context Window working desk operates.
Step 1: What is an LLM? (A Child Growing Up vs. Training an AI)¶
Think about how a human child learns to speak.
When a baby is born, they don't start with an Oxford Dictionary or a grammar textbook pre-installed in their brain. Instead, they learn through three natural stages:
- The Listening & Reading Phase: Over years of childhood, a child listens to parents talking at the dinner table, hears stories, reads books, and watches how people react.
- Spotting Patterns: Without memorizing grammar formulas, the child's brain notices patterns—for example, whenever someone says "Thank you!", the most natural reply is "You're welcome!".
- Speaking Naturally: As an adult, when someone asks you a brand-new question, you don't look up a rulebook. You form a reply based on all the patterns and context you absorbed growing up.
An LLM develops in the exact same way:
Instead of hard-coding grammar rules, engineers feed an LLM billions of written sentences from books, articles, Wikipedia, and websites. By analyzing how humans use words across trillions of examples, the model builds an internal map of language, facts, and logic.
Step 2: What Do the Three Words "Large Language Model" Actually Mean?¶
People throw the acronym LLM around every day, but each of the three words has a specific meaning:
1. Large (Two Things Are Huge: The Library & The Brain Dials)¶
- Massive Training Data: Modern LLMs read between 1 trillion and 15+ trillion words during training—the equivalent of reading millions of books non-stop—spanning stories, science papers, documentation, and conversations.
- Billions of Parameters (Weights): You will often hear names like "Llama-3 70B" or "8B parameters". What is a parameter?
Everyday Analogy: The Mixing Board with 70 Billion Dials
Imagine a music studio soundboard covered in 70 billion tiny volume knobs (called parameters or weights).
* At the start of training, every knob is set to a random number, so the model outputs complete gibberish.
* Each time the model practices predicting a word and gets it slightly wrong, it nudges a few million knobs slightly left or right.
* After reading trillions of sentences, those 70 billion number dials settle into the exact positions that capture human language, facts, and coding logic!
[!IMPORTANT] Do These 70 Billion Knobs Turn Every Time You Ask ChatGPT a Question? No! Once training is finished, all 70 billion knobs are 100% LOCKED (frozen) in place.
* During Training (In the AI Lab): Engineers spend months tuning the 70 billion knobs on supercomputers. When training is done, the knobs are locked.
* During Chatting / Inference (When You Use ChatGPT): Not a single knob moves! Your question (converted into numbers) simply flows through those 70 billion locked knobs—just like music flowing through a mixing board whose dials are already set—to calculate the next word in milliseconds.
🏥 How Are Those Billions of Parameters Organized? (Dense vs. Mixture-of-Experts / MoE)¶
When you look at modern AI models, you will notice two different ways engineers organize those billions of parameter knobs: Dense Models and Mixture-of-Experts (MoE) Models.
The easiest way to understand the difference is the Hospital Analogy:
1. A "Dense" Model (One Giant Brain That Wakes Up for Every Word)¶
- The Hospital Analogy: Imagine walking into a hospital with a broken bone, and instead of sending you to a bone specialist, all 100 doctors in the entire hospital (the heart surgeon, eye doctor, dentist, skin doctor, and pediatrician) crowd into your room and examine you for every single question you ask!
- In AI (e.g., Llama-3 70B / 405B): The model is one single giant block of parameters. Every time it predicts 1 single word (even a tiny word like
"the"), 100% of all 405 billion parameters must wake up and do math. - The Catch: Making a Dense model 10× bigger makes it 10× slower and 10× more expensive for every single word it speaks!
2. An "MoE" Model — Mixture-of-Experts (A Smart Router + Specialist Mini-Brains)¶
- The Hospital Analogy: At the front desk sits a fast Triage Nurse (The Smart Router). Behind the desk sit 8 Specialist Doctors (The Experts):
- Expert 1: Python & Coding
- Expert 2: Creative Writing & Poetry
- Expert 3: Math & Logic
- Expert 4: History & Geography When you walk in with a Python bug, the Router glances at your question and says: "Send this to Expert 1 (Coding) and Expert 3 (Logic)! Let the other doctors sleep!"
- In AI (e.g., Gemini, GPT-4, DeepSeek-V3): The model might have 671 Billion TOTAL parameters divided into dozens of specialist Experts, but for each word, the Router wakes up only 37 Billion ACTIVE parameters!
- The Superpower: You get the vast knowledge of a 671B giant brain, at the speed and low cost of a small 37B model!
| Feature | Dense Model (e.g. Llama-3 70B, Gemma 27B) | Mixture-of-Experts / MoE (e.g. Gemini, DeepSeek-V3) |
|---|---|---|
| How It's Built | 1 single giant block of parameters | Many smaller "Expert" blocks + a Smart Router |
| What Fires Per Word? | 100% of parameters fire on every word | Only 5% – 15% of parameters fire on each word |
| Speed & Cost | Gets slower and costlier as total size grows | Blindingly fast even when total size is 500B+ |
| Published Examples | GPT-3: 175B • Gemma 3: 27B • Llama 3.1: 8B, 70B, 405B |
DeepSeek-V3 / R1: 671B Total (only 37B Active per token!) |
(Note: Proprietary frontier cloud models like Google DeepMind's Gemini and Anthropic's Claude do not publicly disclose their exact parameter counts for competitive reasons, while open-weight models like Llama, Gemma, and DeepSeek publish their exact numbers).
2. Language (More Than Just English)¶
Because any structured system of symbols follows patterns, an LLM doesn't just learn English: * Human Languages: English, Hindi, Spanish, French, Japanese, and 100+ others. * Computer Code: Python, JavaScript, SQL, C++, Rust. * Structured Formats: Math equations, JSON, Markdown tables, and even protein sequences in biology.
3. Model (A Pattern-Predicting Engine, Not a Database)¶
An LLM does not store a giant zip file of Wikipedia articles inside itself to copy-paste from. Instead, the Model is a mathematical neural network (a giant formula made of those billions of parameter dials) that takes your input words and calculates what words should logically come next.
Wait—If It Doesn't Keep a Zip File of Wikipedia, How Does It Know the Answer to My Question?
Think about your own brain! If someone asks you "What is the capital of India?", you instantly say "New Delhi"—even though you don't carry a school geography book inside your head to pressCtrl + Fon.How? By storing facts as connection strengths (pathways)!
1. During Training: Every time the LLM reads a sentence containing"capital","India", and"New Delhi"together (over 50,000+ times across the web), it turns the parameter knob connecting["capital" + "India"] ➔ ["New Delhi"]all the way UP (0.99), while turning the knobs for"Tokyo"or"Banana"down to0.00. When training finishes, the raw Wikipedia files are thrown away—only the knob settings are kept!
2. When You Ask a Question: When you type "What is the capital of India?", the mathematical signal flows straight down the strongest locked pathway (0.99) and lights up"New Delhi"!
Step 3: What Does "GPT" Stand For?¶
Even if you have never written a line of AI code, you have used a GPT model—whether summarizing a PDF, translating English to French, or chatting with ChatGPT.
GPT stands for Generative Pre-Trained Transformer:
| Letter | Term | What It Means in Plain English | Real Example |
|---|---|---|---|
| G | Generative | Unlike Google Search (which only finds existing web pages), the model generates brand-new text word by word on the spot. | Asking it to write a bedtime story about a database engineer who opens a chai stall on Mars. |
| P | Pre-Trained | The model has already been educated on a massive library of books, articles, and code before you ever ask it your first question. | Like hiring a graduate who has already spent 15 years in school reading general knowledge, ready to help on Day 1. |
| T | Transformer | The neural network architecture (invented by Google researchers in 2017) that looks at all words in a sentence at once to understand how they relate. | Knowing whether the word "bank" means a river bank or an ICICI Bank account based on the surrounding words. |
Step 4: Why the "Transformer" Changed Everything (Self-Attention)¶
To appreciate why LLMs suddenly became so smart after 2017, let's look at how older AI models read text—and why they struggled.
The Old Way (Before 2017): Reading Word-by-Word Through a Straw¶
Older language models—called RNNs (Recurrent Neural Networks) and LSTMs (Long Short-Term Memory networks)—read a sentence strictly one word at a time from left to right, passing a tiny summary note from one word to the next:
The Two Fatal Flaws:
1. It Couldn't Look Ahead: When reading left-to-right, the moment the model hit the word "bank", it hadn't seen "deposit money" yet—so it didn't know if Alex was at an ICICI Bank branch or a muddy river bank!
2. It Forgot the Beginning: Just like playing a game of "Telephone" down a line of 50 people, by the time the model reached the end of a long paragraph, the early words had faded from its memory!
The Breakthrough (2017): The Transformer & "Self-Attention"¶
In 2017, researchers introduced the Transformer architecture with a superpower called Self-Attention.
Instead of reading one word at a time in a slow line, a Transformer looks at every word in the sentence simultaneously and shines direct "spotlight beams" between words that explain each other's meaning!
🔍 Concrete Example: Which "bank" Did Alex Visit?¶
Suppose you ask an AI to translate these two sentences from English into Hindi, Telugu, or French (where a Financial Bank and a River Bank are two completely different words!):
- Sentence A: "Alex went to the bank to deposit his money."
- The letters
b-a-n-kby themselves are ambiguous. - When the Transformer processes
"bank", its Self-Attention spotlight scans the whole sentence at once, spots"deposit"and"money", and links them together ➔ 🏦 Financial Bank (Money & Accounts)! - Sentence B: "Alex sat on the bank watching the water in the river."
- The exact same word
"bank"scans the sentence, spots"water"and"river", and shifts its meaning ➔ 🌊 River Bank (Shoreline)!
Because Self-Attention processes all words in parallel on modern GPUs and connects related clues across an entire page, it unlocked the ability to train massive models on trillions of words.
Step 5: How an LLM Actually Speaks (The Next-Token Loop)¶
Here is the most important secret about how Large Language Models work:
An LLM never writes a full paragraph or sentence in one shot.
At its core, an LLM only knows how to do one single job: given a sequence of words, predict the single next token!
Tracing One Loop Step-by-Step:¶
Suppose you type:
- Pass 1: The LLM processes
"The capital of France is"through its Transformer layers and assigns a probability score to every token in its vocabulary: "Paris"➔ 94%"known"➔ 3%"beautiful"➔ 1%- Pick the Winner: The model selects
"Paris". - Loop Back (Autoregressive Step): Now the model glues
"Paris"onto the end of your prompt and feeds the entire updated sentence back into itself for Pass 2: - Repeat Until Done: When you see ChatGPT streaming words across your screen one by one, you are literally watching this Next-Token Prediction Loop run dozens of times per second until the model outputs a special
[STOP]token!
🎛️ What is "Temperature"? (The Creativity Dial)¶
When the model calculates probabilities for the next word (e.g., "Paris" = 94%, "known" = 3%, "beautiful" = 1%), how does it choose which one to pick?
That is controlled by a setting called Temperature (usually between 0.0 and 1.0):
| Temperature Setting | How It Picks the Next Word | Best Used For |
|---|---|---|
Temperature = 0.0 (Strict / Focused) |
Always picks the #1 highest-probability word every single time. Zero randomness. | Coding, SQL queries, math, data extraction, factual Q&A. |
Temperature = 0.7 – 1.0 (Creative / Varied) |
Gives the #2 and #3 words a fair chance of being picked, making responses fresh and varied. | Creative writing, brainstorming names, poetry, storytelling. |
Step 6: How a Raw "Internet Reader" Becomes ChatGPT (The 3 Training Stages)¶
Here is a surprising fact: if you spend $50 million training a Transformer on the entire internet (Pre-Training), the resulting model—called a Base Model—is actually terrible at answering questions!
Why? Because a Base Model only learned to complete documents.
If you ask a raw Base Model:
You: "How do I bake a chocolate cake?"
The Base Model might think it is reading a list of quiz questions on a webpage and reply:
Raw Base Model: "How do I bake a vanilla cake? How do I bake brownies? Click here to subscribe to our cooking newsletter!"
To turn a raw "document completer" into a helpful, polite AI assistant like ChatGPT or Claude, engineers put the model through three distinct stages of schooling:
Stage 1: Pre-Training (Reading the World's Library)¶
- What happens: The model reads trillions of words of raw text from books, articles, and code, practicing next-token prediction.
- What it produces: A Base Model with vast world knowledge and language fluency, but no sense of how to act as an assistant.
Stage 2: Supervised Fine-Tuning — SFT (Learning from Teacher Examples)¶
- What happens: Human domain experts write ~100,000 high-quality demonstrations of
User Question ➔ Ideal Assistant Answer. The model is trained on these conversations so it learns: "When a human asks a question, my job is to answer it step-by-step, not just ramble on!" - What it produces: An Instruct Model that follows user instructions.
Stage 3: RLHF — Reinforcement Learning from Human Feedback (Polishing & Safety)¶
- What happens: The model generates two different answers (Reply A and Reply B) to the same prompt. Human reviewers give a Thumbs-Up 👍 to the reply that is clearer, more accurate, and safer, and a Thumbs-Down 👎 to replies that are rude, unhelpful, or dangerous.
- What it produces: The final Aligned Assistant (like ChatGPT, Claude, or Gemini) that is helpful, well-formatted, and safe for everyday users.
[!IMPORTANT]
Where and When Do All 3 Stages Happen? (Inside AI Labs Before Market Release!)¶
All three stages (Pre-Training ➔ SFT ➔ RLHF) happen entirely inside the AI labs (OpenAI, Anthropic, Google DeepMind, Meta) months before the model is ever released to the market!
Stage Where It Happens Time & Cost What Happens at the End 1. Pre-Training Inside the AI Lab's GPU superclusters (10,000+ GPUs) 2 to 6 months ($50M–$100M+) Produces the raw Base Model 2. SFT (Supervised Fine-Tuning) Inside the AI Lab (using ~100,000 expert Q&A pairs) A few days to 2 weeks Teaches the model how to answer questions ( User:/Assistant:)3. RLHF (Alignment & Safety) Inside the AI Lab (human reviewers grade pairs of replies) 1 to 3 weeks All parameter knobs are 100% locked/frozen and the model is released to the market! By the time Alex opens ChatGPT or Claude on launch day, all 3 stages are already finished. None of these training steps run while you are chatting—your prompt simply flows through the finished, frozen model!
Step 7: Two Golden Rules to Remember When Using LLMs¶
Because of how LLMs are built, they have two natural quirks every developer and user should understand:
1. Why Do LLMs "Hallucinate" (Make Things Up)?¶
Remember Step 5: an LLM is a Next-Token Probability Engine, not a factual database lookup.
* If you ask about a famous fact ("What is the capital of France?"), the model has seen "Paris" thousands of times in training, so its probability is 99%.
* But if you ask about a private company policy or an obscure event it never saw in training, the model still tries to string together words that sound statistically convincing—which can result in a confident, grammatically perfect, completely made-up answer (called a Hallucination).
* How Engineers Fix This (RAG): Instead of relying on the model's memory alone, engineers paste the relevant company document directly into the prompt ("Using only the document below, answer the user's question"). This technique is called RAG (Retrieval-Augmented Generation).
2. What is the "Context Window"? (The Sticky-Note Working Desk)¶
Remember from Step 2 that once an LLM is released, its 70 billion brain knobs are 100% frozen. Because its brain is frozen, the LLM actually has zero memory between messages!
Wait—if the model has no memory between messages, how does ChatGPT remember what Alex told it 2 minutes ago? * The Secret: Every single time Alex sends a new message, the chat app secretly re-sends the entire conversation history from the very beginning back into the model all over again! * The Context Window is simply the maximum number of tokens (words) the model can fit on its "short-term working desk" in a single turn. Everything you type, every PDF you upload, and every reply the AI writes all sit on this desk together. * If a conversation grows longer than the Context Window, the oldest messages fall off the left edge of the desk and the model completely forgets them!
Step-by-Step Example: Alex and the 3-Slot Desk¶
Imagine a tiny LLM whose Context Window desk can only hold 3 messages at a time:
- Turn 1 (1 / 3 Slots Used):
- Alex types: "Hi! My name is Alex and I am allergic to peanuts."
- Desk holds:
[Msg 1: Name = Alex, Peanut Allergy] - Turn 2 (2 / 3 Slots Used):
- Alex types: "Give me a quick breakfast idea."
- Desk holds:
[Msg 1: Name = Alex, Peanut Allergy]+[Msg 2: Oatmeal with berries] - Turn 3 (3 / 3 Slots Used — Desk is 100% FULL!):
- Alex types: "Explain how Python lists work."
- Desk holds:
[Msg 1: Name = Alex, Peanut Allergy]+[Msg 2: Oatmeal]+[Msg 3: Python lists] - Turn 4 (Desk Overflows — Msg 1 Falls Off the Edge! 💥):
- Alex types: "Now suggest an evening snack for me, and remind me what my name is."
- Putting Msg 4 onto the 3-slot desk pushes Msg 1 right off the edge!
- Desk now holds: ~~
[Msg 1]~~ (Forgotten!) ➔[Msg 2: Oatmeal]+[Msg 3: Python lists]+[Msg 4: Snack & Name?] - AI replies: "How about a peanut butter sandwich? Also, you haven't told me your name yet!" 😱
How Big Are Real Frontier Context Windows Today?¶
Modern frontier models have expanded their working desks from a few pages to entire book libraries and codebases (1 token ≈ ¾ of an English word):
| Frontier Model | Context Window Size (Tokens) | Maximum Output | How Much Fits on the Desk at Once? |
|---|---|---|---|
| GPT-6 Astra (OpenAI) | 1.05M tokens | 128K tokens | ~800,000 words (~10 full books of text, PDFs, and code) |
| Gemini 4 Argon (Google) | 1,048,576 tokens (~1.05M) | Up to 1,048,576 tokens (with long decode) | ~800,000 words (~10 books, hours of video/audio, or an entire codebase) |
| Claude Opus 5.5 (Anthropic) | 1M tokens | 128K tokens | ~750,000 words (~10 full books or hundreds of PDFs and code files) |
| Claude Sonnet 5.5 (Anthropic) | 1M tokens | 128K tokens | ~750,000 words (~10 full books or hundreds of PDFs and code files) |
[!TIP] Both Input AND Output (Plus "Thinking" Tokens) Share the Desk!
Every word Alex types, every file Alex attaches, every internal reasoning step the model takes, AND every word the AI replies with all sit on the exact same desk. OncePrompts + Files + AI Replies > Context Window Limit, the earliest messages slide off the edge!
Summary Cheat Sheet: LLM Fundamentals at a Glance¶
| Core Concept | Everyday Analogy | What It Actually Is in AI |
|---|---|---|
| LLM (Large Language Model) | A well-read adult who absorbed patterns from thousands of books | A neural network trained on trillions of words to understand and generate text |
| Parameters (Weights) | Billions of tiny tuning knobs on a studio mixing board | The learned numbers inside the neural network (e.g., 8B, 70B) adjusted during training and frozen in production |
| Dense vs. MoE | Calling every doctor in a hospital vs. a triage nurse routing to 2 specialists | Dense activates 100% of parameters per token; MoE activates only a small subset (e.g., 37B of 671B) |
| Transformer & Self-Attention | Looking at a whole page and highlighting words that connect to each other | The 2017 architecture that processes all tokens in parallel and links related words (like "bank" ➔ "money" or "river") |
| Next-Token Prediction | Playing "guess the next word" in a loop, one word at a time | How an LLM generates replies: scoring the vocabulary, picking 1 token, appending it, and repeating |
Temperature (0.0 vs 0.8) |
A strict accountant (0.0) vs. a creative poet (0.8) |
Controls whether the model always picks the #1 most likely token or explores creative alternatives |
| Pre-Training ➔ SFT ➔ RLHF | Reading a library ➔ Practicing Q&A worksheets ➔ Coaching with feedback | The 3 training stages completed inside AI labs before market release |
| Context Window | A short-term working desk with limited space for sticky notes | Maximum tokens (e.g., ~1M+ tokens in GPT-6 Astra, Gemini 4 Argon, and Claude 5.5) the model can read at once before oldest messages fall off |
| Hallucination | A student bluffing a confident-sounding answer on an exam | When an LLM predicts plausible-sounding words that are factually untrue |
What's Next?¶
Now that you understand both how text becomes vectors (Chapter 0) and how an LLM learns, attends to context, and predicts tokens (Chapter 1), our upcoming guides will dive deeper into Prompt Engineering, RAG (Retrieval-Augmented Generation), and AI Agents!