AI vs ML vs DL vs GenAI, explained
The four terms everyone uses loosely, defined precisely, with Indian examples. The full notes of our free Lesson 1.1.
These are the complete notes of Lesson 1.1, which is free. The lab and quiz are in the learning app.
Why this matters
Every conversation about AI at work starts with four words that people use loosely: artificial intelligence (AI), machine learning (ML), deep learning (DL) and generative AI (GenAI). A product manager says "let's add AI". A vendor says "our platform is AI-powered". A client asks "can GenAI fix our fraud problem?". If you cannot say precisely what each word means, you cannot judge any of these claims, and you cannot choose the right tool.
Here is where this skill shows up in real AI and data work:
- Choosing the approach for a new problem. A lending start-up wants to flag risky loan applications. Should the team write rules with the credit analysts, train an ML model on past loans, train a deep network, or call a large language model? Each choice has a different cost, a different data need and a different failure mode. The first job of an AI engineer is to pick the simplest approach that works.
- Reading a system you inherit. When you join a team, you will find a mix of hand-written rules, classic ML models and deep networks, often in the same product. A UPI payments app might block a payment with a rule ("more than ₹1 lakh to a new payee at 2 a.m."), score it with a gradient-boosted tree model, read a scanned cheque with a deep network, and answer the customer's complaint with a GenAI chatbot. To debug it, you must know which part is which.
- Evaluating vendor claims. Procurement teams regularly ask engineers "is this really AI?". The three-question test in this lesson gives you a calm, evidence-based answer in two sentences.
- Predicting how a system will fail. Rules break when the world changes. ML copies the biases in its data. Deep networks are hard to explain. GenAI can write fluent text that is false. Knowing the category tells you where to look first when something goes wrong.
- Interviews. "Explain the difference between AI, ML and deep learning" is one of the most common opening questions in interviews for data and AI roles, at every level. A crisp, structured answer with one example each sets the tone for the whole interview.
This lesson has four objectives. We refer to them as O1 to O4 throughout.
- O1. Explain in one plain sentence each what AI, ML, DL and GenAI mean, and how they fit inside each other.
- O2. Tell the difference between a program that follows rules a person wrote and a model that learned its rule from examples.
- O3. Classify a real-world system as RULES, ML, DL or GENAI using the three-question test, and justify the choice in one sentence.
- O4. Name one typical risk or limitation of each category.
You do not need to write code to pass this lesson. But the notes contain small, runnable Python examples, because seeing a rule being learned by a few lines of code is the fastest way to understand what learning means. Read each code block, read the explanation below it, and do not worry if some syntax is new. Module 2 teaches Python properly.
Before you start
This is the first lesson of the course, so there are no earlier lessons to revise. You only need a few everyday ideas. Here is a two-minute refresher of each, with a tiny example. The examples are written in Python so that you get used to seeing it.
1. A program turns inputs into outputs by following steps. A calculator app takes two numbers (inputs), follows a fixed step (add them) and shows the answer (output). Every system in this lesson, from a spam filter to a chatbot, is an input-to-output machine. The question is always where the steps came from.
price = 500
gst_rate = 0.18
total = price + price * gst_rate
print(total)
590.0
A variable such as price is a name for a value. print shows a value on the screen.
2. A rule is an if-then statement. "If the bill is over ₹2,000, give free delivery." In Python an if line checks a condition that is either True or False.
bill = 2450
if bill > 2000:
print("free delivery")
else:
print("delivery fee applies")
free delivery
3. A list holds many values in order. We will store example emails as a list of pairs: (number of suspicious words, was it really spam?). len counts the items.
examples = [(0, False), (5, True), (2, False)]
print(len(examples), examples[1])
3 (5, True)
4. A function is a named, reusable recipe. def name(inputs): starts it and return hands back the result.
def with_gst(amount):
return amount * 1.18
print(round(with_gst(1000), 2))
1180.0
5. Accuracy is a fraction. If a system gets 11 answers right out of 16, its accuracy is $11 \div 16 = 0.6875$, or 68.75%. We will compare systems by accuracy a lot in this lesson.
print(11 / 16, 14 / 16)
0.6875 0.875
That is everything you need. Unknown words are in the IRI Glossary, and each one is also explained here the first time it appears.
Concept ladder
The ladder goes from the widest, easiest idea to the narrowest and most technical one. Each rung uses the ones before it.
1. Artificial intelligence: the widest box
Plain English: Artificial intelligence is the broad goal of making software do tasks that we normally think need human judgement: playing chess, planning a route, recognising a face, answering a question. AI is a goal, not a single technique. Many different methods can reach it, and some of them involve no learning at all.
Analogy: "Transport" is a goal: getting people from A to B. Bicycles, trains and aircraft are all transport, built in very different ways. AI is like the word "transport"; machine learning is like "motor vehicles", one important family inside it.
Precise definition: AI is the field of computer science that builds systems which perceive inputs, reason about them and choose actions or outputs for tasks that would require judgement if a human did them. The name "artificial intelligence" comes from a 1955 proposal for a summer research workshop held at Dartmouth College in 1956. A system can be AI whether its decision logic was written by people (for example a search algorithm or a set of expert rules) or learned from data. A plain calculation, such as an average or a GST total, is not AI: it involves no judgement, only arithmetic.
Worked example, step by step: Is each of these AI?
- A GST calculator multiplies a price by 18%. The task needs no judgement; any clerk with a formula does it identically. Not AI, just software.
- A route planner searches thousands of road combinations to find the fastest way from Koramangala to the airport. Choosing a route is a judgement task, and the program uses a search algorithm that programmers wrote. AI, of the RULES kind: it does not learn from data.
- A chess program looks ahead several moves and scores each board with a formula programmers wrote (for example, a queen is worth 9 points, a rook 5). Playing chess needs judgement; nothing is learned. AI, RULES.
- A phone app names a plant from a photo. It was trained on many labelled photos. AI, and also ML (rung 3).
The line in step 1 matters in practice. Some products call any automation "AI". Arithmetic, sorting and filtering are useful, but they are not AI.
See it: One big box labelled "AI". Inside it, on the left, sit a route planner and a chess engine with small gear icons (rules written by people). On the right is an empty space waiting for the ML box. Outside the big box sit a calculator and a spreadsheet total, clearly not inside.
Check yourself: A hospital app follows a flowchart of if-then questions written by doctors to decide which patients see a doctor first. Is it AI?
Answer
Yes, it is AI of the RULES kind. Deciding who needs care first (triage) is a judgement task, and the system makes that judgement with rules that people wrote. It is not machine learning, because nothing was learned from data.2. Rules-based systems: logic written by people
Plain English: A rules-based system follows if-then logic that a person wrote down. The person looks at the problem, uses their experience, and encodes a decision: "if an email has 5 or more suspicious words, call it spam". The program never changes that rule by itself. It does exactly what it was told, every time. Older AI systems of this kind, built from hundreds of rules collected from experts, were called expert systems.
Analogy: A recipe card from your grandmother. It says "add salt until it tastes right, about one teaspoon". The card never improves itself; if the recipe is wrong, someone has to rewrite the card.
Precise definition: A rules-based system is a function $f(x)$ from inputs to outputs whose logic, including every threshold and constant, was chosen by a person. In this course we label such systems RULES. For the spam example, with $c$ = the number of suspicious words in an email and a human-chosen threshold of 5:
$$f(c) = \begin{cases} \text{spam} & \text{if } c \ge 5 \ \text{not spam} & \text{if } c < 5 \end{cases}$$
Worked example, step by step: We have 16 example emails. Each is described by one number, its suspicious-word count, and we know whether it really was spam. This is the same data as the lab.
emails = [ # (suspicious_word_count, is_spam)
(0, False), (1, False), (0, False), (2, False), (1, False), (2, False), (1, False), (4, False),
(3, True), (5, True), (4, True), (6, True), (7, True), (3, True), (4, True), (2, True),
]
def human_rule(count):
return count >= 5
correct = 0
for count, is_spam in emails:
if human_rule(count) == is_spam:
correct += 1
print(correct, "of", len(emails), "=", correct / len(emails))
11 of 16 = 0.6875
- The 8 real non-spam emails have counts 0, 1, 0, 2, 1, 2, 1, 4. All are below 5, so the rule says "not spam" for all 8. All 8 are right.
- The 8 real spam emails have counts 3, 5, 4, 6, 7, 3, 4, 2. Only 5, 6 and 7 reach 5, so the rule catches 3 of them. The other 5 spam emails (counts 3, 4, 3, 4, 2) slip through. That is 3 right and 5 wrong.
- Total right: $8 + 3 = 11$. Accuracy: $11 \div 16 = 0.6875$, which is 68.75%.
The rule is easy to read and easy to explain. But the number 5 was a guess, and nobody checked it against the data.
See it: A number line from 0 to 8. Sixteen dots sit on it, green for real non-spam, red for real spam. A vertical wall stands at 5, drawn by a human hand. Everything right of the wall is called spam. Five red dots sit to the left of the wall, glowing as mistakes.
Check yourself: If a person changed the rule to "3 or more words is spam", how many of the 16 emails would be right?
Answer
14. Non-spam: only the email with count 4 is wrongly called spam, so 7 of 8 are right. Spam: every count except 2 reaches 3, so 7 of 8 are right. $7 + 7 = 14$, which is $14 \div 16 = 87.5\%$. But notice that a person would only know to pick 3 by checking the data, which is exactly what learning does (rung 3).3. Machine learning: finding the rule from examples
Plain English: Machine learning is a way of building AI where the program is shown many examples and finds the rule by itself. You give it inputs together with the right answers, and it searches for the rule that makes the fewest mistakes on those examples. The search is called training. The rule it ends up with, together with any numbers it learned, is called a model.
Analogy: A new cricket coach does not arrive with a rulebook for picking the batting order. She watches many past matches, notices which orders scored the most runs, and adjusts. Her rule comes from the evidence, and it changes if the evidence changes.
Precise definition: A widely used definition comes from the textbook Machine Learning by Tom Mitchell (1997): "A computer program is said to learn from experience E with respect to some class of tasks T and performance measure P, if its performance at tasks in T, as measured by P, improves with experience E." For our spam filter: the task T is labelling emails, the performance measure P is accuracy, and the experience E is the 16 labelled emails. The numbers a model learns are called parameters. Here there is one parameter, the threshold $t$, and training chooses
$$t^{*} = \arg\max_{t} \ \text{accuracy}(t)$$
which reads "the $t$ that gives the highest accuracy". The name machine learning was popularised by Arthur Samuel, whose 1959 paper described a checkers program that improved by playing.
Worked example, step by step: Instead of guessing 5, let the program try every threshold from 0 to 8 and keep the best.
def accuracy(threshold, data):
right = 0
for count, is_spam in data:
predicted_spam = count >= threshold
if predicted_spam == is_spam:
right += 1
return right / len(data)
for t in range(0, 9):
print(t, accuracy(t, emails))
best_t, best_score = None, -1
for t in range(0, 9):
score = accuracy(t, emails)
if score > best_score:
best_t, best_score = t, score
print("learned threshold:", best_t, "accuracy:", best_score)
0 0.5
1 0.625
2 0.8125
3 0.875
4 0.75
5 0.6875
6 0.625
7 0.5625
8 0.5
learned threshold: 3 accuracy: 0.875
- $t = 0$: every email has at least 0 words, so everything is called spam. The 8 spam are right, the 8 non-spam are wrong. $8 \div 16 = 0.5$.
- $t = 2$: the non-spam emails with counts 2, 2 and 4 are wrongly called spam (3 mistakes). Every spam email has at least 2 words, so none is missed. $13 \div 16 = 0.8125$.
- $t = 3$: one non-spam email (count 4) is wrongly flagged, and one spam email (count 2) is missed. 2 mistakes, $14 \div 16 = 0.875$.
- $t = 4$: one non-spam (count 4) wrongly flagged, three spam missed (counts 3, 3, 2). 4 mistakes, $12 \div 16 = 0.75$.
- $t = 5$ is the human rule: $0.6875$.
- The loop keeps the highest score. It reaches 0.875 at $t = 3$ and nothing later beats it, so the learned threshold is 3.
Nobody told the program the number 3. It found it by checking the examples. This search is the smallest possible picture of learning. Real ML models search over thousands or millions of parameters with cleverer methods (Lesson 3.8 covers gradient descent, the most important one), but the idea is the same: choose the parameters that make the fewest mistakes on the examples.
A real library does the same search. A decision tree with one split (a "decision stump") from scikit-learn, a popular Python ML library, finds the same boundary:
from sklearn.tree import DecisionTreeClassifier
X = [[count] for count, is_spam in emails]
y = [is_spam for count, is_spam in emails]
stump = DecisionTreeClassifier(max_depth=1, random_state=0).fit(X, y)
print(stump.tree_.threshold[0], stump.score(X, y))
2.5 0.875
The tree splits at 2.5, halfway between 2 and 3. "Count greater than 2.5" means the same as "count of 3 or more", because counts are whole numbers. Same rule, same 87.5% accuracy.
See it: The same number line with sixteen dots. Now the wall is not drawn by hand. It slides from 0 to 8, and above it a counter shows the accuracy at each stop: 0.5, 0.625, 0.8125, 0.875, then falling. The wall locks at 3, the highest point.
Check yourself: In the loop above, the test is score > best_score. If two thresholds tied for the best score, which one would the loop keep: the smaller or the larger?
Answer
The smaller one. The loop goes from 0 upwards, and a later threshold replaces the current best only if it is *strictly* greater. A tie is not strictly greater, so the first (smaller) threshold stays. With `>=` the loop would keep the larger one.4. Training versus inference, and why we test on new data
Plain English: Two words describe the two phases of every ML system's life. Training is when the model learns from example data. Inference is when the trained model is used on new data to give an answer. Training usually happens once, or now and then; inference happens every time a user needs an answer. Because a model is chosen to fit its training examples, we must check it on new examples it has never seen, or we fool ourselves about how good it is.
Analogy: A student who memorises last year's question paper will score full marks on that paper. Only a fresh paper shows whether the student understood the subject. The training data is last year's paper; the test data is the fresh one.
Precise definition: - Training data: the labelled examples used to choose the parameters. - Test data: labelled examples held back and used only to measure performance after training. - Inference: computing the model's output $\hat{y} = f(x)$ for a new input $x$, using the parameters fixed during training. (The hat on $\hat{y}$ means "predicted".) - Generalisation: how well performance on training data carries over to new data. - Overfitting: when a model fits quirks of its training data so closely that it does worse on new data.
Worked example, step by step: We trained on the 16 emails and learned $t = 3$. Now 8 new emails arrive from the same kind of inbox.
new_emails = [(0, False), (3, False), (1, False), (2, False), (6, True), (3, True), (5, True), (1, True)]
learned_t = best_t
predictions = [count >= learned_t for count, _ in new_emails]
print(predictions)
print("test accuracy:", accuracy(learned_t, new_emails))
[False, True, False, False, True, True, True, False]
test accuracy: 0.75
- Training: done already. The parameter is frozen at $t = 3$.
- Inference on each new email: counts 0, 3, 1, 2, 6, 3, 5, 1 compared with 3 give False, True, False, False, True, True, True, False.
- Compare with the truth: email 2 (count 3, not spam) is a false alarm; email 8 (count 1, spam) is missed. 6 of 8 right.
- Test accuracy is $6 \div 8 = 0.75$, lower than the 0.875 on the training data. This is normal. The training score is always an optimistic estimate because the model was chosen to do well on exactly those examples.
With one parameter, overfitting is limited. With millions of parameters, a model can memorise its training data almost perfectly and still fail on new data, which is why every serious ML project keeps a separate test set. Lesson 1.2 shows how to set up the evaluation of a new AI problem.
See it: Two panels. On the left, the 16 training dots and the wall locked at 3, with "0.875" above. On the right, 8 new dots fall onto a fresh number line with the same wall; two of them flash as mistakes and the counter reads "0.75".
Check yourself: A team reports "our model is 99% accurate" but measured it on the same data it was trained on. What should you ask?
Answer
Ask for the accuracy on held-out test data the model never saw during training. Accuracy on training data only shows how well the model fits examples it has already seen, not how it will do on new cases.5. Kinds of machine learning: labels, numbers and groups
Plain English: ML problems come in a few shapes. In supervised learning every training example comes with the right answer (the label). If the answer is a category, such as spam or not spam, it is classification. If the answer is a number, such as a house price, it is regression. In unsupervised learning there are no labels; the model finds structure by itself, for example grouping similar customers (clustering). All of these are ML, and none of them needs a neural network.
Analogy: Supervised learning is learning with an answer key at the back of the book. Unsupervised learning is being handed a box of mixed buttons and sorting them into piles that look alike, with no one telling you the "right" piles.
Precise definition: Given pairs $(x_i, y_i)$, supervised learning finds $f$ with $f(x_i) \approx y_i$. When $y$ is a category, it is classification; when $y$ is a real number, it is regression. The simplest regression model is a straight line $\hat{y} = m x + b$, where the slope $m$ and intercept $b$ are the parameters. The least-squares line picks the $m$ and $b$ that minimise the sum of squared errors, and has the closed form
$$m = \frac{\sum_i (x_i - \bar{x})(y_i - \bar{y})}{\sum_i (x_i - \bar{x})^2}, \qquad b = \bar{y} - m\bar{x}$$
where $\bar{x}$ and $\bar{y}$ are the averages. In unsupervised learning there is no $y$; clustering assigns each $x_i$ to a group.
Worked example, step by step: Four flats sold recently. Size is in hundreds of square feet; price is in ₹ lakh.
sizes = [6, 8, 10, 12]
prices = [45, 57, 66, 80]
x_bar = sum(sizes) / len(sizes)
y_bar = sum(prices) / len(prices)
num = sum((x - x_bar) * (y - y_bar) for x, y in zip(sizes, prices))
den = sum((x - x_bar) ** 2 for x in sizes)
m = num / den
b = y_bar - m * x_bar
print(x_bar, y_bar, num, den)
print(round(m, 2), round(b, 2), round(m * 11 + b, 2))
9.0 62.0 114.0 20.0
5.7 10.7 73.4
- Averages: $\bar{x} = (6 + 8 + 10 + 12) \div 4 = 9$ and $\bar{y} = (45 + 57 + 66 + 80) \div 4 = 62$.
- Deviations from the average: sizes give $-3, -1, 1, 3$; prices give $-17, -5, 4, 18$.
- Products: $(-3)(-17) = 51$, $(-1)(-5) = 5$, $(1)(4) = 4$, $(3)(18) = 54$. Sum: $51 + 5 + 4 + 54 = 114$.
- Squared size deviations: $9 + 1 + 1 + 9 = 20$.
- Slope $m = 114 \div 20 = 5.7$: each extra 100 sq ft adds about ₹5.7 lakh.
- Intercept $b = 62 - 5.7 \times 9 = 62 - 51.3 = 10.7$.
- Inference for an 1,100 sq ft flat ($x = 11$): $5.7 \times 11 + 10.7 = 62.7 + 10.7 = 73.4$ lakh.
The line was learned from data, it is not a deep network, and its output is a number. By the three-question test (rung 10) it is ML.
Clustering, with no labels at all:
from sklearn.cluster import KMeans
import numpy as np
monthly_spend = np.array([[200], [250], [300], [5000], [5200], [5400]])
km = KMeans(n_clusters=2, n_init=10, random_state=0).fit(monthly_spend)
groups = {}
for spend, label in zip(monthly_spend[:, 0], km.labels_):
groups.setdefault(int(label), []).append(int(spend))
print(sorted(groups.values()))
[[200, 250, 300], [5000, 5200, 5400]]
k-means found two groups of customers, light spenders and heavy spenders, without anyone labelling them. The group numbers it uses (0 or 1) are arbitrary, so we print the groups themselves.
See it: Four dots on a size-versus-price chart, with a line swinging into place through them; a dashed arrow drops from size 11 to the line and across to 73.4. Beside it, six dots on a spend axis split into two coloured clouds.
Check yourself: A model predicts how many minutes a food delivery will take. Is that classification or regression?
Answer
Regression, because the output is a number (minutes), not a category. If the model instead predicted "on time" or "late", it would be classification.6. Features: turning the world into numbers
Plain English: A model can only work with numbers. A feature is one measurable number that describes an input, such as "count of suspicious words" or "does the email contain a link (1 or 0)". In classic ML, people design the features by hand, and the model learns how to combine them. This design work is called feature engineering, and it is where much of the skill in classic ML lies. For tidy tables, such as transaction records, hand-made features work very well.
Analogy: A doctor does not look at "the whole patient" as one blob. She measures temperature, pulse and blood pressure: a few numbers that summarise the person. Features are the measurements you choose to take.
Precise definition: A feature vector is an ordered list of numbers $x = (x_1, x_2, \dots, x_d)$ that represents one input. $d$ is the number of features. A feature extractor is the function, usually written by a person in classic ML, that turns a raw input (an email's text) into $x$.
Worked example, step by step: Turn one email into three features.
SUSPICIOUS = {"free", "winner", "urgent", "prize", "click", "offer"}
def features(text, sender_known):
words = text.lower().replace("!", " ").split()
n_suspicious = sum(1 for w in words if w in SUSPICIOUS)
has_link = 1 if "http" in text.lower() else 0
return [n_suspicious, has_link, 1 if sender_known else 0]
msg = "URGENT! You are a winner. Click http://example.test to claim your FREE prize"
print(features(msg, sender_known=False))
[4, 1, 0]
lower()makes every letter lower-case, so "URGENT" and "urgent" match.replace("!", " ")turns each exclamation mark into a space.split()breaks the text into words at the spaces.- The words are: urgent, you, are, a, winner., click, http://example.test, to, claim, your, free, prize. Notice "winner." still has its full stop attached.
- Check each word against
SUSPICIOUS. "urgent", "click", "free" and "prize" match. "winner." does not match "winner", because the full stop makes it a different string. Son_suspiciousis 4, not the 5 a human reader would count. has_linkis 1 because the text contains "http".- The sender is unknown, so the last feature is 0.
You can print the matching words to see this for yourself:
words = msg.lower().replace("!", " ").split()
print([w for w in words if w in SUSPICIOUS])
['urgent', 'click', 'free', 'prize']
This small surprise carries a real lesson. A hand-written feature extractor contains hidden choices (here: which punctuation to strip), and each choice changes the numbers the model sees. Always print what your extractor produces on a few real inputs before you trust it.
See it: A raw email on the left. Three funnels pull out three numbers: a word counter (4, with "winner." shown greyed out because of its full stop), a link detector (1) and a sender check (0). The numbers drop into a row of three boxes: the feature vector.
Check yourself: How would you fix the extractor so that "winner." counts as "winner"?
Answer
Remove punctuation before splitting, for example by replacing "." (and other punctuation) with a space as well as "!". Then "winner." becomes "winner", and the count becomes 5. This is a feature-engineering decision a person must make.7. Neural networks: layers of simple units
Plain English: A neural network is a model made of many small units called neurons, arranged in layers. Each neuron takes some numbers in, multiplies each by a weight, adds them up with a bias, and passes the total through a simple function called an activation. The outputs of one layer become the inputs of the next. Training adjusts all the weights and biases so that the final outputs match the labels. The weights and biases are the network's parameters.
Analogy: A panel of judges at a cooking contest. Each judge gives more importance to some things (taste, presentation) than others; that importance is a weight. Their scores are passed to a head judge, who weighs the judges' opinions to give the final verdict. A deep network has many rows of judges, each row listening to the row before.
Precise definition: One neuron with inputs $x_1, \dots, x_n$, weights $w_1, \dots, w_n$ and bias $b$ computes
$$z = w_1 x_1 + w_2 x_2 + \dots + w_n x_n + b, \qquad a = g(z)$$
where $g$ is the activation function. Two common ones are ReLU, $g(z) = \max(0, z)$, and the sigmoid, $\sigma(z) = \dfrac{1}{1 + e^{-z}}$, which squashes any number into the range 0 to 1. A fully connected layer with $n_{\text{in}}$ inputs and $n_{\text{out}}$ neurons has $n_{\text{in}} \times n_{\text{out}}$ weights plus $n_{\text{out}}$ biases.
Worked example, step by step: One neuron scoring our email features $x = [3, 1, 0]$ (3 suspicious words, a link, unknown sender), with weights $[0.8, 1.5, -2.0]$ and bias $-2.5$. These weights are chosen by hand here to show the arithmetic; in a real network, training would find them.
import math
x = [3, 1, 0]
w = [0.8, 1.5, -2.0]
bias = -2.5
z = sum(wi * xi for wi, xi in zip(w, x)) + bias
relu = max(0, z)
sigmoid = 1 / (1 + math.exp(-z))
print(round(z, 2), round(relu, 2), round(sigmoid, 4))
1.4 1.4 0.8022
- Multiply each input by its weight: $0.8 \times 3 = 2.4$, $1.5 \times 1 = 1.5$, $-2.0 \times 0 = 0$.
- Add them: $2.4 + 1.5 + 0 = 3.9$.
- Add the bias: $3.9 + (-2.5) = 1.4$. So $z = 1.4$.
- ReLU: $\max(0, 1.4) = 1.4$.
- Sigmoid: $e^{-1.4} \approx 0.2466$, so $\sigma(1.4) = 1 \div 1.2466 \approx 0.8022$. Read it as "about 80% spam".
- Note the negative weight on "known sender": a known sender pushes the score down. If the sender were known, $z = 1.4 - 2.0 = -0.6$ and $\sigma(-0.6) \approx 0.354$.
Now count the parameters of a small network with layer sizes $[3, 4, 4, 1]$: 3 inputs, two hidden layers of 4 neurons, 1 output.
def count_params(layers):
total = 0
for n_in, n_out in zip(layers[:-1], layers[1:]):
total += n_in * n_out + n_out
return total
print(count_params([3, 4, 4, 1]), count_params([784, 128, 64, 10]))
41 109386
- Layer 1: $3 \times 4 = 12$ weights plus 4 biases $= 16$.
- Layer 2: $4 \times 4 = 16$ weights plus 4 biases $= 20$.
- Output: $4 \times 1 = 4$ weights plus 1 bias $= 5$.
- Total: $16 + 20 + 5 = 41$ parameters.
- A network for 28×28 pixel digit images, $[784, 128, 64, 10]$: $784 \times 128 + 128 = 100{,}480$, then $128 \times 64 + 64 = 8{,}256$, then $64 \times 10 + 10 = 650$. Total $109{,}386$. Compare that with the one parameter of our threshold model.
See it: Three input circles on the left labelled 3, 1, 0. Lines fan out to a column of four circles, then another four, then one output circle. Line thickness shows weight size; a pulse of light travels left to right as the numbers flow through. A counter in the corner ticks up to 41 parameters.
Check yourself: How many parameters does a single fully connected layer with 10 inputs and 5 outputs have?
Answer
$10 \times 5 = 50$ weights plus 5 biases, which is 55 parameters.8. Deep learning: many layers that learn their own features
Plain English: Deep learning is machine learning with neural networks that have many layers. "Deep" refers only to the number of layers; it does not mean clever or mysterious. The big advantage is that a deep network can take raw, messy input, such as the pixels of a photo, the samples of a sound recording or the pieces of a sentence, and learn useful features by itself, layer by layer. In classic ML a person would have to design those features by hand, which is very hard for photos and sound.
Analogy: An assembly line for recognising a face. The first workers only spot edges. The next group combines edges into shapes like eyes and noses. The last group combines shapes into "this is Priya". No worker was told what an eye looks like; each group learned what to pass on.
Precise definition: A deep neural network is a neural network with several hidden layers between input and output. There is no official cut-off number; in practice "deep" is used for networks with more than one or two hidden layers, and modern ones often have dozens or more. Deep learning is the part of ML that trains such networks, usually on large datasets and with specialised hardware such as GPUs (graphics processing units). Deep networks learn a representation: each layer transforms its input into a new set of numbers that makes the final task easier. Well-known kinds include convolutional neural networks (CNNs), designed for images, and transformers, the architecture behind most modern language models. A 2012 deep CNN, known as AlexNet, won the ImageNet image-recognition competition by a wide margin, and that result is usually named as the moment deep learning took over computer vision.
Worked example, step by step: How big is the raw input a deep network must handle?
h, w, channels = 224, 224, 3
pixels = h * w * channels
print(pixels)
grey_digit = 28 * 28
print(grey_digit)
audio_samples = 16000 * 5
print(audio_samples)
150528
784
80000
- A colour photo resized to 224 by 224 pixels, with 3 colour values per pixel (red, green, blue): $224 \times 224 = 50{,}176$ pixels, times 3 is $150{,}528$ numbers.
- A small greyscale handwritten digit, 28 by 28: $784$ numbers, one brightness value each.
- Five seconds of audio recorded at 16,000 samples per second: $16{,}000 \times 5 = 80{,}000$ numbers.
- No person can write rules over 150,528 raw numbers to tell a rose from a tulip, and hand-designing features for photos is slow and brittle. A deep network learns the features from labelled examples instead.
- Now classify. A plant-identifier app: learned (ML), a deep CNN (deep), output is a plant name, which is a label. So it is DL, not GenAI.
See it: A photo of a flower dissolves into a grid of coloured numbers (150,528 of them). The grid flows into a tall stack of layers; the first layer lights up on edges, a middle layer on petal shapes, and the last layer outputs one word: "rose".
Check yourself: Is a gradient-boosted decision tree model trained on a table of 50 transaction features "deep learning"? Why?
Answer
No. It learns from data, so it is ML, but decision trees are not neural networks, so it is not deep learning. "Deep" refers only to many-layered neural networks. Tree models like this are very strong on tidy tables and are widely used for fraud and credit scoring.9. Generative AI: creating new content
Plain English: Generative AI uses deep learning models to create new content: text, images, audio, video or code. The key difference is the output. A model that looks at a photo and says "cat" is recognising; a model that draws a new cat is generating. Large language models (LLMs), which power chatbots, generate text one small piece at a time: they repeatedly predict a likely next piece given everything so far, add it, and repeat.
Analogy: A music critic and a composer both know a lot about music. The critic listens and gives a label ("this is a raga in Yaman"). The composer writes a new piece. Classic DL models are critics; generative models are composers.
Precise definition: A generative model learns the patterns of its training data well enough to produce new samples that resemble it. A language model assigns a probability to each possible next token (a word or piece of a word) given the text so far, written $P(\text{next token} \mid \text{previous tokens})$, and generates text by choosing tokens one after another. Modern LLMs are deep transformer networks with billions of parameters. In this course a system is GENAI when it is a deep learning model whose main output is new content. The opposite kind, which outputs a label or a number, is sometimes called discriminative.
Worked example, step by step: Build the smallest possible text generator, a bigram model: it counts which word follows which, then uses those counts to write. It is only a toy (it is not a deep network, so by our test it would be ML), but it shows the mechanism of generation clearly.
corpus = "the order is late . the order is here . the refund is late ."
tokens = corpus.split()
next_counts = {}
for current, following in zip(tokens[:-1], tokens[1:]):
next_counts.setdefault(current, {})
next_counts[current][following] = next_counts[current].get(following, 0) + 1
print(next_counts["the"], next_counts["is"])
total_the = sum(next_counts["the"].values())
print({word: round(c / total_the, 3) for word, c in next_counts["the"].items()})
{'order': 2, 'refund': 1} {'late': 2, 'here': 1}
{'order': 0.667, 'refund': 0.333}
- Split the text into tokens: the, order, is, late, ., the, order, is, here, ., the, refund, is, late, . (15 tokens).
- Walk through every neighbouring pair. After "the" we see "order" twice and "refund" once. After "is" we see "late" twice and "here" once.
- Turn counts into probabilities: $P(\text{order} \mid \text{the}) = 2 \div 3 \approx 0.667$ and $P(\text{refund} \mid \text{the}) = 1 \div 3 \approx 0.333$.
Now generate. We follow every possible path from "the" and list the sentences the model can write.
def all_sentences(word, sentence):
if word == ".":
return [" ".join(sentence)]
results = []
for nxt in sorted(next_counts[word]):
results += all_sentences(nxt, sentence + [nxt])
return results
possible = all_sentences("the", ["the"])
seen = {"the order is late .", "the order is here .", "the refund is late ."}
for s in possible:
print(s, "| in training text" if s in seen else "| NEW")
the order is here . | in training text
the order is late . | in training text
the refund is here . | NEW
the refund is late . | in training text
- The model can write four sentences. Three were in its training text. One, "the refund is here .", is new: it was never written anywhere.
- That new sentence is fluent and grammatical. But nothing in the data says the refund is here. If a customer asked about their refund and the model wrote this, it would be a confident, fluent, false statement. This is the mechanism behind hallucination in large language models: they produce what is likely-sounding, not what is checked to be true. Real LLMs are vastly more capable than this toy, but they share the same basic behaviour.
See it: A small graph of words with arrows: "the" branches to "order" (thick arrow, 2) and "refund" (thin arrow, 1); "is" branches to "late" (thick) and "here" (thin). A highlighted path walks the → refund → is → here, and the finished sentence glows orange with the tag "NEW, never seen".
Check yourself: A speech recogniser turns a voice note into written text. It outputs text, so is it GenAI?
Answer
No, it is DL. Its output is a transcript of what was actually said, not new content. It *recognises* speech; it does not create anything. Compare a text-to-speech system that produces a brand-new voice recording from typed text: that one creates new audio, so it is GENAI.10. The three-question test: nested boxes as a decision procedure
Plain English: The four ideas nest inside each other. AI is the biggest box. ML sits inside it. DL sits inside ML. GenAI is built with DL, so we place it inside DL. To classify any system, ask three questions in order and stop at the first one that settles it. Always place the system in the innermost box that fits.
Analogy: An address: India, Karnataka, Bengaluru, Indiranagar. Someone in Indiranagar is also in Bengaluru, Karnataka and India. The most useful answer is the most specific one. A GenAI chatbot is also DL, ML and AI, but "GENAI" tells you the most.
Precise definition: The IRI three-question test:
- Did the decision rule come from a person (written) or from data (learned)? Written means RULES.
- If learned, is the learner a neural network with many layers? If no, it is ML.
- If yes, is its main output new content (text, image, audio, code)? If yes, GENAI. If its output is a label or a number, it is DL.
As sets: $\text{GenAI} \subset \text{DL} \subset \text{ML} \subset \text{AI}$, and RULES is the part of AI that is outside ML. For a product made of several parts, classify the part that makes the decision you are asking about, and name each part separately.
Worked example, step by step: Encode the test as a function and run it on six systems.
def three_question_test(rule_from, deep_network, creates_content):
if rule_from == "person":
return "RULES"
if not deep_network:
return "ML"
if creates_content:
return "GENAI"
return "DL"
systems = [
("Loan scorecard, points chosen by credit analysts", "person", False, False),
("Loan scorecard, points fitted by logistic regression on past loans", "data", False, False),
("Cheque reader: deep network turns handwriting into amounts", "data", True, False),
("Support bot writing new replies with an LLM", "data", True, True),
("Self-play chess engine scoring boards with a deep network", "data", True, False),
("Image tool that draws a new product photo from a prompt", "data", True, True),
]
for name, rule_from, deep, creates in systems:
print(three_question_test(rule_from, deep, creates), "-", name)
RULES - Loan scorecard, points chosen by credit analysts
ML - Loan scorecard, points fitted by logistic regression on past loans
DL - Cheque reader: deep network turns handwriting into amounts
GENAI - Support bot writing new replies with an LLM
DL - Self-play chess engine scoring boards with a deep network
GENAI - Image tool that draws a new product photo from a prompt
- The two loan scorecards look identical on screen: both add up points and compare them with a cut-off. The only difference is where the points came from. Analysts chose them: RULES. A model fitted them from past loans: ML. The mechanism decides the category, not the appearance.
- The cheque reader is learned and deep, and its output is a number read from the image, not new content: DL.
- The support bot is learned, deep, and writes new text: GENAI.
- The chess engine is interesting. Classic chess engines use search plus hand-written scoring formulas: RULES. Engines in the style of AlphaZero (DeepMind, 2017) instead score positions with a deep network trained by playing against themselves. The output is a move choice, not new content: DL. The same product type can land in different boxes depending on how it was built.
- The image tool is learned, deep, and creates a new picture: GENAI.
Now a hybrid product. A voice assistant in a banking app has three parts: a deep network turns speech into text (DL), a fixed list of keywords routes "block my card" to the card-blocking flow (RULES), and an LLM writes the reply (GENAI). Asking "which category is the assistant?" has no single answer. The right answer names each part and its mechanism.
See it: Four nested boxes: AI, ML, DL, GenAI. A system card drops in from the top and passes three gates, one per question. At each gate it either stops (landing in RULES, ML or DL) or moves one box inwards. The two loan scorecards land in different boxes even though their cards look the same.
Check yourself: A thermostat switches the heater on when the room is below 20°C. The vendor calls it "AI-powered". Classify it.
Answer
Question 1: the rule "below 20°C, heat on" was written by a person, so it is RULES at most. Keeping a room warm with a fixed threshold involves hardly any judgement, so many engineers would say it is plain automation, not AI at all. Either way, nothing is learned, so calling it "AI-powered" in the ML sense is not justified.11. Risks and limits of each category
Plain English: Each category fails in its own typical way. Rules break when the world changes and nobody updates them. ML copies whatever patterns are in its training data, including mistakes and biases, and it also goes stale when the world changes. DL is hard to explain: millions of parameters make each decision, so it is hard to say why. GenAI can produce fluent content that is false (hallucination), and it can be steered by cleverly written input. Knowing the category tells you which failure to test for first.
Analogy: Every vehicle has its known weak spot. A bicycle struggles uphill, a car gets stuck in traffic, a plane needs a runway. You still use all three; you just plan for the weak spot.
Precise definition: - Brittleness (RULES): a rule gives wrong outputs for situations its author did not foresee. - Data drift (RULES and ML): the data seen at inference time changes from the data the rule or model was built on, so performance drops. - Bias (ML, DL, GenAI): systematic errors that fall more heavily on some groups, usually because the training data under-represents them or records past unfair decisions. - Opacity (DL, GenAI): it is hard to explain an individual decision in human terms. - Hallucination (GenAI): fluent generated content that is not supported by facts or the given source.
Worked example, step by step: Drift. Spammers learn that our filter counts suspicious words, so next month they write spam with fewer of them.
next_month = [(0, False), (1, False), (2, False), (1, False), (0, False),
(1, True), (2, True), (2, True), (3, True), (1, True)]
print("old threshold on new data:", accuracy(3, next_month))
for t in range(0, 5):
print(t, accuracy(t, next_month))
old threshold on new data: 0.6
0 0.5
1 0.7
2 0.7
3 0.6
4 0.5
- With the learned $t = 3$, all 5 non-spam are right, but only 1 of 5 spam (count 3) is caught. $6 \div 10 = 0.6$, down from 0.75 on last month's test data.
- Retrain on the new data: the best threshold reaches only $0.7$ (at $t = 1$ or $t = 2$).
- The lesson: retraining helps a little, but one feature is no longer enough. The team needs new features (for example, links or sender history). Drift is why production ML systems are monitored and retrained, and why rules need owners.
Bias, measured by comparing accuracy across groups:
results = [("metro", True)] * 18 + [("metro", False)] * 2 + [("small town", True)] * 6 + [("small town", False)] * 4
for group in ["metro", "small town"]:
rows = [ok for g, ok in results if g == group]
print(group, len(rows), round(sum(rows) / len(rows), 2))
metro 20 0.9
small town 10 0.6
- For metro applicants the model is right 18 times out of 20: 0.9. For small-town applicants, 6 out of 10: 0.6. The overall accuracy, $24 \div 30 = 0.8$, hides this gap. Always break accuracy down by group.
See it: Four panels, one per box. RULES: the wall at 3 stays put while the red dots slide left past it. ML: two bars of different heights, 0.9 and 0.6. DL: a network with thousands of tangled lines and a question mark. GenAI: the sentence "the refund is here" glowing with a warning icon.
Check yourself: Which category's typical risk is "it states false things confidently", and what is one practical guard against it?
Answer
GenAI (hallucination). One practical guard is to make the system answer only from a trusted source document and check its output against that source, for example by checking that every number in the answer appears in the source, and by having a person review high-stakes answers.Step-by-step walkthroughs
Walkthrough 1: rules versus learning, counting every kind of mistake
Accuracy hides which mistakes a system makes. For spam, calling a real customer's email spam (a false positive) is often worse than letting one spam through (a false negative). Let us compare the human rule and the learned rule mistake by mistake.
def mistakes(threshold, data):
fp = sum(1 for count, is_spam in data if count >= threshold and not is_spam)
fn = sum(1 for count, is_spam in data if count < threshold and is_spam)
return fp, fn
for name, t in [("human rule", 5), ("learned rule", 3)]:
fp, fn = mistakes(t, emails)
print(f"{name}: threshold {t}, false positives {fp}, false negatives {fn}, accuracy {accuracy(t, emails)}")
cost = {t: mistakes(t, emails)[0] * 5 + mistakes(t, emails)[1] * 1 for t in range(0, 9)}
print(cost)
print("cheapest threshold:", min(cost, key=cost.get))
human rule: threshold 5, false positives 0, false negatives 5, accuracy 0.6875
learned rule: threshold 3, false positives 1, false negatives 1, accuracy 0.875
{0: 40, 1: 30, 2: 15, 3: 6, 4: 8, 5: 5, 6: 6, 7: 7, 8: 8}
cheapest threshold: 5
Line by line:
mistakescounts two kinds of error.fpcounts emails the rule calls spam (count >= threshold) that were not spam.fncounts emails the rule lets through (count < threshold) that were spam.- The human rule never blocks a real email (0 false positives) but lets 5 spam through. The learned rule makes 1 of each.
- The
costline gives each false positive a cost of 5 and each false negative a cost of 1, because blocking a customer's real email is five times as bad in this made-up business. For threshold 3: $1 \times 5 + 1 \times 1 = 6$. For threshold 5: $0 \times 5 + 5 \times 1 = 5$. min(cost, key=cost.get)finds the threshold with the lowest cost: 5.
The surprise: once mistakes have different costs, the human's threshold of 5 is the best choice. Learning did not become useless. It is still the search that found the cheapest threshold. What changed is what we asked it to optimise. Choosing the right measure of success is part of framing a problem, which Lesson 1.2 covers. The job skill here is: never accept "accuracy went up" without asking which mistakes changed.
Walkthrough 2: auditing a vendor list with the three-question test
A procurement team receives a list of tools that all say "AI-powered". Your task is to classify each one with evidence. We store what the vendor documents say as simple facts, then apply the test.
catalogue = [
{"tool": "Invoice GST checker", "rule_from": "person", "deep": False, "creates": False,
"evidence": "applies GST slabs typed in by the finance team"},
{"tool": "Churn predictor", "rule_from": "data", "deep": False, "creates": False,
"evidence": "logistic regression trained on 2 years of subscriptions"},
{"tool": "KYC photo matcher", "rule_from": "data", "deep": True, "creates": False,
"evidence": "deep network compares a selfie with an ID photo, outputs match or no match"},
{"tool": "Product description writer", "rule_from": "data", "deep": True, "creates": True,
"evidence": "LLM writes new descriptions from a list of features"},
{"tool": "Warehouse route optimiser", "rule_from": "person", "deep": False, "creates": False,
"evidence": "shortest-path search written by engineers, no training data"},
]
summary = {}
for item in catalogue:
label = three_question_test(item["rule_from"], item["deep"], item["creates"])
summary[label] = summary.get(label, 0) + 1
print(f"{label:6} {item['tool']}: {item['evidence']}")
print(summary)
RULES Invoice GST checker: applies GST slabs typed in by the finance team
ML Churn predictor: logistic regression trained on 2 years of subscriptions
DL KYC photo matcher: deep network compares a selfie with an ID photo, outputs match or no match
GENAI Product description writer: LLM writes new descriptions from a list of features
RULES Warehouse route optimiser: shortest-path search written by engineers, no training data
{'RULES': 2, 'ML': 1, 'DL': 1, 'GENAI': 1}
Step by step:
- Each tool is a dictionary of facts. The
evidencefield records where the facts came from. An audit without evidence is just an opinion. three_question_test(from rung 10) turns the three facts into a label.f"{label:6} ..."prints the label padded to 6 characters so the columns line up.summarycounts how many tools fall in each box.- Read the result. Two of the five "AI-powered" tools learn nothing. That is not a criticism: the GST checker should be rules, because tax law is written down and must be applied exactly. The route optimiser is a sound search algorithm. The point of the audit is to set the right expectations and the right risks: the GST checker needs an owner to update the slabs when the law changes; the churn model needs retraining and bias checks; the photo matcher needs testing across skin tones, ages and lighting; the description writer needs fact-checking against the product sheet.
The GST checker also shows a subtle point. Rung 1 said a GST calculator is not really AI, because it is plain arithmetic. In an audit, you would say so politely: "this is rules-based automation; it is reliable and appropriate, but it is not machine learning".
Walkthrough 3: a tiny network forward pass with NumPy
Deep learning is layers of weighted sums. Here is a forward pass through a network with layer sizes $[3, 4, 1]$, written with NumPy, the standard Python library for arrays of numbers (Lesson 2.12 teaches it properly). The weights are fixed by hand so that you can check every number.
import numpy as np
x = np.array([3.0, 1.0, 0.0]) # suspicious words, has link, known sender
W1 = np.array([[0.5, -0.2, 0.1, 0.0],
[0.3, 0.8, -0.5, 0.2],
[-1.0, 0.4, 0.2, -0.3]]) # 3 inputs x 4 hidden neurons
b1 = np.array([-1.0, 0.0, 0.5, 0.1])
W2 = np.array([[1.2], [0.7], [-0.4], [0.9]]) # 4 hidden x 1 output
b2 = np.array([-0.5])
z1 = x @ W1 + b1
h = np.maximum(0, z1)
z2 = h @ W2 + b2
p = 1 / (1 + np.exp(-z2))
print(np.round(z1, 2), np.round(h, 2))
print(np.round(z2, 3), np.round(p, 3))
print("parameters:", W1.size + b1.size + W2.size + b2.size)
[0.8 0.2 0.3 0.3] [0.8 0.2 0.3 0.3]
[0.75] [0.679]
parameters: 21
Step by step:
xholds the 3 features.W1is a 3 by 4 grid of weights: column $j$ holds the three weights of hidden neuron $j$.x @ W1multiplies and adds for all four neurons at once. For neuron 1: $3 \times 0.5 + 1 \times 0.3 + 0 \times (-1.0) = 1.5 + 0.3 + 0 = 1.8$; plus bias $-1.0$ gives $0.8$. Neuron 2: $3 \times (-0.2) + 1 \times 0.8 + 0 = -0.6 + 0.8 = 0.2$; plus 0 gives $0.2$. Neuron 3: $3 \times 0.1 + 1 \times (-0.5) + 0 = 0.3 - 0.5 = -0.2$; plus 0.5 gives $0.3$. Neuron 4: $0 + 1 \times 0.2 + 0 = 0.2$; plus 0.1 gives $0.3$. So $z_1 = [0.8, 0.2, 0.3, 0.3]$.np.maximum(0, z1)applies ReLU. All four values are already positive, so $h = z_1$. (Had neuron 3's total stayed at $-0.2$, ReLU would have turned it into 0.)h @ W2 + b2: $0.8 \times 1.2 + 0.2 \times 0.7 + 0.3 \times (-0.4) + 0.3 \times 0.9 = 0.96 + 0.14 - 0.12 + 0.27 = 1.25$; plus $-0.5$ gives $z_2 = 0.75$.- Sigmoid: $e^{-0.75} \approx 0.4724$, so $p = 1 \div 1.4724 \approx 0.679$, which reads as "about 68% spam".
- Parameters: $W_1$ has $3 \times 4 = 12$, $b_1$ has 4, $W_2$ has $4 \times 1 = 4$, $b_2$ has 1. Total $12 + 4 + 4 + 1 = 21$, which matches
count_params([3, 4, 1]): $16 + 5 = 21$.
In real deep learning, nobody picks these weights by hand. Training starts from random weights and nudges them, over many examples, to reduce the error. That process uses derivatives and gradient descent, taught in Lessons 3.5 to 3.8.
Common mistakes and how to debug them
1. "AI means ChatGPT." - Symptom: Every AI example you give is a chatbot. In an interview you cannot name an AI system that is not generative. - Cause: Media coverage is dominated by GenAI. - Fix: Remember the nesting. GenAI is the innermost box. Route planners, fraud models and face unlock are all AI. Keep one example ready for each of the four categories.
2. Trusting the marketing label. - Symptom: You classify a product as ML because its website says "AI-powered machine learning". - Cause: Labels are chosen to sell, not to describe the mechanism. - Fix: Ask the three questions and look for evidence of the mechanism: training data, a model type, retraining schedules. If the vendor cannot say what the model learned from, assume RULES until shown otherwise.
3. Confusing "uses data" with "learns from data". - Symptom: Calling a dashboard that computes averages "AI" or "ML". - Cause: Any software processes data. Learning means the decision rule is chosen by fitting examples. - Fix: Ask: if the data changed, would the rule change by itself after retraining? For an average or a fixed threshold, no.
4. "Deep means clever" or "deep means hard". - Symptom: Calling a complicated but non-neural model (a large gradient-boosted tree ensemble) "deep learning". - Cause: Reading "deep" as an ordinary English word. - Fix: Deep means a neural network with many layers. Nothing else.
5. Calling recognition "generative". - Symptom: Labelling speech-to-text, OCR (reading printed or handwritten text from images) or face recognition as GENAI because the output is text or an identity. - Cause: Mixing up "outputs text" with "creates new content". - Fix: Ask whether the output records what was already there (a transcript, the digits on a cheque: DL) or makes something that did not exist (a new summary, a new image, a new voice recording: GENAI).
6. Classifying the whole product instead of the part. - Symptom: Arguing whether "the banking app" is ML or GenAI. - Cause: Real products combine several mechanisms. - Fix: Split the product into the decisions it makes and classify each one: rules route the request, a model scores risk, an LLM writes the reply.
7. Measuring on training data. - Symptom: A model scores very well in the notebook and badly after launch. - Cause: The accuracy was measured on the same examples used for training, which is always optimistic (rung 4: 0.875 on training, 0.75 on new emails). - Fix: Hold back test data that the model never sees during training, and report that number.
8. Forgetting that rules and models go stale. - Symptom: No error message at all. Performance slowly drops month after month (rung 11: 0.75 fell to 0.6). - Cause: Data drift. Users, fraudsters and markets change. - Fix: Monitor accuracy on recent labelled data, give every rule an owner, and retrain or redesign features when performance falls.
9. Trusting fluent GenAI output. - Symptom: A chatbot states a refund date, a policy clause or a statistic that does not exist. - Cause: Generative models produce likely-sounding content, not verified content (rung 9's "the refund is here"). - Fix: Give the model the source text to answer from, check key facts (numbers, names, dates) against the source automatically, and send high-stakes answers to a person.
10. Lab bug: comparing text with a number.
- Symptom: TypeError: '>=' not supported between instances of 'str' and 'int'
- Cause: A count was stored as the text "3" instead of the number 3, for example after reading it from a file or a form.
- Fix: Convert with int(...) before comparing: int(count) >= threshold.
11. Lab bug: running cells out of order.
- Symptom: NameError: name 'emails' is not defined
- Cause: A notebook cell that uses emails was run before the cell that creates it, or the notebook was restarted.
- Fix: Run the cells from the top, in order (in most notebook tools there is a "Run all" command).
12. Lab bug: > instead of >=.
- Symptom: No error, but the lab check "The learned threshold is 3" fails because the loop reports 2.
- Cause: count > threshold means "strictly more than". "More than 2" is the same rule as "3 or more", so the search finds the same rule but names it with the number 2.
- Fix: Use count >= threshold as the lab asks. The rule was right; only its name changed, which is why you must read the definition of a threshold carefully.
In production
Here is how these categories show up in real systems at scale.
Most production systems are hybrids. A payments company typically runs hand-written rules and ML models side by side. Rules encode regulations and hard limits ("block payments to sanctioned accounts", "cap at the daily UPI limit"), because these must be exact and auditable. ML models score risk for everything the rules let through, because fraud patterns shift faster than people can write rules. Deep networks read unstructured inputs such as scanned documents or selfies. GenAI increasingly drafts customer replies or summarises cases for human agents. An engineer who can map which component does what is far more useful than one who says "the AI does it".
Start with the simplest thing that works. Experienced teams build in this order: a rules baseline (hours), then a classic ML model on good features (days), then deep learning only if inputs are unstructured or the simpler model plateaus. A rules baseline also gives you a number to beat. If a model cannot beat the rules, it is not worth its extra cost and risk.
Tools by category. Classic ML in Python is usually built with scikit-learn, and gradient-boosted trees with libraries such as XGBoost or LightGBM. Deep learning is usually built with PyTorch or TensorFlow. GenAI applications usually call a hosted LLM through an API, or run an open-weights model. You will meet all of these later in the course; for now, knowing which category each belongs to is enough.
What goes wrong. - Rules sprawl. Over years, a rules system can grow to thousands of overlapping rules that nobody fully understands. Changing one breaks another. Keep rules few, documented and owned. - Silent drift. ML and rules both degrade without any error message. Production teams monitor input statistics and accuracy on freshly labelled samples and set alerts on drops. - Unfair outcomes. A model trained on past decisions repeats their unfairness. Teams break metrics down by group (walkthrough in rung 11) before launch and regularly after. - Unexplainable decisions. In lending and insurance, customers and regulators may ask why a decision was made. Teams often prefer simpler, explainable models for such decisions, or add explanation tools on top of complex ones. - Hallucination and prompt injection. GenAI systems can invent facts, and text written by an attacker (hidden in an email or web page the model reads) can try to steer the model's behaviour. Teams restrict what the model can do, ground answers in trusted documents, and check outputs. - Cost. Deep networks and LLMs need GPUs and cost far more per prediction than a rule or a small tree model. For high-volume, simple decisions this matters a great deal.
Documentation. Mature teams write down, for every model, what data it was trained on, what it is for, how it was evaluated and its known limits. When you classify a system with the three-question test and name its risks, you are writing the first lines of exactly this kind of document.
Interview preparation
-
Explain the difference between AI, ML, deep learning and generative AI. (fresher; asked at every level) Model answer: AI is the broad goal of software doing tasks that need human judgement, whether by written rules or learning. ML is the part of AI where the rule is learned from example data instead of being written by hand. Deep learning is ML with neural networks of many layers, which can learn features from raw data like images and audio. Generative AI uses deep models to create new content such as text or images. They nest: GenAI inside DL inside ML inside AI. Example: a route planner (AI, rules), a churn model with logistic regression (ML), face unlock (DL), a chatbot (GenAI).
-
Is every machine learning model a neural network? (fresher) Model answer: No. Linear and logistic regression, decision trees, gradient-boosted trees, k-means and Naive Bayes are all ML without neural networks. On tidy tabular data such as transactions, tree-based models are often the strongest choice. Neural networks are one family of ML models.
-
When would you choose rules over ML? (fresher, SDE-1) Model answer: When the logic is known exactly and must be applied exactly, such as tax slabs, regulatory limits or eligibility criteria; when there is little or no labelled data; when every decision must be fully explainable; or as a quick baseline. I would move to ML when the pattern is too complex to write down, labelled data exists, and a model clearly beats the rules baseline on held-out data.
-
What do training and inference mean? (fresher) Model answer: Training is the phase where the model's parameters are chosen by fitting labelled examples. Inference is using the trained model with fixed parameters to produce outputs for new inputs. Training is done occasionally and can be expensive; inference happens on every request and must be fast and cheap.
-
Why can't you report accuracy on the training data? (fresher, SDE-1) Model answer: The parameters were chosen to fit those exact examples, so the score is optimistically biased, and a flexible model can memorise them. The number that predicts real-world performance comes from held-out test data the model never saw during training.
-
What makes deep learning "deep", and why did it win on images and speech? (fresher, SDE-1) Model answer: "Deep" means many layers in a neural network. Each layer transforms its input into a more useful representation, so the network learns features from raw pixels or audio instead of relying on hand-designed ones. With large labelled datasets and GPUs, this beat hand-engineered features, famously on the ImageNet competition in 2012.
-
How many parameters does a fully connected network with layers [10, 20, 5] have? (fresher) Model answer: Each layer has $n_{\text{in}} \times n_{\text{out}}$ weights plus $n_{\text{out}}$ biases. $10 \times 20 + 20 = 220$ and $20 \times 5 + 5 = 105$, total 325.
-
A speech-to-text system outputs text. Is it generative AI? (SDE-1) Model answer: Under the definition that GenAI creates new content, no. It transcribes what was said, so it is a deep learning recognition system. A text-to-speech system that produces a new audio recording, or an LLM that writes a summary of the transcript, would be generative. I would state the definition I am using, because some people use "generative" more loosely for any model that outputs sequences.
-
What is hallucination, and how would you reduce it in a customer-support bot? (SDE-1, senior) Model answer: Hallucination is fluent generated content that is not supported by facts or the provided source. Language models produce likely-sounding text, not verified text. To reduce it: give the model the relevant policy documents in the prompt and instruct it to answer only from them, check key facts in the output (amounts, dates, order IDs) against the source or database, let the bot say "I don't know" and hand over to a person, and measure the hallucination rate on a test set of real questions.
-
A vendor says their thermostat is "AI-powered". How do you evaluate the claim? (fresher) Model answer: Apply the three-question test. Ask where the decision rule comes from. If it is a fixed setpoint or schedule written by an engineer, it is rules-based automation, not ML. If it learns the household's patterns from sensor data, it is ML; I would ask what data it trains on and how it is evaluated. I would reply politely with the category and the evidence.
-
Give one typical risk for each of rules, ML, DL and GenAI. (fresher) Model answer: Rules: brittle when the world changes and nobody updates them. ML: copies bias in its training data and drifts as data changes. DL: hard to explain individual decisions. GenAI: hallucination, confidently stating false things. Each needs a matching control: rule ownership, monitoring and group-wise evaluation, explanation tools or simpler models for regulated decisions, and grounding plus output checks.
-
Write a function that learns the best threshold for a one-feature classifier. (fresher, SDE-1) Model answer: Try each candidate threshold, measure accuracy, keep the best; break ties towards the smaller threshold.
def learn_threshold(data, candidates):
best = None
best_acc = -1.0
for t in candidates:
acc = sum((x >= t) == y for x, y in data) / len(data)
if acc > best_acc:
best, best_acc = t, acc
return best, best_acc
print(learn_threshold(emails, range(0, 9)))
(3, 0.875)
(x >= t) == y is True when the prediction matches the label; sum counts True as 1. This is training by exhaustive search, the simplest form of learning.
-
Your team's fraud model accuracy fell from 94% to 85% over three months, with no code change. What do you investigate? (SDE-1, senior) Model answer: Data drift first: compare recent input distributions (transaction amounts, merchant types, channels) with the training data, and check whether fraud patterns changed. Check the labels too: delayed or changed labelling can make accuracy look worse. Check upstream data pipelines for broken or renamed fields. Then retrain on recent data, consider new features, and add monitoring with alerts so the next drop is caught earlier.
-
A product manager wants to use an LLM to approve or reject loan applications. What do you say? (senior) Model answer: Approval is a classification decision on structured data, so a classic ML model (or a scorecard) is the natural fit: cheaper, faster, easier to evaluate and easier to explain to customers and regulators. An LLM adds hallucination and opacity risks without a clear benefit for this decision. An LLM could help elsewhere, for example summarising documents for a human underwriter. I would propose a rules and ML baseline, evaluated on held-out data and broken down by group.
Cheat sheet
| Idea | One-line meaning | Example | Typical risk |
|---|---|---|---|
| AI | Software doing tasks that need judgement | Route planner, chess engine | Over-claimed in marketing |
| RULES | AI whose logic a person wrote | "5+ suspicious words = spam" | Brittle; goes stale |
| ML | Rule learned from examples | Logistic regression churn model | Copies data bias; drift |
| DL | ML with many-layer neural networks | Face unlock, plant ID | Hard to explain; costly |
| GENAI | DL that creates new content | Chatbot, text-to-image | Hallucination |
The three-question test: (1) person or data? person → RULES. (2) deep network? no → ML. (3) new content? yes → GENAI, no → DL. Pick the innermost box. For products, classify each component.
Nesting: $\text{GenAI} \subset \text{DL} \subset \text{ML} \subset \text{AI}$. Not AI: plain arithmetic (averages, GST totals).
Key formulas: - Accuracy $= \dfrac{\text{correct}}{\text{total}}$; lab: human rule $11/16 = 0.6875$, learned $14/16 = 0.875$. - Training by search: $t^{*} = \arg\max_t \text{accuracy}(t)$. - Neuron: $z = \sum_i w_i x_i + b$, $a = g(z)$; ReLU $\max(0, z)$; sigmoid $1/(1 + e^{-z})$. - Dense layer parameters: $n_{\text{in}} \times n_{\text{out}} + n_{\text{out}}$. - Least-squares line: $m = \sum (x - \bar{x})(y - \bar{y}) / \sum (x - \bar{x})^2$, $b = \bar{y} - m\bar{x}$. - Image size: height × width × channels, e.g. $224 \times 224 \times 3 = 150{,}528$.
Rules of thumb: - The mechanism decides the category, not the appearance or the label. - Supervised: labels given. Classification → category; regression → number. Unsupervised: no labels (clustering). - Tidy tables → classic ML is often best. Photos, audio, free text → DL. - Recognition (transcribe, detect, identify) → DL. Creation (write, draw, speak new) → GENAI. - Always measure on held-out data, and break metrics down by group. - Accuracy hides mistake types: count false positives and false negatives separately. - Rules need owners; models need monitoring; GenAI needs grounding and checks.
Key terms
- Artificial intelligence (AI)
- Machine learning (ML)
- Deep learning (DL)
- Generative AI (GenAI)
- Rules-based system
- Expert system
- Model
- Parameter
- Training
- Inference
- Training data
- Test data
- Generalisation
- Overfitting
- Supervised learning
- Unsupervised learning
- Classification
- Regression
- Clustering
- Label
- Feature
- Feature engineering
- Feature vector
- Threshold
- Accuracy
- False positive
- False negative
- Neural network
- Neuron
- Weight
- Bias (neuron)
- Activation function
- Hidden layer
- Convolutional neural network (CNN)
- Transformer
- Large language model (LLM)
- Token
- Hallucination
- Data drift
- Bias (fairness)