Machine Learning Fundamentals · Unit 8 of 8
Unit 8: Bias, neural networks and large language models
How bias gets into data, measuring it with per-group metrics, what a neural network is, and how large language models are the same recipe at enormous scale.
Opens the first lesson of this unit in Machine Learning Fundamentals. Every lesson is open from the start.
Lesson 1: Bias in data
Goal: Name the main ways bias enters data and why removing a column does not remove it.
A model learns whatever patterns its data contains, including unfair ones. "Bias" here means a systematic error that disadvantages some group or situation, and it usually enters through the data.
| Kind | What happens | Example |
|---|---|---|
| Historical bias | The data records past unfairness | Past promotions favored one group, so a model learns to favor it |
| Sampling bias | Some groups are missing or rare in the data | A voice assistant trained mostly on one accent struggles with others |
| Label bias | The labels themselves are skewed | "Good employee" labels came from biased reviews |
| Measurement bias | A feature is measured differently across groups | Arrest records used as a stand-in for crime reflect where police patrol |
| Proxy features | A neutral-looking feature stands in for a protected one | A postcode can stand in for ethnicity or income |
Worked example: a documented case
In 2018 the news agency Reuters reported that Amazon had abandoned an experimental recruiting tool after finding that it rated CVs from women lower.
- The model had been trained on about ten years of CVs submitted to the company, most of them from men.
- It learned to penalize signs associated with women, such as the word "women's" in "women's chess club captain".
- Editing the model to ignore such words did not guarantee it would not find other proxies, and the project was dropped.
Nobody told the model to discriminate. It learned the pattern in its data.
Deleting a sensitive column, such as gender or ethnicity, does not remove bias when other features act as proxies for it. The fix starts with measuring, which is the next lesson.
- Bias (in ML)
- Systematic error that disadvantages some group or situation, usually learned from the data.
- Historical bias
- Unfairness from the past recorded in the data a model learns from.
- Sampling bias
- When some groups are missing or under-represented in the data.
- Proxy feature
- A feature that stands in for a sensitive attribute, such as a postcode for income.
Remember: Bias comes in through history, sampling, labels, measurement and proxies. Removing a column is not enough.
Lesson 2: Measuring and reducing bias
Goal: Evaluate a model per group and know the main ways to reduce bias.
You cannot fix what you do not measure. Evaluate a model separately for each group that matters, using the metrics from Unit 5. An overall accuracy of 90% can hide 96% for one group and 75% for another.
Hands-on lab in the room: Confusion matrix and threshold lab. Use one threshold for two groups of job applicants and compare how many qualified people in each group the model finds.
Worked example: per-group metrics
A model screens job applications for interview, with a threshold of 0.5.
- Group A: of 100 qualified applicants, 80 are put forward for interview, a recall of 80%.
- Group B: of 100 qualified applicants, 55 are put forward, a recall of 55%.
- Same model, same threshold, very different chances for equally qualified people.
- Investigation finds that one feature, "gap in employment history", is common in group B for reasons unrelated to ability, such as caring for relatives.
Overall numbers hid an unfair gap that per-group numbers revealed.
- Collect more representative data, and check the labels.
- Remove or fix features that act as unfair proxies.
- Compare per-group error rates before deployment, and keep monitoring them after.
- Keep a person accountable for decisions about people, with a way for people to appeal.
- Document the model: its data, how it was tested and where it should not be used, often in a model card.
- Sometimes the honest answer is not to automate the decision at all.
Fairness has more than one definition, such as equal recall across groups, equal false positive rates or equal approval rates, and they cannot always all be met at once. Choosing one is a values decision that should involve the people affected, not just the data team. Laws in many places also restrict automated decisions about credit, employment and housing.
- Per-group evaluation
- Computing a model's metrics separately for each group of people it affects.
- Model card
- A short document describing a model's data, testing, intended use and limits.
Remember: Measure every metric per group. Fix data and proxies, keep people accountable, and document limits.
Lesson 3: Neural networks
Goal: Compute a neuron's output and explain layers and backpropagation.
A neural network is built from simple units called neurons. Each neuron does something you already know: a weighted sum of its inputs plus a bias, passed through an activation function. With a sigmoid activation, a single neuron is exactly logistic regression.
Worked example: one neuron, by hand
Inputs x₁ = 2 and x₂ = 3; weights w₁ = 0.5 and w₂ = −1; bias b = 1; activation ReLU, which outputs max(0, z).
- Weighted sum: z = 0.5 × 2 + (−1) × 3 + 1 = 1 − 3 + 1 = −1.
- ReLU(−1) = max(0, −1) = 0. The neuron stays silent for this input.
- With x₂ = 1 instead: z = 1 − 1 + 1 = 1, and ReLU(1) = 1.
A neuron is a weighted sum and a simple bend. The power comes from wiring thousands of them together.
Neurons are arranged in layers. The input layer takes the features, one or more hidden layers transform them, and the output layer produces the prediction. Each layer's outputs are the next layer's inputs. Because the activations bend the signal, stacked layers can represent very complicated patterns, and the hidden layers learn useful features by themselves, such as edges and shapes in images, instead of a person designing them. Networks with many layers are called deep learning.
Training uses exactly the ideas from Unit 4: a loss function and gradient descent. Backpropagation is the efficient way to compute the gradient for every weight in every layer at once, working backward from the error at the output. Overfitting, regularization (including dropout), validation sets and learning rates all apply just as before.
- Neural network
- A model made of layers of neurons, each computing a weighted sum followed by an activation.
- Neuron
- A unit that computes a weighted sum of inputs plus a bias, then applies an activation function.
- Activation function
- The bend applied to a neuron's weighted sum, such as ReLU or sigmoid.
- ReLU
- An activation that outputs max(0, z): zero for negative sums, the sum itself otherwise.
- Backpropagation
- The method for computing the gradient of the loss for every weight in a network.
- Deep learning
- Machine learning with neural networks that have many layers.
Remember: Neuron = weighted sum + bias + activation. Layers stack them; backpropagation plus gradient descent trains them.
Lesson 4: How large language models fit in
Goal: Explain an LLM in terms of features, labels, loss, training, overfitting and bias.
A large language model (LLM) is a very large neural network, usually of a design called a transformer, trained on enormous amounts of text. Its core task is one you can now describe precisely: given the text so far, output a score for every possible next token. That is a classification over a vocabulary of tens of thousands of tokens.
| Idea from this course | In a large language model |
|---|---|
| Features | Each token becomes a learned list of numbers, an embedding; similar words get similar embeddings |
| Labels | The next token in real text: the data labels itself, called self-supervised learning |
| Loss | How little probability the model gave the true next token (cross-entropy) |
| Training | Gradient descent and backpropagation over billions of examples |
| Overfitting | Watched with held-out text; models can memorize rare passages |
| Bias in data | The model absorbs stereotypes and gaps present in its training text |
| Evaluation | Test sets of questions and tasks, plus ratings by people |
Worked example: next-token prediction as classification
- Input: "The capital of France is".
- The network scores every token in its vocabulary; turned into probabilities, " Paris" gets 0.92, " a" 0.02, " the" 0.01, and everything else tiny amounts.
- During training, gradient descent would push the probability of the true next token up and the rest down.
- To write text, the model repeats the prediction one token at a time, sampling from those probabilities.
An LLM is the recipe you have learned, data plus a loss plus gradient descent plus evaluation, at enormous scale.
After this pre-training, models are usually fine-tuned: trained further on examples of helpful answers, and adjusted using people's preferences between answers. That is what turns a text predictor into an assistant. Hallucination, a fluent answer that is false, follows from the design: the model is optimized to produce plausible next tokens, and plausible is not the same as true. That is why the evaluation and checking habits from this course matter even more for language models.
- Large language model (LLM)
- A very large neural network trained to predict the next token of text.
- Transformer
- The neural network design used by most large language models.
- Embedding
- A learned list of numbers representing a token or a piece of text, where similar meanings are close together.
- Self-supervised learning
- Learning where the labels come from the data itself, such as the next word in a sentence.
- Pre-training
- The first, large-scale training of a model on general data.
- Fine-tuning
- Further training of a pre-trained model on narrower examples, such as helpful answers.
Remember: An LLM classifies the next token: embeddings as features, the next token as label, gradient descent as training.
Practise it in Machine Learning Fundamentals
Each lesson ends with three questions that check you can use the idea, not just recognise it. Wrong answers explain why and come back in Review. The unit ends with a 6-question quiz; pass it with 80% or more to master the unit. Hands-on lab: Confusion matrix and threshold lab.
Every lesson is free: no ads, no lives and no paywall.