Machine Learning 101 — AI Web

In machine learning, a program finds the rules itself from examples. Training changes a model's parameters (the numbers in its formula, here w and b) step by…

You've just moved to a new city and taken a motorbike taxi five times. Nobody told you the fare. But from those five rides you can guess the rule: so much per kilometre, plus a starting fee. A program can learn the same way. That is machine learning: you don't write the rule yourself, the program finds it from examples, like those five rides. The formula that holds that rule is called a model. Guessing the rule from examples is called training. Using the rule you found for a sixth ride is called inference.

Training: the model finds the rule itself

The Bookshop wants to guess how many copies of a book sell from how many times the book's page was viewed. Here is the data (example numbers for learning, not real sales data):

Views (hundreds), x 1 2 3 4 5
Sold (copies), y 2 3 5 6 8

Our model is just one straight-line formula: prediction = w × x + b. x is the number of views (in hundreds), and prediction is the guessed number of copies sold. The numbers w and b are called parameters (or weights): the numbers inside the model that training changes. In the motorbike taxi fare, w is the price per kilometre and b is the starting fee. Both start at 0.

Training changes w and b bit by bit so the loss gets smaller. The loss measures how far the guesses are from the real answers: for each example, the difference between the prediction and y is squared, then all of them are averaged. This code runs 500 steps of training:

const data = [[1, 2], [2, 3], [3, 5], [4, 6], [5, 8]];
let w = 0;
let b = 0;
const lr = 0.05; // learning rate: how big each step is

function loss() {
  return data.reduce((s, [x, y]) => s + (w * x + b - y) ** 2, 0) / data.length;
}

for (let step = 1; step <= 500; step++) {
  let gw = 0;
  let gb = 0;
  for (const [x, y] of data) {
    const diff = w * x + b - y;
    gw += (2 * diff * x) / data.length; // which way the loss moves if w goes up
    gb += (2 * diff) / data.length; // which way the loss moves if b goes up
  }
  w -= lr * gw; // step the other way so the loss goes down
  b -= lr * gb;
}
console.log(w.toFixed(2), b.toFixed(2), loss().toFixed(2)); // 1.50 0.30 0.06

How training goes, computed for real with the code above:

Step w b Loss
0 0 0 27.6
1 1.74 0.48 0.99
2 1.42 0.39 0.093
10 1.475 0.390 0.0615
200 1.499 0.304 0.0600
500 1.500 0.300 0.0600

The result is prediction = 1.5 × x + 0.3. The loss doesn't reach 0 because the five data points don't lie on a perfectly straight line.

Supervised and unsupervised

Our data has an answer for every example (the Sold row of the table). That answer is called a label. Learning from labelled data is called supervised learning. From data with no labels, say customers' purchase histories with no notes at all, a model can only find patterns on its own. For example, it groups the customers who like historical novels. That is unsupervised learning.

Inference: using a finished model

After training, w and b are frozen: their values don't change any more. For a book viewed 600 times, x is 6, and the guess takes one calculation: 1.5 × 6 + 0.3 = 9.3 copies. That is inference: cheap and fast.

A large language model, the kind of AI model you call over an API, also has these two steps, training and inference, only far bigger. Training it takes a huge amount of text, thousands of GPUs and months of time. The provider does all of that. When you call the API you only run inference: the parameters don't change, and the model doesn't learn from your conversation.

LLM: guessing the next token

An LLM (Large Language Model) is a deep learning model: a neural network, which is a huge formula built from many layers of calculations, with billions of parameters like w and b. An LLM is trained until it can understand and produce language. It works in a loop: look at the text so far, guess the next piece, add it, repeat.

That piece is called a token: a word, part of a word, or a punctuation mark. With OpenAI's tokenizer (a program that splits text into tokens) o200k_base, used by GPT-4o, Is The Rainbow Troops still in stock? becomes 9 tokens: Is The Rainbow Tro ops still in stock ?. Other models may cut a little differently. The word Troops is cut into 2 tokens, while the longer availability is just 1. Text in many other languages often needs more tokens than English, and API costs are counted per token.

Say the text so far is The Rainbow Troops is. The model gives each candidate next token a raw score called a logit. The bigger the logit, the bigger the chance that candidate is picked. This table is an illustration: we made up the logits so the maths can be followed; they don't come from a real model. The percentages are computed for real from those logits:

Candidate Logit Chance (temperature 1)
available 4.0 61.9%
in 3.0 22.8%
still 2.0 8.4%
popular 1.5 5.1%
sold 0.5 1.9%

That 61.9% for available is at temperature 1. The temperature is a setting in the request that decides how boldly the model picks candidates with a small chance. Before you read on, guess: if the temperature goes down to 0.2, what does the chance of available become? Still 61.9%, about 86%, or 99.3%?

