π₯ AI Challenges
In the previous chapters you learned how AI techniques work, from logic and search algorithms to decision trees, neural networks and large language models, and in the previous chapter you saw how to measure whether such a model works well. This chapter asks the question that comes next: what does it take to build an AI system that people really use? What can go wrong, and how do you prevent it?
Suppose the university asks you to build a student success model: a system that predicts in November which first-year students are at risk of failing, so that the study advisors can invite them for a meeting before it is too late. You have the data of previous years: prior education, attendance at the exercise sessions, results of the midterm tests, and whether those students passed in the end. Sounds feasible. Yet something can go wrong at every step, and those pitfalls are exactly what we look at here.
πΊοΈ From idea to working system
Building an AI system is not a straight line from "data in" to "model out". In practice you go through a cycle of six phases, and you regularly return to an earlier step.
Try it out: click through the phases below, or use Next step, and see which question each phase asks for the student success model. Together they form the common thread of this chapter.
Step 1 of 6
Problem definition
What exactly do you want to predict, and what counts as a mistake?
For the student success model
Is a student "at risk" if they do not pass in the first exam period, or only if they fail the year? And is a missed at-risk student as bad as a false alarm?
Read more:Which mistake is worse?Β β
π Collecting data
Almost every AI project starts with the same question: which data do you have, and is it good enough? Every technique we saw, from naive Bayes to convolutional neural networks, learns from examples. Even a rule-based system is not built without data: you need examples to write your rules and to test them.
For the student success model that immediately raises three questions, which often come up when collecting data in general.
- Which features do you include? Only the test results, or also attendance, prior education and the number of times someone logs in to Toledo, the university's learning platform? More features mean more collection work, and irrelevant features can mislead the model.
- Who labels the data? For supervised learning, every example has to carry the right answer. Here that is easy (whether someone passed is in the university's records), but with medical images a specialist has to assess every scan, and that is expensive and slow.
- Are you allowed to use the data at all? Study results and attendance are personal data. The General Data Protection Regulation (GDPR) requires that you only collect them for a clear purpose and that students know what happens with them.
π How much data is enough?
Dozens of examples? Thousands? Millions? That depends on how complex the pattern is that your model has to learn. In the previous chapter you saw that a model that is too complex for its data starts to overfit: it memorizes the random noise instead of the real pattern. So how much data a model needs is tied to how flexible it is.
In theory, more data is almost always better. In practice, a large labeled dataset is expensive and slow to collect: a study program has only a few hundred first-year students per year, and for a rare disease you get only a handful of scans, which then take doctors a lot of time and effort to label. So you have to estimate in advance how much data you can get, and what you will do if that is not enough (see further on).
πΊοΈ Outside the range of your data
Even with a lot of data, one limitation remains: a model is only reliable within the range of its training data. Between the training points a model can follow the pattern, but beyond them it has no points to hold on to. As soon as you make predictions there, you are extrapolating.
Extrapolation is predicting outside the range of the training data. The model has seen no examples there, so such predictions are uncertain by definition.
A straight line that predicts the rent of a student room (a kot, as students in Leuven call it) well between 12 and 26 mΒ² gives a price with no real basis for an apartment of 100 mΒ²: apartments are priced differently from student rooms.
A recommendation system trained on the viewing behavior of teenagers gives strange suggestions to retired people. And the student success model, trained on the first-year students of one study program, will obediently give a number for working students from another faculty too, but that number is a guess: it never learned anything about such students.
π Too little data? Augmentation and synthetic data
If you have too little training data, you can expand your existing data artificially. In image recognition that is very common: you rotate, flip and crop photos, or add noise. For text you can use back-translation: translating a sentence into another language and back again, so that you get the same content in other words. Such data augmentation increases the variation, but adds no new information: if all your photos of dogs were taken in daylight, flipping them will not give you a model that recognizes dogs in the dark.
One step further is synthetic data: with diffusion models or language models you generate completely new training examples, for instance of rare situations that hardly occur in real data. This has become standard practice: reasoning models, for example, are trained on generated math problems whose answers can be checked automatically.
There is one catch, though. If you train a model on data generated by a previous model, and the next model on the output of that one, model collapse (external link) can occur: each generation loses a little of the rare cases, until the data becomes monotonous. Below, an image generator learns from 100 animal photos and makes 100 new ones, from which the next generation learns. Try it out: click Next generation a few times and see which animals disappear first.
Generation 0100 real photos
Species on the wall12 of 12
Number of species per generation
The real photos: lots of dogs and cats, and a handful of rare animals.
Some people fear that fate for future language models, because the internet is filling up with AI-generated text. Turn on Mix in real photos in the demo, and you see what helps: keep adding real data, and filter strictly on quality. Datasets such as FineWeb (external link) show that a model trained on a carefully filtered selection of web texts performs better than the same model trained on the full, unfiltered pile.
β οΈ Data bias
Even more dangerous than too little data is skewed data. If your training data gives a distorted picture of reality, your model adopts that distortion, and often even amplifies it. After all, a model can never be better than the data it learns from: "garbage in, garbage out".
Data bias is a systematic error in the training data that makes the model learn a distorted version of the world. It arises from an unrepresentative sample, from prejudices of the past in the data, or from errors in the way things are measured.
Look at the data of the student success model with that in mind, and you see three kinds of bias.
-
Selection bias: the sample is not representative of the population. The question is which cases are in the data? The university's records only keep those who stayed until the exam. Those who had already dropped out in November are missing, and that is exactly the group you want to find. The same mechanism is behind a facial recognition system that was trained mainly on light skin tones and works systematically worse on dark ones: the camera works fine, but one group is underrepresented. Collecting broader or more balanced data usually solves this.
-
Measurement bias: the measurement itself is skewed. The question is how are the features measured? It is about systematic errors, always in the same direction or different between groups, not about random noise. If you measure attendance with a badge scanner at the door, anyone who comes in through the back counts as absent. If you ask students how many hours they study, you get socially desirable answers, just as people in a survey systematically underestimate their alcohol consumption. The sample can be perfectly representative, but the values are wrong.
-
Historical bias: the data reflects old prejudices or inequality from the past, such as a recruitment system that learned to score women lower because the company used to hire mostly men. Even if you delete background or gender from the table, the bias creeps in through someone's school, postal code or hobbies (more on that in the next chapter).
Selection and measurement bias sometimes look alike. A handy test: does a more balanced sample solve the problem? Then it was selection bias. Does the problem remain even with a representative sample? Then the error is in the measurement itself.
βοΈ Class imbalance
You saw in the previous chapter that class imbalance (one class occurs far more often than the other) makes accuracy worthless, and which measures do tell you something then. Here the question is what you can do about it:
- Undersampling: leave out part of the majority class.
- Oversampling: duplicate examples of the minority class or generate synthetic ones.
- Weighted errors: make an error on the minority class count more heavily during training.
- Choosing a different measure: optimize for precision, recall or F1 score instead of accuracy.
Which data problem is at work here? Drag each AI mistake to the right type.
π§© Model choice
You have good data. Which model do you choose? Every model makes assumptions about the shape of the pattern in the data, and those assumptions determine what it can learn and what it cannot.
π² Different decision boundaries
Think back to the classification models you saw. Each model draws its decision boundaries in a different way:
- Decision trees divide the space with horizontal and vertical lines: the boundary consists of rectangular blocks.
- Logistic regression and the perceptron draw one straight line. That works if the classes can be separated by a straight line, and fails with curved boundaries.
- k-nearest neighbors follows the data points closely and draws irregular regions, which therefore also follow every noisy point.
- Neural networks with hidden layers can learn any boundary. But more flexibility also means a greater chance of overfitting.
See for yourself in the demo below. Choose another dataset or drag data points, and see how each model redraws its boundaries differently.
So isn't there simply one best model? No. The No Free Lunch theorem (external link) states that no single algorithm performs best on all problems. On one problem a decision tree wins, on another logistic regression, because each model suits a different kind of pattern.
So the choice always depends on the problem, the available data, the budget (see further on) and the tradeoff between performance and interpretability.
πΉ Bias-variance tradeoff
You can tell whether a model is too simple or too complex for its data by underfitting and overfitting, as you saw in the previous chapter. Machine learning has two technical terms for this, which describe why a model makes mistakes:
- Model bias (not to be confused with the data bias from above) is the systematic error of a model that is too simple for the pattern. If the real relationship is a curve but your model can only draw straight lines, it will always be off, however much data you have. High bias causes underfitting.
- Variance says how sensitive a model is to the random details of its training data. If you train a model with high variance on a slightly different sample, a very different model comes out: it has learned the noise as if it were the pattern. High variance causes overfitting.
On the target below, the bullseye is the true pattern, and every hit is a model you trained on a new sample. Bias says how far the hits are from the bullseye on average, variance how far apart they lie. Try it out: draw a New sample a few times, and then set the bias or the variance to High.
π― Ideal
Every model lands close to the true pattern, whichever sample you draw.
- the true pattern
- one model, on a sample of its own
- the average model
With real models, you play it out in the demo below. The gray dashed line is the true pattern. Each click on "New sample" draws a new, slightly different set of training points from that same pattern and fits a model to it.
- Start with degree 1 and draw about ten samples: all the straight lines stay close together (low variance), but none of them follows the curve (high bias).
- Set the degree to 10 and draw again: the curves shoot off in all directions (high variance), although their average (purple) still follows the pattern fairly well (low bias).
- Find the degree at which the sum of the two is smallest, and then see what happens if you take more points per sample: the variance drops, and a more complex model becomes feasible.
The bias-variance tradeoff is the dilemma that a simpler model has more bias but less variance, and a more complex model less bias but more variance. The art is to find the right middle ground, and that middle ground shifts toward more complex models as you have more data.
πͺ Occam's razor: start simple
From that tradeoff follows a practical rule of thumb, Occam's razor: when performance is equal, choose the simplest model. If a logistic regression for the student success model gives the same test error as a neural network with a thousand parameters, choose the logistic regression. Simple models are easier to understand and maintain, and less prone to overfitting.
The principle is named after the 14th-century English Franciscan William of Ockham (external link). The Latin adage "Entia non sunt multiplicanda praeter necessitatem" ("entities must not be multiplied without necessity", or: do not add complexity unless it is needed) is traditionally attributed to him, although this exact wording was only formulated later (external link).
In practice you therefore always start with a simple model as a baseline: a logistic regression, naive Bayes or a shallow decision tree trains in seconds and gives you a point of reference. Only when a more complex model clearly beats that baseline on the test data is the extra complexity worth it. Two other ways to keep a model simple:
- Feature selection: not every available feature has to go into your model. Leaving out irrelevant features reduces the noise the model can overfit on.
- Regularization: penalizing the model for complexity, such as pruning a decision tree or keeping the weights of a neural network small. That way you lower the variance without switching to another model.
πΈ How much can it cost?
A last factor in choosing a model is the computational cost, which differs enormously between the techniques in this course. In the chapter on CNNs you saw how the number of parameters explodes with larger images. Compare that with the other models:
| Model | Parameters |
|---|---|
| Linear regression (2 features) | 3 |
| Decision tree (depth 10) | ~1,000 |
| k-NN | 0 (stores the data itself) |
| Small neural network | ~100,000 |
| ResNet-50 (CNN) | ~25 million |
| Llama 3.1 (external link) (open language model) | 405 billion |
Between a linear regression and a large language model lies a factor of a hundred billion, and that largely determines where a model can run. The student success model trains and runs on any laptop. A model like ResNet-50 already needs a powerful GPU to train smoothly, and large language models require whole GPU clusters, or a subscription with someone who has such a cluster. The response time follows the same trend: a small model answers in microseconds, a large language model often needs seconds per answer.
Yet ever larger models keep being built, because they perform better: according to the scaling laws, language models get systematically better (external link) as you train them on more data with more computing power. That curve does flatten out (diminishing returns), so you rarely train from scratch: you reuse a pretrained model and make a large model more efficient with distillation and quantization.
π Interpretability
Your model has been chosen, trained and evaluated, and it performs well on paper. Then this appears on the student portal: "Our system estimates your chance of passing at 23%." What do you do with that number? You want to know why. Is it your math score? Your attendance? Or something you cannot change? Someone who is refused a loan asks the same question: "Our AI has decided that you are not eligible." "But why not?" And the bank employee shrugs.
AI systems increasingly make decisions that affect people's lives, and then you want an answer to that question. Not every model can give one equally well. In the chapter on the dimensions of AI we made the distinction between reasoning and learning algorithms; reasoning systems are usually much more transparent than learning ones.
The most powerful models (deep neural networks, large language models) are usually the least transparent, and the most transparent ones (decision trees, linear regression) are often less powerful. So you have to weigh how much transparency you give up for better performance.
π― Why explain?
Why would you want to understand how a model reaches its decision?
- Justifying: showing that a decision is correct and fair, such as a bank that has to explain why a loan was refused, or a university that must be able to tell a student why it labels them as at risk.
- Checking: finding mistakes before you deploy the model. Maybe it only works well for one target group, or it looks at the wrong features.
- Improving: if you know why a model makes mistakes, you can tackle them in a targeted way.
- Discovering: a transparent model can reveal patterns that even experts did not know yet.
Explainable AI (XAI) is the collective name for techniques that make AI decisions understandable to people, without sacrificing performance.
A research team (external link) trained an interpretable model to predict the risk of death from pneumonia. The model learned something surprising: patients with asthma had a lower risk of death. That sounds illogical, because asthma is in fact a risk factor. The explanation? Asthma patients with pneumonia were treated more intensively by default, so they survived more often. The model learned the effect of the treatment, not of the disease.
Had this model been deployed blindly, it would have labeled asthma patients as "low risk" and sent them home, with potentially deadly consequences. Only because the model was interpretable could the researchers find that mistake: an example of both checking and improving.
π³ Interpretable models
With a decision tree you can follow the whole reasoning: every node is a question, and every path from root to leaf is a readable rule. "Less than 60% on the midterm test and present at less than half of the exercise sessions: at risk." With linear or logistic regression, each coefficient tells you exactly how much a feature contributes: you can see that each extra percent of attendance raises the chance of passing a little, and that the math score counts the most. Naive Bayes and k-nearest neighbors can be explained too: you can show which probabilities or which similar students made the difference.
π³οΈ Black-box models
A neural network with millions of parameters does not offer that transparency. A CNN that classifies a photo as "dog" does so on the basis of thousands of filters. Which pattern made the difference? The whiskers? The background? Or the watermark of a website full of dog photos? Afterward you can approximately explain which parts of the input the model found important, but that remains an explanation after the fact, not a transparent line of reasoning.
Interpretability is the degree to which a person understands how a model decides by looking at its structure and parameters. Explainability is the degree to which you can give an explanation afterward, even for a model that in itself is impossible to understand.
For images you already saw such an explanation technique: Grad-CAM draws a heatmap over the photo with the spots where the CNN "looked". That technique only works for CNNs, and explains one photo at a time. For a model such as the student success model, with a table as input, you need something more general.
π LIME: explaining any model locally
What if you want an explanation for a model you cannot look inside, whatever model it is? Then you need a model-agnostic technique, such as Local Interpretable Model-agnostic Explanations (LIME) (external link). The idea: to understand why the model makes a certain prediction, LIME changes the input a little each time and watches how the prediction changes along with it. Based on that, it builds a simple linear model that imitates what the big model does in the neighborhood of that one example, and that you can read directly.
Back to the 23% chance of passing that was predicted for a student. LIME changes small things (a different math score, a different attendance rate, different exercise results) and watches how the prediction shifts. That way it can show: "Your math score contributed β15%, your attendance β8%, your exercises +5%." A related approach is the counterfactual explanation: not what contributed, but what would have had to be different for a different result. For example: "With a math score of 75% instead of 60%, your chance of passing would be 52%."
Try it out: below, you are LIME, and the student success model is a black box that you may only query. Click Query a variant a few times and watch the explanation take shape. Then find under Counterfactual which single change gets you above 50%.
You
- Math test60%
average 70%
- Attendance40%
average 70%
- Exercises done70%
average 62%
Success model
a black box: you cannot see how it computes
Chance of passing
23%
0 variants queried
| Math test | Attendance | Exercises done | Chance of passing |
|---|---|---|---|
| No variants yet: LIME has not asked the model anything. | |||
LIME's explanation
3 more variants and LIME can give a first explanation.
For a student and a study advisor, such an explanation is a number you can actually work with.
LIME works with any model (neural network, random forest, ...) because it only queries the model and never looks at it from the inside. That makes it widely applicable, but the explanation remains an approximation, not an exact representation of what the model does internally.
Where on the spectrum do you place these models?
π‘οΈ Robustness: when AI fails
The student success model scores well on the test set and you can explain its predictions. Time to deploy it. But the real world is not a tidy test set. In this section we look at four ways in which a model goes wrong there: deliberate deception, made-up answers, overconfidence, and a world that changes while the model stands still.
π Deception
In the chapter on CNNs you saw how vulnerable neural networks are to deliberate manipulation: add invisibly small noise to a photo of a panda, and the network sees a gibbon with great confidence. You can look at such an adversarial attack again below, on a photo of a giant panda that the network then takes for a dog: the middle image is the added noise, amplified ten times to make it visible.
Researchers also showed (external link) that a few stickers on a stop sign are enough to make a traffic sign recognizer read the sign as a speed limit sign, even when filmed from a moving car. One defense is adversarial training: you deliberately also train the model on such perturbed examples, so that it can handle them better. But it remains an arms race: every better defense provokes smarter attacks.
Even without pixel noise a model gets manipulated, simply because people adapt. As soon as students know that the badge scans count for the student success model, some of them scan their badge and leave again. As soon as spammers know which words a filter looks for, they write "frβ¬e". A feature that was a good measurement loses its value as soon as it becomes a goal.
π«§ Hallucinations
When large language models produce fluent nonsense, that is not a bug you can remove. It is the same robustness problem in text form: a model that knows only probability and not truth sounds just as convincing when it is wrong. The chapter on large language models already showed what helps: giving the model tools to look up facts, and continuing to check what comes out.
π Overconfidence
Models are often overconfident: they attach high probabilities to wrong answers. That is dangerous, because users confuse the model's confidence with its correctness. If the student success model says "95% chance of failing", a study advisor will believe that number, but a model that is "95% sure" may in reality be right in only 70% of cases. That difference is called a calibration problem: the model is poorly calibrated.
The demo below shows it. On the left are 25 predictions of a model with the confidence it reported, green if the prediction turned out to be right and red if it was wrong. On the right, those predictions are grouped by confidence: a well-calibrated model that says "80%" is also right in about 80% of those cases, and so follows the dashed line. With the overconfident model, the bars lie far below that line.
In safety-critical applications (a medical diagnosis, a self-driving car), a model must also be able to say "I don't know". Most models are bad at that, and for language models that is partly due to how they are trained. Their performance is measured as the number of correctly answered questions, not as the number of times they rightly said "I don't know". It is an exam with no penalty for guessing (external link): guessing always pays off, so the model learns to always answer, even when it has no idea.
A related problem is sycophancy: the model adapts its answer to tell users what they want to hear. Say "I think the earth is flat, is that right?", and a sycophantic model answers "That is an interesting point of view!" instead of correcting you. During training on human preferences it learned that users rate agreeable answers higher, and it then optimizes for approval instead of for truth. In April 2025, OpenAI had to roll back an update of ChatGPT (external link) because the model suddenly agreed with everything, even with users' downright bad plans.
π The world changes
The world does not stand still. The patterns in your data today may be different tomorrow.
Concept drift is the phenomenon that the relationship between input and output changes over time. A model that once worked well then gradually starts to perform worse, because reality has drifted away from the training data.
A spam filter from 2020 is out of date today, because spammers have adapted their tactics. Facial recognition trained on photos without face masks suddenly worked less well when face masks became the norm. And the student success model, trained on years with regular classes, lost all its predictive power in the COVID year: the exercise sessions moved online, so attendance suddenly said nothing anymore. Each time, the data in use differs from the data the model learned from, and the model does not "know" that it does not know something: it simply gives a prediction.
Try it out: follow the student success model below year by year with Next year, and see what happens when the exercise sessions move online. Then turn on Retrain after year 4.
Year 1training
Midterm test score β
Attendance at the exercise sessions β
- passed
- did not pass
- predicted wrongly
- gets invited for a meeting
Monitoring: accuracy per year
level on the training data
Training data: students who often attend the exercise sessions and score well on the test usually pass. The model learns a boundary.
Two lessons. First: test your model not only on a test set that resembles the training data, but also on data that deliberately differs from it. Only then do you discover where the limits lie. Second: deploying a model is not the end of the work. You keep tracking its performance and regularly retrain it on new data. That is called model monitoring, and it is a fixed part of every AI system in production. This closes the cycle from the start of this chapter: from use back to data.
The Dutch-language model RobBERT (external link) was trained in 2019 on Dutch web texts. When the COVID-19 pandemic broke out, the model knew words such as "knuffelcontact" (the one person you were still allowed to hug) or "coronapas" (the COVID pass) barely or not at all. In 2022 the researchers therefore trained it further on more recent data, which gave RobBERT-2022 (external link). The model picked up the new pandemic vocabulary by itself as frequent words, and as a result performed better on language tasks about COVID.
If the system still works after all those hurdles, the technical question is answered. But only then comes the hardest question: may a university score its students like this, who is responsible if the model is wrong, and who decides on that? That is the topic of the next chapter.
πΉοΈ Demos
Experiment further with the full simulators and demos featured above.






π£οΈ Feedback
Just like machine learning algorithms, we also love learning from your feedback to improve the course.
Let us know how informative and how difficult you found this chapter, and where it could be better.