Module 1 · The big picture: AI, machine learning, deep learning, and TrayCheck
Time: about 4 hours, including the lab · Lab: python course/labs/lab01_first_look.py
You need: nothing. This module assumes no maths beyond arithmetic. Where an idea is explained properly in a later module, the text says so and tells you what to picture for now.
By the end you can:
- explain, with an example you worked through yourself, what machine learning is: what people write, what the data decides, and how the result is judged;
- say why some tasks can't be solved by writing rules, and why a photo is one of them;
- explain how a model can output a category, and how it is told it was wrong;
- explain what a feature is, and what deep learning learns that older methods didn't;
- define AI, machine learning and deep learning by what each one adds, and place each part of TrayCheck in that picture;
- describe TrayCheck's model precisely: input, output, parameters, training, and how it was measured.
Why this matters for the internship
The ISS role asks for "an understanding of fundamental machine learning concepts, including training and testing data, model accuracy, pattern recognition and predictive analytics". You won't build the vendor's model; you'll help judge it. Judging a model starts with being precise about what it is, what it learned from, and what its accuracy does and doesn't tell you.
Here is TrayCheck described precisely, in one breath. Right now some of the words will be new. By the end of this module, every one of them will be.
"It maps a 96 × 96 colour photo to a probability for each of four dishes. It's a MobileNetV2 network pre-trained on ImageNet: I trained a new output layer on 400 labelled photos, then fine-tuned its last 20 layers, by minimising cross-entropy. On 160 photos it never saw during training, it named the right dish 142 times: 88.75%."
1. The map: three words, one picture
Before building each idea, here is where they all sit:
Artificial intelligence the GOAL: systems that choose good outputs or actions
└─ Machine learning one METHOD: the input → output rule is chosen by fitting it to examples
└─ Deep learning machine learning where the model also learns which
measurements of the input matter, using many layers ◄ TrayCheck
Each ring is a special case of the one around it. All deep learning is machine learning; all machine learning is a way of building AI. The reverse is not true: plenty of AI involves no learning (§6), and plenty of machine learning isn't deep (§5).
The rest of this module builds these ideas from the inside out of everyday programming: first rules written by people (§2), then rules fitted to examples (§3–§4), then models that also learn what to look at (§5), then the wider goal that all of them serve (§6).
2. Rules written by people, and where they run out
A program is a rule
An ordinary computer program is a rule that a person wrote down exactly. TrayCheck contains one:
If the predicted dish is not on today's menu, flag the tray for a person to check.
This rule is perfect for its job. It is easy to state, easy to test, and does exactly what it says. Most software in the world is rules like this. When you can write the rule, write the rule.
Some rules can't be written down
Now try to write the rule for "is this photo bibimbap?" To do that, you first need to know what a photo is to a computer.
A photo is a grid of numbers. A digital image is divided into tiny squares called pixels. Each pixel's colour is stored as three numbers: how much red, green and blue light it contains, each from 0 (none) to 255 (full). A pure red pixel is (255, 0, 0); white is (255, 255, 255); a dark brown might be (90, 50, 20). These three layers of numbers are called the image's colour channels.
A tiny 2 × 2 image is therefore 2 × 2 × 3 = 12 numbers. TrayCheck shrinks every photo to 96 × 96 pixels, so each photo reaches the model as 96 × 96 × 3 = 27,648 numbers. That list of numbers is all the model ever sees.
Now attempt the rule. "If pixel (40, 52) is reddish and pixel (41, 52) is white…" fails at once:
- The same dish gives completely different numbers. Move the camera a few centimetres and every pixel now shows something else. The bowl that was at pixel (40, 52) is now at (47, 58). Change the lighting and every number shifts. Change the bowl, the portion, the angle, the garnish, and there is no fixed pattern of numbers left to point to.
- Different dishes can give similar numbers. Ribs and bread pudding are both brown and glossy. At the level of individual pixel values they overlap heavily.
- You can't say how you do it yourself. You recognise bibimbap instantly, but you can't list the steps your eyes and brain take. There is nothing to write down.
This is the situation machine learning exists for: a task where examples of the right answer are easy to collect, but the rule that produces them is impossible to write. Anyone can label 640 food photos. Nobody can write the function from 27,648 numbers to a dish name.
3. Machine learning, worked by hand
The idea is easiest to see on a problem small enough to do on paper. Leave photos aside for a moment.
The problem
A hospital kitchen wants to predict how many meals to prepare for a ward, from the number of patients on it. Here are four past days:
| Day | Patients | Meals actually needed |
|---|---|---|
| 1 | 10 | 14 |
| 2 | 20 | 23 |
| 3 | 30 | 35 |
| 4 | 40 | 44 |
These pairs (an input and the correct output) are examples, also called labelled data: each input comes with its correct answer, the label.
Step 1: choose a family of rules (the model)
Looking at the table, "meals goes up steadily with patients" seems a fair guess. So write a rule with two blanks:
w is "meals per patient" and b is a fixed extra (spares, staff meals). This is not one rule; it is a family of rules, one for every choice of w and b. The family is called the model. The blanks w and b are its parameters. A person chose this family. A person could have chosen a different one.
Step 2: choose a way to score a rule (the loss)
To compare rules, you need a number that says how wrong a rule is on the examples. A simple choice: for each day, how far off was the prediction (ignoring whether it was too high or too low), then average. This is the average miss. A formula that scores wrongness like this is called a loss: lower is better. A person chose this too.
Step 3: search for the best parameter values (training)
Try some values of w and b:
| Rule | Predictions for days 1–4 | Misses | Average miss |
|---|---|---|---|
| A: w = 1, b = 0 | 10, 20, 30, 40 | 4, 3, 5, 4 | 4.0 |
| B: w = 1, b = 4 | 14, 24, 34, 44 | 0, 1, 1, 0 | 0.5 |
| C: w = 1.2, b = 0 | 12, 24, 36, 48 | 2, 1, 1, 4 | 2.0 |
| D: w = 0.8, b = 7 | 15, 23, 31, 39 | 1, 0, 4, 5 | 2.5 |
Rule B fits the past days best. (A computer search over thousands of values of w and b finds nothing better.) Choosing parameter values by making the loss as small as possible on the examples is called training, or fitting the model. The examples used for it are the training data.
Trying values one by one is fine for two parameters but hopeless for millions. Real training uses a smarter search, gradient descent: from the current values, work out which small change to each parameter would lower the loss, make that change, and repeat (Module 2 §5 does it by hand). The procedure that does the searching is called the optimiser. A person chose that too.
Step 4: check the rule on days it has never seen (testing)
Rule B was chosen because it fits days 1–4. That makes its 0.5 average miss on those days an optimistic measure: of course it fits the data it was chosen to fit. The real question is whether it works on new days. So, before training, two more days were held back and not used at all:
| Day | Patients | Rule B predicts | Actually needed | Miss |
|---|---|---|---|---|
| 5 | 25 | 29 | 28 | 1 |
| 6 | 35 | 39 | 40 | 1 |
Average miss on unseen days: 1.0, twice the 0.5 on the training days. That gap is normal and is the reason the score on training data can't be trusted. The held-back examples are the test data, and the score on them is the honest measure of how the rule will do in use.
Why not just memorise?
Here is a "model" that scores perfectly on the training days: a lookup table. "10 patients → 14 meals; 20 → 23; 30 → 35; 40 → 44." Average miss on days 1–4: zero. But ask it about 25 patients and it has no answer, because 25 isn't in the table. It memorised; it didn't learn anything that carries over.
The goal of machine learning is never to fit the examples. It is to do well on new inputs of the same kind, which is called generalisation. Fitting the examples is only the means. This is why every model is judged on test data it never trained on.
What you just did is machine learning
Every supervised machine learning project has the same five parts you just used:
| Part | What it is | In the meals example | In TrayCheck |
|---|---|---|---|
| Data | Examples: inputs with correct answers | 4 training days + 2 test days | 640 labelled photos (400 training, 80 validation, 160 test) |
| Model | A family of rules with parameters left open | w × patients + b (2 parameters) | MobileNetV2 + a new head (about 2.4 million parameters) |
| Loss | A score for how wrong a rule is | Average miss | Cross-entropy (§4) |
| Optimiser | A search for the parameter values with the lowest loss | Trying values by hand | Gradient descent (the Adam version), 32 photos at a time |
| Test | Measuring on examples never used for training | Average miss 1.0 on days 5–6 | 142 of 160 test photos right: 88.75% |
"Supervised" means the examples come with correct answers that supervise the fitting.
So, precisely: machine learning is choosing the parameter values of a model by minimising a loss on example data, and judging the result on examples that weren't used. Tom Mitchell's classic definition says the same in one line: a program learns from experience E, at a task T, measured by P, if its performance at T, measured by P, improves with E. For TrayCheck: T is naming the dish in a photo, P is accuracy on photos it hasn't seen, E is the labelled photos.
What people write, and what the data decides
A common description says machine learning means "no hand-written rules". The meals example shows why that's wrong. People wrote:
- the model family (a straight-line rule, not some other shape);
- the loss (average miss, not some other score);
- the optimiser and its settings (how to search, and for how long);
- which data to collect, and how to split it into training and test;
- the code around the model (TrayCheck's menu check is a hand-written rule).
The data decided only one thing: the values of the parameters, and therefore which specific rule from the family gets used. In the meals example that is 2 numbers. In TrayCheck it is about 2.4 million numbers, and those numbers decide which dish any particular photo is called. Machine learning replaces writing the specific mapping, not writing code.
A model only knows what its examples show
Suppose every training photo of bibimbap happened to have a fried egg on top. Then "egg means bibimbap" is a rule that fits the training data perfectly, and training may well find it. It fails on the first bibimbap without an egg. The model has no idea which parts of the pattern a person would consider essential. It only has the examples. Modules 9 and 10 are about finding gaps like this before users do.
When to use machine learning, and when not
| Use a written rule when… | Use machine learning when… |
|---|---|
| The rule is easy to state exactly | The rule can't be written, but examples are easy to collect |
| Mistakes must be impossible, or explainable line by line | Some mistakes are acceptable and can be caught (Module 11) |
| TrayCheck: "flag dishes not on today's menu" | TrayCheck: "which dish is in this photo?" |
Using machine learning where a simple rule would do adds errors and makes the system harder to explain.
4. Predicting a category: classification
Numbers versus categories
The meals model predicts a number; that kind of task is called regression. TrayCheck predicts a category: one of four dishes. That kind of task is called classification. A formula can only produce numbers, so how can it produce a category?
The standard answer has three steps: compute a score for each category, turn the scores into probabilities, and pick the category with the highest probability.
Step 1: a score per category
To keep it small enough for paper, take two dishes, beet salad and bread pudding, and describe each photo by just two measurements of its pixels:
- red: the share of pixels that are deep red or purple;
- gold: the share of pixels that are golden brown.
A measurement like this, computed from the raw input because it helps the decision, is called a feature. (Who decided to measure "red" and "gold"? A person. Hold that thought until §5.)
Each dish gets its own weighted sum of the features, with its own parameters:
beet score = 5 × red − 2 × gold pudding score = −2 × red + 5 × gold
The weights say how much each feature counts for or against each dish: lots of red is evidence for beet salad and against bread pudding. In a real model these weights are parameters, learned in training, not chosen by hand as they are here.
A photo with red = 0.4 and gold = 0.1 scores:
beet: 5 × 0.4 − 2 × 0.1 = 1.8 pudding: −2 × 0.4 + 5 × 0.1 = −0.3
Step 2: from scores to probabilities
Scores can be any number, including negative ones, and they don't add up to anything in particular. A function called softmax turns them into probabilities: all positive, adding up to 1, and keeping the order (the highest score gets the highest probability). For these two scores it gives beet salad 0.89, bread pudding 0.11. Module 2 §7 shows exactly how; for now, think of it as "make the scores positive, then divide each by the total".
Step 3: pick the most probable
The model predicts beet salad, and 0.89 is what TrayCheck's app calls the score of the prediction. A photo with red = 0.05, gold = 0.45 would go the other way: bread pudding with probability 0.94.
How a classifier is told it was wrong: the loss
For the meals model, the loss was simply "how far off". For a classifier, the loss looks at the probability the model gave to the correct answer, p, and charges −ln(p). (ln is the natural logarithm, explained in Module 2 §2; you only need its behaviour here.)
| Probability given to the correct dish | Loss −ln(p) |
|---|---|
| 0.90 | 0.11 |
| 0.50 | 0.69 |
| 0.01 | 4.61 |
Two things to see:
- If the photo above really is beet salad, the model gave the correct dish 0.89 and pays a small loss of 0.12. If it is really bread pudding, the model gave the correct dish only 0.11 and pays 2.22, nearly twenty times more.
- A confident wrong answer (0.01 on the right dish) costs about 40 times as much as a confident right one (0.90). That pressure is what pushes training to put high probability on the correct dish, and to avoid being confidently wrong.
This loss is called cross-entropy or log-loss. TrayCheck is trained by minimising its average over the training photos. Module 2 §8 explains why this particular formula is the principled choice.
Accuracy
Once trained, a classifier is usually reported by accuracy: the share of test examples whose predicted category is correct. TrayCheck: 142 of 160 test photos, 88.75%. Accuracy is easy to understand but hides a lot, for example which dishes the model confuses. Module 10 covers what to report instead and alongside.
5. Features, and what deep learning adds
Good features make the decision easy
In §4 the decision was easy because "red" and "gold" separate beet salad from bread pudding well. With good features, even a simple weighted sum decides correctly. With bad features, nothing downstream can rescue it.
Raw pixels are about the worst features there are. A single pixel's value says almost nothing about the dish, and it changes completely if the camera moves (§2). So everything depends on the step that turns 27,648 raw numbers into a few informative ones. Who designs that step is the difference between classical machine learning and deep learning.
Classical machine learning: people design the features
Before about 2012, image recognition worked like §4: people designed the features, and machine learning only learned how to weigh them. Typical hand-designed image features:
- colour histograms: count how many pixels fall into each of, say, 64 colour ranges (so 64 numbers describe the photo's colours, wherever they are in the image);
- edge and corner detectors: small calculations that respond where brightness changes sharply, summarised into counts of edges in each direction.
This works when people can anticipate what matters. It struggles when they can't: what feature separates a pale bread pudding from a pile of roast potatoes? Every new problem needed experts to invent new features. Most "predictive analytics" on tables of numbers (Module 12) is still classical machine learning, because there the columns are already good features: ward, day, meals ordered.
Deep learning: the features are learned too
Deep learning removes the hand-design step. The model is a stack of layers, and every layer has parameters that are learned.
What a layer computes. A layer takes a list of numbers and produces a new list. Each output number (called a unit or neuron) is a weighted sum of the inputs, like the dish scores in §4, followed by one simple bend: if the result is negative, replace it with 0. That bend is called ReLU.
Why the bend matters. Without it, stacking layers is pointless: a weighted sum of weighted sums is just another weighted sum. (Double something, then triple the result, and you've just multiplied by six. Two steps collapsed into one.) The bend is what lets a unit respond in ways a single weighted sum can't. For example, take two features that range from 0 to 1, "white grains" and "red", and one unit computing white + red − 1, then the bend:
| white | red | white + red − 1 | After the bend |
|---|---|---|---|
| 0 | 0 | −1 | 0 |
| 1 | 0 | 0 | 0 |
| 0 | 1 | 0 | 0 |
| 1 | 1 | 1 | 1 |
This unit switches on only when both are present: a "rice next to something red" detector. No weighted sum on its own can stay at zero for every other combination like this. Units like it, stacked layer on layer, can build up arbitrarily specific detectors.
What the layers end up detecting. When researchers looked at what each layer of a trained image network responds to, they found a clear progression:
| Layers | Respond to | In a food photo |
|---|---|---|
| First | Edges, colour contrasts in tiny patches | The rim of a bowl, a red-against-white boundary |
| Middle | Textures and repeated patterns | Rice grains, the glossy surface of a sauce |
| Later | Parts of objects | A mound of rice, a fried egg, a rack of ribs |
| Last | Whole categories | "Bibimbap" |
Nobody programmed any of these detectors. They emerged because every layer's parameters are adjusted together, by the same loss and the same optimiser, to make the final answer less wrong. This is called training end to end. "Deep" just means many layers: MobileNetV2, TrayCheck's network, has 52 convolution layers (layers of learned detectors, Module 7) between the raw pixels and its final 1,280 features.
| Approach | Raw input → features | Features → decision | Example |
|---|---|---|---|
| Hand-written program | Designed by people | Written by people | TrayCheck's menu check |
| Classical machine learning | Designed by people | Learned | Image recognition before 2012; most table-based predictive analytics today |
| Deep learning | Learned | Learned | TrayCheck's dish classifier |
Why deep learning took over
ImageNet is a collection of about 1.2 million labelled photos in 1,000 categories (dog breeds, vehicles, foods, tools…). From 2010 it was the basis of a yearly competition. Entries were scored by top-5 error: the share of test photos for which the correct category was not among the model's five most probable answers.
In 2012 a deep network called AlexNet made a top-5 error of 15.3%. The best entry built on hand-designed features made 26.2%. That gap was unheard of, and within a few years almost all computer vision used learned features. Three things made it possible at that moment: a large labelled dataset (ImageNet), cheap parallel computing (graphics cards), and a few training techniques you'll meet in Modules 5–7.
The catch, and how TrayCheck gets around it: transfer learning
Learning good features from scratch needs a great deal of data. TrayCheck has 400 training photos, far too few to learn what edges, textures and food parts look like.
But a network trained on ImageNet's 1.2 million photos has already learned edges, textures, shapes and object parts. Those are useful for food too. So TrayCheck borrows them. This is transfer learning (Module 8):
- Take MobileNetV2, a network already trained on ImageNet. Remove its last layer, the one that chose among ImageNet's 1,000 categories, and keep everything that turns a photo into 1,280 features. That kept part is called the backbone; its trained values are called pre-trained weights.
- Add a new, small head that turns those 1,280 features into scores for TrayCheck's 4 dishes.
- Stage 1: keep the backbone's parameters fixed (frozen) and train only the head, about 123,000 parameters, on the 400 photos.
- Stage 2: unfreeze the last 20 layers of the backbone and train them too, with a learning rate (the size of each adjustment step) 50 times smaller: 0.00001 instead of 0.0005. Small steps let the borrowed features adapt to food without being wrecked. This is called fine-tuning.
6. AI: the goal that all of this serves
What "artificial intelligence" means
The standard university textbook (Russell and Norvig's Artificial Intelligence: A Modern Approach) defines AI as building agents. An agent takes in observations, chooses an output or action, and is judged by a performance measure: a statement of which outcomes are better. A good (rational) agent chooses the action expected to score best, given what it has observed.
That definition describes a goal. It says nothing about how the agent decides. There are several families of method:
| Method | How the system decides | Example |
|---|---|---|
| Search | Tries many possible sequences of actions and keeps the best | Deep Blue, which beat world chess champion Kasparov in 1997, examined about 200 million positions per second, scoring each with a formula written and tuned by people |
| Logic and rules | Derives conclusions from facts and rules supplied by experts | 1980s "expert systems" for diagnosis or credit approval |
| Probability | Weighs uncertain evidence | Spam filters that combine many weak clues into a probability |
| Learning | Fits its behaviour to data | AlphaZero (2017) searches like Deep Blue but learned how to score positions, from millions of games against itself |
Deep Blue and AlphaZero do the same task with different methods. Both are AI; only AlphaZero uses machine learning. So:
"Is it AI?" asks what the system does. "Is it machine learning?" asks how its behaviour was produced. "Is it deep learning?" asks whether it also learned its own features.
Every part of TrayCheck, placed on the map
TrayCheck as a whole is an AI system that combines a learned part with rules, which is typical of real deployments:
| Part | How its behaviour was produced |
|---|---|
Dish classifier (food_model.py) |
Learned: deep learning, parameters fitted to 400 photos |
Review threshold 0.85 (vision/review_policy.json) |
Tuned on data, but not learned by the model: the lowest threshold that kept the error among unflagged validation photos at or below 5% |
Menu check and 10% random spot check (review_rules.py) |
Written by hand |
When you evaluate a vendor's system, ask the same question of each part: learned, tuned or written? Learned and tuned parts can quietly change behaviour when the data changes; written rules change only when someone edits them.
7. TrayCheck through the recipe
Now the five parts from §3, with TrayCheck's real numbers.
The optimiser, concretely
Training takes 32 photos at a time (a batch). For that batch it computes the average loss, works out for every trainable parameter whether nudging it up or down would lower that loss (the gradient, Module 2 §4), and moves every parameter a small step that way. One pass through all 400 training photos is an epoch: 13 batches. TrayCheck's head trained for 9 epochs and the fine-tuning stage for 6, so about 200 steps in total, which took 30 seconds on a laptop. Adam, the optimiser used, is a version of gradient descent that gives each parameter its own step size (Module 6).
Three datasets, three jobs
The meals example had two kinds of data: training and test. Real projects need a third.
| Split | Used for | TrayCheck |
|---|---|---|
| Training | Fitting the parameters | 400 photos (100 per dish) |
| Validation | Making choices: when to stop training, which threshold to use | 80 photos (20 per dish) |
| Test | One honest measurement at the end; never used for any choice | 160 photos (40 per dish) |
Why the extra set? Every choice made by looking at a dataset tunes the system to that dataset, just as fitting tunes the parameters to the training data. If the test set were used to choose, say, the review threshold, the test score would no longer be an honest measure of performance on new photos (Module 9 shows how much it inflates). So choices are made on validation photos, and the test photos are read once, after every choice is fixed. TrayCheck chose its threshold on validation photos and scored the test photos last.
Generalisation, in numbers
By the end of training, the model scored about 96% on its own training photos, 85% on validation photos and 88.75% on test photos. The drop from training to unseen photos is the same gap you saw in the meals example (0.5 vs 1.0), and it is why the training score can't be used to judge a model. (The training figure is measured with random flips and dropout switched on, so it's only roughly comparable; Module 6 explains both.)
Every measured number is an estimate
Validation (85%) and test (88.75%) differ by about three photos' worth, and that's expected. A test set is a sample: a different 160 photos would give a somewhat different number. For 160 photos at this accuracy, a 95% interval runs from about 83% to 93% (Module 2 §12 builds this from scratch). Quote that range, not just "88.75%".
8. Kinds of learning
- Supervised learning: examples with correct answers. Everything above.
- Classification predicts a category: which dish; whether a tray will come back more than half full.
- Regression predicts a number: meals needed tomorrow; grams left on a plate.
- Unsupervised learning: no answers; find structure. Clustering groups similar items (wards with similar waste patterns). Anomaly detection finds unusual ones (a day with three times the usual waste).
- Reinforcement learning: an agent learns by trial and reward, as AlphaZero did (games, robotics).
- Self-supervised learning: the data supplies its own answers (hide a word in a sentence, predict it). This is how large language models are first trained; outside this course's scope.
9. TrayCheck framed precisely
x: a photo f_θ(x) ŷ: 4 probabilities
96 × 96 pixels × 3 colours (add up to 1)
= 27,648 numbers (0–255)
│
├─ training only: random left–right flip, small random rotation (data augmentation)
├─ rescale each number to the range −1 … 1 (what MobileNetV2 was trained on)
▼
MobileNetV2 backbone ──────────► 1,280 learned features ──► head: 96 units (ReLU), dropout ──► 4 outputs, softmax
pre-trained on ImageNet; trained here [ribs 0.00, beet 1.00,
last 20 layers fine-tuned here bibimbap 0.00, pudding 0.00]
│
predicted dish = the largest
Reading the diagram:
- fθ(x) is the usual shorthand: the model f with parameter values θ ("theta") applied to the input x. ŷ ("y-hat") is its output.
- Data augmentation (training only): each time a photo is used, it may be mirrored or rotated slightly, so the model learns that a plate seen from the other side is still the same dish (Module 6).
- Rescaling: the pre-trained network learned from pixel values scaled to −1…1, so TrayCheck's must be scaled the same way, or the borrowed features are meaningless (Module 8).
- Dropout (training only): randomly switches off a quarter of the head's 96 units at each step, so the model can't rely on any one of them (Module 6).
What the model gives and can't give:
- Output: a probability for each of 4 dishes, adding up to 1. The prediction is the dish with the largest probability; that probability is the score.
- What it cannot know: grams on the plate, ingredients, allergens, whether the meal suits a patient, or any dish outside the four. Show it a pizza and it will still name one of the four, possibly with a high score, because those four are its only possible answers. A model like this is called a closed-set classifier. The menu check and human review exist partly because of it.
The model is a small part of the system
photo → model → review rules → person checks → record (SQLite) → dashboard → decisions by staff
▲ Modules 4–8 ▲ Module 11 ▲ Module 11 ▲ Module 12 ▲ Modules 10, 12, 13
A well-known Google paper on machine learning in production (Sculley et al., 2015) drew the model code as a tiny box surrounded by much larger ones: data collection, data checking, configuration, serving, monitoring. TrayCheck is the same. For the internship this is the main point. The vendor owns the model. ISS's question is whether the whole chain produces information that kitchen staff and dietitians can trust and act on.
10. Translating the job description
| Term in the position description | What it means precisely | Where in this course |
|---|---|---|
| Training and testing data | Data used to fit parameters vs data held back to measure performance honestly | This module §3, §7; Module 9 |
| Model accuracy | Share of correct predictions on held-out data; one of several metrics, often not the most useful one | This module §4; Module 10 |
| Pattern recognition | The older name for classification, especially from sensors and images | This module §4–§5; Modules 7, 8 |
| Pattern and trend identification | Mostly descriptive analysis of records (trends over time, comparisons between wards), plus unsupervised methods such as anomaly detection | Modules 10, 12 |
| Predictive analytics | Supervised learning on historical, usually tabular, data to forecast an outcome, like the meals example | This module §3; Modules 4, 12 |
| AI-enabled food identification, portion recognition | Image classification (which dish) and, harder, estimating amounts from images | Modules 7, 8, 12 |
| Testing AI outputs against actual operational outcomes | Comparing predictions with ground truth collected in the real setting (a person's check, a weighed plate) | Modules 10, 11 |
Worked example: what the lab shows
Running Lab 1 prints:
Original photo: 512 rows x 512 columns x 3 colour channels
Resized for the model: (96, 96, 3) = 27,648 numbers go in
baby_back_ribs 0.000013
beet_salad 0.999959
bibimbap 0.000029
bread_pudding 0.000000
Random guessing (1 of 4): 25.0%
Always guess the most common dish: 25.0%
The trained model: 88.75% (142 of 160)
Average top score when RIGHT: 92.0% (142 photos)
Average top score when WRONG: 66.9% (18 photos)
Wrong answers with a top score of 90% or more: 4
Three lessons:
- Always compare with a baseline. A baseline is the score of a trivial approach. Guessing at random gets 1 in 4 right; so does always guessing the most common dish, because the test set has 40 photos of each. 88.75% is 3.5 times better. With unbalanced classes the second baseline can be surprisingly high: if 90% of trays are "no waste", a model that always says "no waste" is 90% accurate and useless (Module 10).
- Scores are informative on average. Wrong answers have lower scores on average (66.9% vs 92.0%), which is why sending low-score photos to a person catches many mistakes.
- …but not individually reliable. Four mistakes scored above 90%. No threshold catches those without reviewing nearly everything, which is the reason for random spot checks (Module 11).
Try it: edit the lab to print the full row for test/baby_back_ribs/2134746.jpg, the ribs photo
the model calls bibimbap at 99%. Open the photo (data/vision/test/baby_back_ribs/2134746.jpg) and
decide whether the mistake is understandable. (It has a large mound of rice next to the ribs.)
Questions to ask about any AI proof of concept
Each comes straight out of this module, and each is a responsibility in the position description ("understand how machine learning models are being applied", "testing AI outputs against actual operational outcomes"):
- Input: what exactly does the model see? One photo per tray? Taken before or after the meal? From what angle, under what lighting?
- Output: what are the possible answers? Is there an "unknown" or "not on the menu" answer, or is it closed-set?
- Learned, tuned or written: which parts of the system are trained models, which are thresholds tuned on data, and which are hand-written rules?
- Training data: what was the model trained on? Generic food photos, another hospital's trays, or this site's? (Modules 8 and 9)
- Test data: how was accuracy measured, on how many examples, from which site and period? Were any of those examples also used for training or tuning? (Modules 9 and 10)
- Uncertainty: what happens when the model is unsure? Who checks, and how often? (Module 11)
Check your understanding
1. In the meals example, name the model, the parameters, the loss, the optimiser, the training data and the test data.
Model: the family meals = w × patients + b. Parameters: w and b. Loss: the average miss. Optimiser: trying values and keeping the best (in real projects, gradient descent). Training data: days 1–4. Test data: days 5–6, held back and used only to measure.
2. Rule B's average miss was 0.5 on days 1–4 and 1.0 on days 5–6. Which number would you report, and why?
1.0. Rule B was chosen because it fits days 1–4, so its score there is optimistic. Days 5–6 played no part in the choice, so they show how it does on new days. (Two days is far too few to be precise, but the principle is the same with 160 photos.)
3. A colleague says "machine learning means the computer works things out without hand-written rules." What's right and wrong about that?
Right: the specific mapping from inputs to outputs (the parameter values) is fitted to examples
rather than written by a person. Wrong: almost everything else is written by people: the model
family, the loss, the optimiser and its settings, the choice and split of data, and usually rules
around the model. In TrayCheck people wrote vision_train.py and review_rules.py; training only
chose the values of about 2.4 million parameters.
4. Why can't you write a rule for "is this bibimbap?" in terms of pixel values?
The same dish produces completely different pixel values when the camera, lighting, bowl or portion changes, and different dishes can produce similar values. There is no fixed pattern of numbers to point to, and people can't describe how they recognise it themselves.
5. A classifier gives the correct dish probability 0.9 on one photo and 0.01 on another. Roughly how do their losses compare, and what does that pressure do in training?
About 0.11 against 4.61, roughly 40 times larger. Training lowers the average loss, so it is pushed hard to avoid putting very low probability on the correct answer, that is, to avoid confident mistakes.
6. What does deep learning learn that classical machine learning does not?
The features. In classical machine learning people design how raw input becomes features (for images, things like colour histograms or edge counts), and learning only weighs them. A deep network learns the features as well, in many stacked layers, all trained together on the same loss.
7. Why is the "bend" (ReLU) needed between layers?
Without it, a weighted sum of weighted sums is just one weighted sum, so extra layers add nothing. The bend lets units respond in ways a single weighted sum can't, such as switching on only when two features are both present; stacking such units builds detailed detectors.
8. For each TrayCheck part, say whether it is learned, tuned on data, or written: the dish classifier, the 0.85 threshold, the menu check.
Classifier: learned (parameters fitted to 400 photos). Threshold: tuned on data (chosen on the 80 validation photos to keep unflagged error at or below 5%), but not learned by the model. Menu check: written. Together they make an AI system; only the first is machine learning.
9. Why does TrayCheck use transfer learning instead of training MobileNetV2 from scratch?
Learning general visual features (edges, textures, food parts) needs far more than 400 photos. A network trained on ImageNet's 1.2 million photos already has them, so TrayCheck keeps that backbone, trains a new head for its four dishes, then gently fine-tunes the top of the backbone.
10. What happens if someone uploads a photo of pizza?
The model must output four probabilities that add up to 1, so it names one of the four dishes, possibly with a high score. A closed-set classifier has no "none of these" answer unless one is built in (Module 14 discusses ways to add one). TrayCheck's menu check and human review catch some of these cases.
11. A vendor says "our food recognition is 95% accurate". What are your first three questions?
Measured on what data: how many trays, from which sites and which period, and were any of them used in training or tuning? Accurate at what: naming the dish, or estimating the portion? What is the baseline and the breakdown: accuracy per dish and the most common confusions, since 95% overall can hide a dish that is usually wrong (Module 10).
Go deeper
The module above is self-contained. These give a second explanation of the same ideas, or more history.
Recommended (free)
- Google, Introduction to Machine Learning: the What is ML? and Supervised learning pages (about 30 minutes). developers.google.com/machine-learning/intro-to-ml
- Goodfellow, Bengio & Courville, Deep Learning (2016), Chapter 1, from the start through Figures 1.4 and 1.5: the same "which parts are learned" picture as §5. deeplearningbook.org/contents/intro.html
- 3Blue1Brown, Neural networks, chapter 1, But what is a neural network?: a visual tour of layers, weighted sums and what units detect. 3blue1brown.com
Optional
- James, Witten, Hastie, Tibshirani & Taylor, An Introduction to Statistical Learning with Python, §2.1: prediction vs inference, and why some error can never be removed. Free at statlearning.com.
- Russell & Norvig, Artificial Intelligence: A Modern Approach, 4th ed., §1.1 and §2.1–2.4 (agents and rationality). Paid; check a library. aima.cs.berkeley.edu
- Mitchell, Machine Learning (1997), §1.1: the T/P/E definition with worked examples.
- Krizhevsky, Sutskever & Hinton (2012), ImageNet Classification with Deep Convolutional Neural Networks: the abstract and §6 (the AlexNet result).
- Zeiler & Fergus (2014), Visualizing and Understanding Convolutional Networks, Figure 2: what each layer of a trained network responds to. arxiv.org/abs/1311.2901
- Sculley et al. (2015), Hidden Technical Debt in Machine Learning Systems: the introduction and Figure 1.
- Harvard CS50 AI, Lecture 0 (search: AI without learning) and Lecture 4 (learning). cs50.harvard.edu/ai
Interview angle
"AI is the goal: systems that make good decisions. Machine learning is one way to get there: instead of writing the decision rule, you write a model with adjustable parameters, a loss that scores how wrong it is, and an optimiser, and you fit the parameters to labelled examples. Then you measure it on examples it hasn't seen, because fitting the training data is easy; generalising is the point. Deep learning is machine learning where the features are learned too, by many stacked layers.
TrayCheck uses all three ideas. The dish classifier is deep learning: a MobileNetV2 network pre-trained on ImageNet, with a new head trained on 400 photos and its last 20 layers fine-tuned. It's 88.75% accurate on 160 photos it never saw, roughly 83 to 93% given the sample size. Around it are a threshold tuned on validation data and hand-written rules that decide when a person checks the answer. When I evaluate a system like that, I ask which parts are learned, tuned or written, and how each was tested."