Temperature: how boldly to pick

Logits are turned into chances with softmax: a formula that makes all the chances add up to 100%. Before softmax, each logit is first divided by the temperature. This code does it for temperature 0.2:

function softmax(logits, temperature) {
  const z = logits.map((l) => l / temperature);
  const max = Math.max(...z); // subtract the max so Math.exp doesn't blow up
  const e = z.map((v) => Math.exp(v - max));
  const total = e.reduce((a, c) => a + c, 0);
  return e.map((v) => v / total);
}

console.log(softmax([4, 3, 2, 1.5, 0.5], 0.2).map((p) => (p * 100).toFixed(1)));
// [ '99.3', '0.7', '0.0', '0.0', '0.0' ]

The result for three temperatures:

Candidate T = 0.2 T = 1 T = 1.5
available 99.3% 61.9% 48.5%
in 0.7% 22.8% 24.9%
still 0.0% 8.4% 12.8%
popular 0.0% 5.1% 9.2%
sold 0.0% 1.9% 4.7%

At temperature 0.2, available becomes 99.3%. A low temperature makes the top candidate lead even more. A high temperature evens the chances out.

The model doesn't always take the top candidate. It takes a sample according to the chances, like a draw: at temperature 1, available comes out about 6 times in 10, and the rest of the time another candidate does. That is why the same question can get different answers. A low temperature makes answers more consistent, but providers don't promise exactly the same result every time.

As of October 2026, OpenAI's "Using GPT-6" guide says temperature may only be sent when the reasoning effort (a setting for how much the model "thinks" before answering) is none. So a model that is asked to think first doesn't accept temperature. On Claude, API version 2026-10-21 rejects temperature, top_p and top_k (two other settings for picking candidates) with a 400 error on every model. Its migration guide says no other setting replaces the three of them (checked November 2026).

⚠️ Why the loss blows up, and other wrong ideas

TL;DR: In machine learning, a program finds the rules itself from examples. Training changes a model's parameters (the numbers in its formula, here w and b) step by step so the loss (how far the guesses are from the real answers) goes down. From the Bookshop example data (x = hundreds of views, y = copies sold), training gives prediction = 1.5 × x + 0.3, loss 0.06. Inference uses the frozen parameters: 600 views gives 9.3 copies. Supervised learning learns from labelled data (data with the answers), unsupervised learning finds patterns without labels. An LLM is a deep learning model trained on a huge amount of text. It guesses the next token again and again. Text in many other languages often needs more tokens than English. Softmax turns logits (the raw score of each candidate token) into chances after dividing them by the temperature (a setting in the request). A low temperature (0.2) almost always picks the top candidate (99.3%), a high one evens the choice out. The model takes samples (a draw by the chances), so answers can differ. Calling an API is only inference: the model doesn't learn from your conversation.

⚡ Training: the rule is found from examples

Meaning: In machine learning you don't write the rule: the program finds it from examples. The example here is the Bookshop data: a book's page viewed x hundred times, y copies sold. The model is the line formula prediction = w × x + b, with the parameters (numbers that training changes) w and b. Training moves w and b bit by bit so the loss (how far the prediction is from y) goes down, until it reaches prediction = 1.5 × x + 0.3.

⚡ Labelled or not

Guess first: every example in that data has its answer (copies sold, y). Is this supervised or unsupervised learning? A clue: supervised means "guided".

Supervised. The answer in each example is called a label, and learning from labelled data is called supervised learning.

Meaning: When the data has no labels, say purchase histories with no notes at all, a model can only find patterns on its own. For example, it groups the customers who like historical novels. That is unsupervised learning.

⚡ Inference: the parameters are frozen

Meaning: Inference means using a trained model, whose w and b don't change any more (they are frozen). For a page viewed 600 times, x is 6, so the prediction is 1.5 × 6 + 0.3 = 9.3 copies: one calculation. Calling an LLM API is inference too: the model doesn't learn from your conversation.

⚡ Temperature: how boldly to pick

Write:

console.log(softmax([4, 3, 2, 1.5, 0.5], 0.2).map((p) => (p * 100).toFixed(1)));
// [ '99.3', '0.7', '0.0', '0.0', '0.0' ]
Guess first: [4, 3, 2, 1.5, 0.5] are the logits (raw scores) of five candidates for the next token, and the first one is available. The temperature is a setting in the request. At temperature 1, available has a 61.9% chance. If the temperature drops to 0.2, what does it become?

99.3%, as the code's comment shows. Softmax (the formula that turns logits into chances) runs after each logit is divided by the temperature, so a low temperature makes the top candidate lead even more.

Meaning: An LLM writes text by guessing the next token again and again. The model takes a sample according to the chances (like a draw), not always the top candidate. That is why the same question can get different answers.

What you will learn