From Raw Text to AI Assistant: How Large Language Models Are Actually Built
You use AI every day — to draft emails, debug code, brainstorm ideas. But how does it actually work under the hood?
Most people have a vague mental model: lots of data + massive compute = smart AI. That’s not wrong, but it’s far too shallow. In reality, building a large language model (LLM) from scratch involves three distinct phases, each solving a completely different problem with different methods. Understanding this process changes how you think about what AI can and can’t do.
Here’s a clear, no-jargon breakdown.
The Big Picture: Three Phases
| Phase | Goal | Key Question |
|---|---|---|
| Pre-training | Learn language patterns and world knowledge | How does the model “understand” text? |
| Post-training (SFT) | Learn to follow instructions and hold conversations | How does the model become an assistant? |
| Reinforcement Learning / Alignment | Produce more helpful, honest, and safe responses | How does the model know what it should and shouldn’t say? |
Phase 1: Pre-Training — Teaching the Model to “Read”
Where the Data Comes From
Pre-training starts with massive data collection. Sources include web pages, Wikipedia, academic papers, books, forum posts, code repositories, and other high-quality text.
But not everything on the internet makes it in. Before training begins, the data goes through heavy filtering and cleaning:
- Remove malicious websites, spam, and low-quality marketing content
- Filter out hate speech, illegal content, and self-harm material
- Strip personally identifiable information
- Deduplicate overlapping or near-identical content
What’s left is a curated corpus that can reach trillions of tokens in scale.
Turning Text Into Numbers
Computers don’t understand words — they work with numbers. Getting from raw text to something a neural network can process takes two steps:
Step 1: Tokenization
Text is split into small units called tokens, each mapped to a numeric ID. A token might be a word, part of a word, a character, or a punctuation mark.
"The weather is great today" → [482, 2910, 318, 1049, 1909] (illustrative)
Step 2: Embedding
Token IDs alone are just cold numbers — they carry no meaning. Embedding converts each token into a vector: a list of numbers that encodes its semantic properties across different contexts.
Take the word “Apple.” It might mean a fruit, or it might mean the tech company. An embedding doesn’t lock it into one meaning. Instead, it expresses the strength of its relationship to concepts like “fruit,” “phone,” “technology,” and “company” — all simultaneously, via a vector.
These relationships aren’t hand-coded. They emerge from training: tokens that appear in similar contexts end up close together in vector space. “Burger” and “fries” cluster near each other; “burger” and “weather forecast” stay far apart.
The Training Loop: Predicting the Next Word
The core task of pre-training is disarmingly simple: predict the next token.
Given “The weather is great,” what comes next? The model outputs a probability distribution — maybe “today” at 60%, “out” at 20%, “for” at 10%, and so on.
The system compares that prediction to the actual next word in the training data. If the model was wrong, the loss function measures how wrong, and backpropagation pushes the model’s parameters in the direction that would have produced a better prediction.
This loop — predict → compare → compute loss → update weights — runs billions of times across the entire corpus.
On the surface it looks like a glorified word-guessing game. But at sufficient scale — enough data, enough parameters, enough iterations — this simple task forces the model to internalize:
- Grammar and syntax across languages
- Factual associations between concepts
- Domain-specific writing styles (medical, legal, technical, conversational)
- Code patterns and mathematical notation
- Basic reasoning structures
What You Get After Pre-Training: A Base Model
The result is a base model: a powerful text predictor that has absorbed a huge amount of language structure and world knowledge.
But it’s not an assistant. It’s more like an internet-text simulator. Ask it “What is 2 + 2?” and instead of answering directly, it might continue in whatever style matches your prompt — encyclopedic if your input looks like Wikipedia, forum-style if it looks like Reddit.
The base model knows a lot. It just doesn’t know how to be useful to you.
Phase 2: Post-Training (SFT) — Turning the Model Into an Assistant
What Supervised Fine-Tuning Does
The most critical step in post-training is Supervised Fine-Tuning (SFT).
Mechanically, it’s the same as pre-training — next-token prediction — but the data is completely different. Instead of raw internet text, the model now trains on curated question-and-answer conversation pairs. Sources include:
- Human experts and professional annotators
- High-quality outputs from existing assistant models, filtered and reviewed
- Multi-turn dialogue datasets, cleaned and reformatted
The coverage is broad: everyday questions, technical topics, coding tasks, writing requests, safety-sensitive scenarios — potentially tens of millions of conversation turns.
Why Changing the Data Changes the Model’s Behavior
Here’s the key insight: the data environment shapes what the model learns to produce.
During pre-training, the model was immersed in raw internet text and learned to write like the internet. During SFT, it’s immersed in high-quality human conversations and learns to respond like a helpful assistant.
The model notices: in this new dataset, the text that follows a question isn’t a rambling Wikipedia entry — it’s a concise, direct, task-oriented response. So its output tendencies shift accordingly.
SFT trains the model to:
- Give short answers to simple questions, without unnecessary padding
- Identify what the user actually wants, not just what they literally asked
- Follow instructions and complete specific tasks
- Avoid dangerous or inappropriate responses
- Communicate in a natural, human-friendly way
One important clarification: the model hasn’t actually “become polite” or “developed emotional intelligence.” It’s doing something more precise — learning to mimic the output patterns of high-quality human conversation. The appearance of helpfulness comes from statistical learning, not genuine understanding.
Phase 3: Reinforcement Learning / Alignment — Teaching the Model Where the Lines Are
Why SFT Isn’t Enough
An SFT model can hold a conversation, but it still falls short of what a reliable assistant needs to do. A good assistant doesn’t just answer questions — it knows:
- What topics to engage with and what to decline
- When to offer solutions and when to first acknowledge emotions
- How to handle sensitive or dangerous requests
For example: if someone asks about methods of self-harm, the model shouldn’t recite medical literature or provide step-by-step details. If someone asks how to hack into a neighbor’s Wi-Fi, it shouldn’t provide instructions for illegal activity. SFT alone doesn’t reliably produce this kind of judgment.
Bringing in Human Feedback
This phase introduces human feedback directly into the training loop. Annotators, safety teams, and domain experts compare multiple model responses to the same prompt and rank them.
Ranking criteria go beyond “which answer is smarter” to include:
- Is it genuinely helpful?
- Is it honest? (Does it admit uncertainty instead of confabulating?)
- Is it safe?
- Does it address the user’s actual need?
Training teams also establish explicit behavioral guidelines for the model:
| Boundary Type | Rule |
|---|---|
| Safety | When a request involves violence, self-harm, or illegal activity, decline rather than risk giving harmful guidance |
| Honesty | When the model doesn’t know something, say so — don’t generate a confident-sounding fabrication |
| Empathy | When a user is in distress, prioritize acknowledgment and support over purely informational responses |
The Reward Model: Scaling Human Judgment
Human annotators can’t score every model output — the volume is too large. The solution is to train a separate reward model on the collected human preference data.
The reward model’s job: predict which response a human would prefer, given a particular prompt. It learns the patterns behind human scoring without needing a human in the loop for every single decision.
With the reward model in place, the pipeline looks like this:
- The assistant model generates multiple responses to a prompt
- The reward model scores each response
- A training algorithm (typically PPO or a similar RL method) adjusts the assistant model’s weights to favor higher-scoring outputs
- Repeat across millions of examples
This is Reinforcement Learning from Human Feedback (RLHF). Over time, the assistant model becomes increasingly likely to produce responses that are helpful, honest, and safe — because those are the responses that score well.
Comparing the Three Phases
| Pre-Training | SFT | RLHF / Alignment | |
|---|---|---|---|
| Data source | Public internet text | Curated Q&A conversation pairs | Human rankings of model outputs |
| Training objective | Predict next token | Imitate high-quality response style | Maximize reward model score |
| What the model learns | Language patterns + world knowledge | How to respond like an assistant | What to say, what to avoid |
| Output | Base model | Conversational model | Deployable AI assistant |
What This Means for How We Think About AI
Today’s AI assistants didn’t start out as assistants. Their development follows a clear arc:
- Pre-training: Absorb trillions of tokens of text, learn the statistical structure of language and knowledge — become a powerful text predictor
- SFT: Immerse in high-quality human dialogue data, learn to respond to instructions — acquire the basic capabilities of an assistant
- RLHF: Use human preference data and reward models to continuously calibrate outputs — become more helpful, more honest, and safer
Understanding this process gives you a more grounded mental model of what AI actually is: not a system that “understands” in the way humans do, but one that has learned extraordinarily precise statistical patterns from human language and behavior — and has been iteratively shaped by human judgment to be more useful.
It also highlights a less obvious truth: the quality of an AI assistant is heavily determined by the quality of its training data, the quality of human feedback, and how carefully the people building it have defined what “good” looks like. The model reflects those decisions at every layer.