Velamuvi AIAcademy

Lesson 7 of 12 · How It Works

Training vs Inference

Training builds a model from data; inference uses it to answer. Pretraining, fine-tuning, human feedback, knowledge cutoffs and whether chatting teaches it.

  • 8 min read
  • Beginner
  • Reviewed
In this lesson you will learn
  • The difference between training a model and using it (inference)
  • What parameters are, and why training is so expensive
  • The stages that turn a text predictor into a helpful assistant
  • Why models have a knowledge cutoff, and whether your chats teach the model

Two very different jobs

Every AI model has two phases in its life.

An analogy: training is like years of school and practice; inference is like answering a question in an exam. During the exam you use what you learned, but you do not learn new material.

Parameters: what training changes

The program below trains a model with just one parameter to convert kilometres into miles. It does not know the conversion rule. It starts with a weight of 0 and nudges it after every example, until its guesses match.

Try it yourselfPython
# Examples the model learns from: kilometres -> miles
examples = [(1, 0.62), (5, 3.11), (10, 6.21), (21, 13.05), (42, 26.1)]

weight = 0.0           # the model's only parameter, before training
learning_rate = 0.0005

# ---------- Training: adjust the weight many, many times ----------
updates = 0
for epoch in range(200):
    for km, miles in examples:
        guess = weight * km
        error = guess - miles
        weight -= learning_rate * error * km   # nudge the weight to shrink the error
        updates += 1

print(f"Training finished after {updates} updates")
print(f"Learned weight: {weight:.4f}")

# ---------- Inference: use the frozen weight ----------
for km in [3, 100]:
    print(f"{km} km is about {weight * km:.1f} miles")

Look at the costs. Training needed 1,000 updates. Each inference was one multiplication. The model learned the true rule (1 km is about 0.6214 miles) purely from examples, and it answers for 100 km even though it never saw 100 in training.

Now scale it up. An LLM has billions of parameters instead of one, and is trained on trillions of tokens instead of five examples. Training takes weeks or months on thousands of specialised chips and can cost many millions of dollars. Inference, one forward pass per token, happens in a fraction of a second.

TrainingInference
What it doesSets the parametersUses the parameters
How oftenOnce per model versionEvery request, by every user
TimeWeeks to monthsSeconds
Who does itThe AI companyYou, whenever you use it
Changes the model?YesNo

How a text predictor becomes an assistant

Training a chat model happens in stages.

A pretrained model asked "What is the capital of France?" might continue with "What is the capital of Germany? What is the capital of Spain?", because lists of quiz questions are common on the web. So further stages follow.

  1. Instruction tuning. Fine-tune on example conversations written or checked by people, so the model learns the shape of a helpful answer.
  2. Learning from preferences. People (and other models) compare pairs of answers and say which is better. The model is trained to produce answers more like the preferred ones. This is often called RLHF, reinforcement learning from human feedback.
  3. Safety training. The model learns to decline harmful requests and to be honest about uncertainty.
  4. Reasoning training (for reasoning models). The model practises solving problems with checkable answers, such as maths and code, and is rewarded when its step-by-step working reaches a correct result.

The knowledge cutoff

Because training is so expensive, a model is not retrained every day. Its knowledge is a snapshot. Ask about something that happened after its cutoff and it may say it doesn't know, or worse, guess. Assistants with search fill the gap by finding current pages and putting them into the context window.

Does chatting teach the model?

Not directly. During your conversation the parameters do not change; the model "remembers" earlier messages only because they are in the context window. Close the chat and it is gone from the model.

However, a company may use conversations to train future versions, depending on its policy and your settings. That is a privacy question, covered in the last lesson of this course.

Common mistakes

Practice exercise

Complete the training step, then use the trained weight for inference.

Your solutionPython
examples = [(1, 2.5), (2, 5.0), (4, 10.0)]   # (kilograms, price)
weight = 0.0
learning_rate = 0.05

# Training
for epoch in range(100):
    for kg, price in examples:
        error = weight * kg - price
        # Add the line that nudges the weight, like in the lesson

print(f"Learned price per kg: {weight:.2f}")

# Inference: print the price of 3 kg, like: 3 kg costs 7.50
Knowledge check

You tell a chat assistant a new fact in one conversation. What happens to the model's parameters?

Summary

  • Training sets a model's parameters from examples. It is slow and expensive, and done rarely.
  • Inference uses the fixed parameters to answer. It happens every time you use the model.
  • Chat models go through pretraining, then fine-tuning on conversations, preference training and safety training.
  • Models have a knowledge cutoff; search tools and pasted documents give them newer information.
  • Your chats do not change the model's parameters, but may be used for future training depending on the provider's policy.

Next: why models confidently make things up, and how to protect yourself.

Finished reading? Tick it off to track your progress.