AI How LLMs Learn
Table of Contents + β
In the last lesson, you learned AI Tokens and Tokenization. Now let us see how an LLM learns, but only at a simple idea level.
Here is the simple learning flow:
π€ Why Learn the Training Process?
You do not need to train a large model yourself to build AI apps.
Still, you should know the basic story.
- The model sees many examples, like text, code, documents, or question-answer pairs.
- It notices things that appear again and again, like common word order, code shapes, and question-answer formats.
- Later, users send new prompts that the model has not seen in that exact form.
- The model uses those learned examples to write an answer for the new prompt.
But you should understand the broad process because it explains:
- Why models can answer many general questions: They saw many kinds of text during training.
- Why they can still be outdated: Training data stops at some point, so newer facts may be missing.
- Why they may produce biased or wrong output: Training data can contain mistakes, imbalance, or harmful patterns.
- Why chat models feel different: Instruction tuning teaches the model to answer tasks, not just continue text.
Pre-training
The model studies huge amounts of text and code so it can learn how sentences, answers, and code usually look.
Instruction tuning
The model learns to follow tasks like explain, summarize, rewrite, or answer.
Human feedback
People compare answers and mark which one is better. For example, they may prefer the answer that is clearer, safer, and follows the instruction.
π Training Data
An LLM learns from huge collections of text and other data.
Data means examples the model learns from.
Training data can include many kinds of examples:
| Example data | What the model may learn |
|---|---|
| Websites | General writing patterns, explanations, lists, and question-answer style from public web pages. |
| Books | Long-form writing, storytelling, grammar, and structured explanation. |
| Code | Syntax, functions, patterns, comments, and common programming mistakes. |
| Documentation | How tools and libraries are explained. |
| Public datasets | Organized collections of text, labels, or examples. |
| Licensed or curated datasets | Cleaner or safer examples selected carefully. |
The model does not store the data like a normal database. During training, it adjusts internal parameters so it can predict patterns from that data.
So do not imagine the model opening a folder and copying one exact page. It is using learned patterns.
π What the Model Notices from Data
The model notices repeated things at many levels. For example, it sees that questions often need answers, headings often introduce sections, and code functions often have inputs and outputs.
| Signal type | Simple meaning |
|---|---|
| Word and sentence patterns | It learns that some words usually come together, like βmachine learning modelβ or βsend a requestβ. |
| Code syntax patterns | It learns that JavaScript functions, Python loops, and HTML tags follow certain shapes. |
| Question and answer patterns | It learns that a question usually needs a direct answer, then explanation. |
| Document structure patterns | It learns that headings, lists, tables, and summaries have different jobs. |
| Reasoning-like step patterns | It learns that some problems are easier when broken into steps. |
| Style and tone patterns | It learns the difference between formal writing, friendly explanation, short answers, and detailed lessons. |
But remember the important point:
- Seeing the same kind of text many times is not the same as checking whether a fact is true.
- A model may generate something that sounds right because it matches a pattern.
- That is why grounding and evaluation matter later.
π Why Models Feel Different
General model
A base model may only continue text. If you write `The capital of France is`, it may complete the sentence, but it may not politely answer like a chat app yet.
Chat model
ChatGPT, Claude, and Gemini feel conversational because their models are tuned to follow instructions.
Coding assistant
A coding model or assistant is tuned and tested on programming-style tasks.
ποΈ Pre-training
Pre-training is the first large learning phase.
The model sees text and learns to predict missing or next tokens.
Training text |Token prediction task |Parameter updates |Base modelAfter pre-training, the model may know how sentences are usually written, how code is usually shaped, and how many common facts are usually explained.
But it may not yet behave like a helpful assistant.
π Instruction Tuning
Instruction tuning teaches the model to follow tasks.
Examples of instructions:
- βSummarize this paragraph.β The model should not continue the paragraph. It should shorten it into main points.
- βAnswer this question.β The model should focus on the question and reply directly.
- βWrite code for this function.β The model should produce code, not a theory paragraph.
- βReturn JSON in this shape.β The model should follow the exact output format requested by the app.
So the model moves from βcontinue this textβ toward βhelpfully respond to this instructionβ.
Why instruction tuning changes the user experience
A raw pre-trained model may simply continue text.
An instruction-tuned model is more likely to:
- Answer directly: If you ask βwhat is a token?β, it explains tokens instead of continuing your sentence.
- Follow format: If you ask for three bullets, it tries to return three bullets.
- Refuse unsafe instructions: It can avoid requests that are harmful or not allowed.
- Ask for clarification: If your request is unclear, it may ask a follow-up question.
- Behave like an assistant: It tries to be useful in a conversation, not just predict random continuation.
This is why most product APIs use instruction-following or chat-tuned models.
π Human Feedback and Alignment
Human feedback is used to improve behavior.
People or preference systems compare outputs and guide the model toward better responses.
This can help the model:
- Follow instructions more clearly: The model learns which answers users prefer for a task.
- Avoid harmful responses: The training process pushes it away from unsafe outputs.
- Refuse unsafe tasks: It can learn to say no when a request should not be completed.
- Prefer clearer answers: If answer A is confusing and answer B explains step by step, people can mark answer B as better.
Alignment is about behavior
Alignment means shaping the model so its outputs better match human intent, safety rules, and product goals. It does not make the model perfect.
β οΈ Why Models Still Make Mistakes
Even after training and alignment, mistakes happen.
- It predicts likely text, not guaranteed truth: A likely sentence can still contain a wrong fact.
- Training data may be incomplete or outdated: The model may not know newer information.
- The prompt may be unclear: If the question is vague, the answer can go in the wrong direction.
- Private context may be missing: The model does not know your companyβs documents unless the app provides them.
- The task may need a tool: Current weather, prices, inventory, or account details need live lookup.
βοΈ Training vs Fine-Tuning vs RAG
These three are different, okay?
- Training from zero creates a base model. This is expensive and rare for normal teams.
- Fine-tuning adjusts a model for a specific behavior or domain.
- RAG does not train the model. It retrieves information and adds it to the current prompt.
For many business apps, RAG is the first choice because documents change often.
This is why later lessons talk about hallucinations, RAG, tools, and evaluation.
π§© What Youβve Learned
- β LLMs are trained on many examples before users ask questions.
- β Instruction tuning teaches a model to respond like an assistant, not just continue text.
Check Your Knowledge
Test what you learned. Pick an answer for each question, then click Check.
- 1
What is pre-training mainly about?
Why: Pre-training teaches the model broad language patterns through token prediction tasks.
- 2
Why is instruction tuning useful?
Why: Instruction tuning improves the model's ability to respond to instructions.
- 3
Does alignment make a model perfect?
Why: Alignment helps guide behavior, but applications still need checks.
- 4
Why can a trained model be outdated?
Why: A model's learned knowledge depends on the data and time period used during training.
π Whatβs Next?
When we write βMy laptop is not chargingβ, the model must understand that the problem is about the laptop. Attention helps it focus on the right words, and a transformer is the structure that uses attention to process the text. Next, let us understand transformers and attention.