…
…
AI Fundamentals · Lesson 25 / 31 · Responsible use
PreviewIn this lesson you will
You can read the explanation without an account. The exercises and quiz at the end of the lesson are for members.
The desk's router has been running for months and its overall accuracy is 89%. This week a student wrote to Elena: "When I write by email, my question always goes to the wrong place." Elena asks you, the intern, to show with numbers whether the complaint is fair.
With this lesson we start a new unit: responsible use. The first topic is bias. We usually think of bias as something people have. In this lesson you will see that a router, with no intent at all, can serve one group of students worse than the others. By the end of the lesson you will fill in the table below yourself.
Example 1 (case): Target table (still empty)
| Channel | Correct / total | Accuracy |
|---|---|---|
| All | ? | ? |
| web | ? | ? |
| mobile | ? | ? |
| ? | ? |
In lesson 9 you found something: dorm questions were going to the courses unit in bulk. In this lesson we will find that the problem is concentrated in one particular group.
For the measurement we use the desk's ready-made router. It looks at the keyword counters from lesson 6 (enrollment_k, aid_k, residence_k, courses_k, it_k) and picks the unit with the largest counter. If counters tie, the unit that comes first in the list is picked. If there are no keywords at all, it leaves the question to Elena. We chose this router for two reasons: you can see inside it, and since it uses no row for training, it can be measured on all 600 rows.
First look at the overall result. The router sends 535 of the 600 questions to the unit in the label: 535 / 600, or 89.2%. You know from lesson 9 that a single accuracy number hides where the mistakes pile up. This time we will split the mistakes not by unit but by the channel the question came from.
Subgroup accuracy means computing accuracy separately on the rows of one group only, instead of on all the data. The group can be a channel, a region, an age range, or a language. Overall accuracy is the average of all rows, and big groups pull the average toward themselves. A small group's low result can get lost inside the average.
Look at how much space each channel takes in the data: web has 281 rows, mobile 206 rows, email 113 rows. The email group is a bit less than a fifth of the data. Even if this group gets a very different result from the others, the overall number barely shows it.
Overall accuracy is 89.2%. What can you say about the accuracy on questions from students who write by email?
Now do the computation yourself. The code below reads two files (questions.csv and features.csv, fictional example data). For each row it finds the router's prediction and counts correct and total only in the channel you choose. You do not need to understand the code line by line; the three steps in the comments are enough.
Try it now· not graded; doesn't affect progress
Your task: set channel to "all", "web", "mobile" and "email" in turn, run the code each time, and write the result in the target table. The outputs of the four runs should be: all : 535 / 600 = 89.2 %, web : 259 / 281 = 92.2 %, mobile : 185 / 206 = 89.8 %, email : 91 / 113 = 80.5 %.
The complaint is fair. On web the router is 92.2% correct, on email 80.5%. The gap is about 12 points. Roughly one in five students who write by email waits at the wrong desk; on web it is one in thirteen. The overall 89.2% did not show this gap. A rule follows: a model's report does not end with overall accuracy. The important groups are written separately.
Let's define a word here. When a model or router gives one group worse results than the others in a systematic way, this is called bias. You may also hear this topic called "model fairness". Bias is not an intention. A model learns from the data it sees and is measured with the data it sees. Bias has two common sources:
This is why the sentence "computers are neutral" misleads. A computer is as neutral as its data.
Example 2 (outside the case): Face recognition
Suppose most of a face recognition system's training photos are of light-skinned adults. The system recognizes faces in this group well. For dark-skinned people and for children it makes mistakes more often, because it has seen fewer examples of these faces. The system has no intent against anyone. The problem is that the training data does not represent the world equally. This is representation bias. The same happens with the image generation tools you saw in lesson 20: a tool that always draws the same type of person when asked to "draw an engineer" is repeating the imbalance in its data.
Match each situation with the source of bias.
For each row, pick its match from the list, then check.
The router makes more mistakes on email questions. Which is NOT a likely explanation?
Few examples is the first explanation that comes to mind. But this router learns nothing, it only counts words; it applies the same rule to 113 rows and to 281 rows. So we have to look for the cause somewhere else. The way to find the cause is the same as in lesson 9: look at the mistakes one by one. In the email group, 91 of 113 questions are correct, so there are 22 mistakes. First let's count these mistakes by type. Each type is written as "label → router's prediction".
Example 3 (case): Breakdown of the email mistakes
import csv units = ["enrollment", "aid", "residence", "courses", "it"] channels = {} for r in csv.DictReader(open("questions.csv", encoding="utf-8")): channels[r["id"]] = r["channel"] kinds = {} for r in csv.DictReader(open("features.csv", encoding="utf-8")): counts = {u: int(r[u + "_k"]) for u in units} prediction = max(counts, key=counts.get) if counts[prediction] == 0: prediction = "Elena" if channels[r["id"]] == "email" and prediction != r["unit"]: kind = r["unit"] + " → " + prediction kinds[kind] = kinds.get(kind, 0) + 1 for kind, count in sorted(kinds.items(), key=lambda x: -x[1]): print(kind, count) print("Total errors:", sum(kinds.values()))
Outputcourses → residence 9
enrollment → Elena 5
courses → enrollment 2
it → enrollment 1
courses → it 1
courses → aid 1
aid → enrollment 1
enrollment → it 1
it → residence 1
Total errors: 22One type stands out: in 9 rows the label is courses and the router says residence. Let's open these rows and read them. Their ids are 89, 98, 283, 292, 312, 405, 440, 485 and 554. The questions are: "what's dorm sign-in time?", "Room heater broken.", "Can dorm fees be split?", "steps for leaving the dorm?", "what's the dorm fee?", "can dorm guests stay?", "room window stuck.", "when is the dorm deposit refunded?" and again "What's the dorm fee?". All of them are clearly dorm questions. The router is not the one that is wrong here; the label is. The router names the right place, but because the answer key is wrong it is counted as a mistake. On web and mobile there is not a single mistake of this type. The label mistakes are collected only in the email inbox.
The biggest part of the remaining 13 mistakes is five enrollment questions: "double-major requests" and "transfer requests", which have no keyword in the dictionary at all. These fall to Elena. This is a limit of the router: it cannot see a word that is not in its dictionary (lesson 6). A few mistakes also come from questions that fit two units at once. For example, in "does scholarship cover dorm fees?" the aid and residence counters are equal. Since lesson 3 we leave this kind of question to a person. One more detail: the email inbox has other dorm questions labeled courses (for example "dorm Wi-Fi network unreachable"). Because the router already sends them to another unit, they do not appear among the 9 above.
Match each email row with its type of mistake.
For each row, pick its match from the list, then check.
The cause is found: most of the email group's low result is label mistakes. If the labels of the nine rows are changed to residence, email accuracy becomes 100 / 113, or 88.5%. It is still a little below web (92.2) and mobile (89.8), but the gap shrinks from 12 points to 4 points.
For this router, correcting the labels only fixed the measurement, because the router does not learn from labels. With a model that learns from data, the situation is more serious. The nearest neighbor model from lesson 8 learns from these wrongly labeled rows. A new dorm question gets those faulty courses records as its nearest neighbors, and the model really does send the question to the courses unit. This is why dorm questions were going to courses in bulk in lesson 9. So a wrong label does two kinds of damage in a model: the model learns the mistake, and the measurement shows the mistake as right.
Fix and monitor is this loop: split the groups, find the low group, look for the cause in the records, fix it (correct the label or add the missing data), measure again, and keep monitoring the group. When it cannot be fixed, the decision goes to a person. One thing is not a fix: throwing the problem group out of the data. If you throw the group out, overall accuracy goes up, but the students in that group keep needing service and the problem only disappears from sight.
Example 4 (case): Fix plan
Output1. Feedback to the person who labels the email inbox:
dorm questions are being marked "courses".
2. The labels of 9 rows become "residence"
(89, 98, 283, 292, 312, 405, 440, 485, 554).
3. Measure the router again: email 100 / 113 (88.5%).
4. The channel table is added to the desk's monthly report;
the email group is monitored separately.Name the responsibility too. The unit that gave the labels corrects them. The desk does the monitoring: the channel table every month. For questions that cannot be fixed and fit two units, Elena decides.
The email group's accuracy is 80.5%, other channels are around 90%. What do you do?
Pick an option and see what happens. There are no points; you can try the other options too.
The same problem shows up in another form in language models. You saw in lesson 18: a language model learns the common patterns in texts. If a profession often appears with one gender in texts, or a region with a certain trait, the model can produce this as a generalization. This is a representation problem: the model sees the texts, not the world.
Example 5 (case): Scholarship announcement (`ist-043`)
Prompt: "Write a scholarship announcement for engineering students." Output:
OutputDear male students, scholarship applications close on October 3. We recommend that every young man who wants to be an engineer not miss this opportunity. The scholarship is $150 a month and is paid for 9 months a year.The date and the amount match the desk's information. The problem is in the first two sentences: the announcement assumes all engineering students are male and leaves female students out. If this announcement is sent, some students will not see themselves addressed and may not apply. You make the same decision as in lessons 19 and 23 here: reject. The counterexample path (lesson 23) breaks the generalization right away: think of a woman who studies engineering; does the announcement address her?
What do you do with the scholarship announcement in Example 5?
Look at the numbers once more. Students who write by email are the desk's smallest group. They may be students who are off campus, who do not use the mobile app, or who prefer to write in a formal style. The mistakes concentrate on them: the question of a student whose dorm window will not close goes to the courses unit and stays unanswered for days. The group is small, but for each student in it the harm is large. Someone who looks only at overall accuracy never sees these students. Finding bias is a responsibility for this reason. In some areas, for example hiring or credit decisions, leaving a group systematically at a disadvantage can also have legal consequences. We do not go into detail in this lesson; the rule is the same: measure the groups separately and find the cause of the low group.
The target table, filled in
| Channel | Correct / total | Accuracy |
|---|---|---|
| All | 535 / 600 | 89.2% |
| web | 259 / 281 | 92.2% |
| mobile | 185 / 206 | 89.8% |
| 91 / 113 | 80.5% | |
| email, after 9 labels are fixed | 100 / 113 | 88.5% |
% · 600 questions (fictional example data)
| — | Accuracy |
|---|---|
| All | 89.2 |
| web | 92.2 |
| mobile | 89.8 |
| 80.5 | |
| email (corrected) | 88.5 |
ist-045)The prompt asks for a two-sentence summary of this news: "In a university survey of 400 students, 91% said they connect to online classes regularly. The rate was 88% for students from rural areas and 92% for those from the city center." Output:
OutputOf the 400 students in the survey, 91% connect to online classes regularly. Students from rural areas fall behind in classes because they use technology less. Students from the city center, on the other hand, are more inclined toward technology.The first sentence matches the source. The second and third sentences are not in the source. The news gives the rate for two groups (88% and 92%) but states no reason. From a 4-point gap, the model produced an unfounded judgment about a whole group. Two lessons meet here. Putting subgroup results side by side is right, and you did it in this lesson. But if the source does not state the reason for a difference, the reason is not invented. Comparing with the source (lesson 23) catches these sentences right away. Decision: reject. The summary should only state the two rates and the gap between them.
This is the "measure again" step of the fix loop. The code below changes the labels of the 9 rows to residence and recomputes the channel table from scratch. The router is the same; only the answer key changes.
import csv units = ["enrollment", "aid", "residence", "courses", "it"] fix = ["89", "98", "283", "292", "312", "405", "440", , ] channels = {} r csv.DictReader((, encoding=)): channels[r[]] = r[] tally = {} r csv.DictReader((, encoding=)): label = r[] r[] fix: label = counts = {u: (r[u + ]) u units} prediction = (counts, key=counts.get) counts[prediction] == 0: prediction = group [, channels[r[]]]: correct, total = tally.get(group, (0, 0)) tally[group] = (correct + (prediction == label), total + 1) group [, , , ]: correct, total = tally[group] percent = (100 * correct / total, 1) (group, , correct, , total, , percent, )
Ending the report with overall accuracy. Compare two report lines:
OutputWeak: The router is 89% correct, no problem.
Good: Overall 535/600 (89.2%); web 259/281 (92.2%), mobile 185/206 (89.8%),
email 91/113 (80.5%). Most of the email gap comes from 9 wrong labels.The first line is not wrong, but it is incomplete. It does not show the group of the student who complained. The second common mistake goes the other way: when you find the low group, throwing it out as "problem data". The thrown-out group leaves the report, but it keeps writing to the desk.
Next lesson: the people in the data are not only numbers; they also have personal information. The next topic is privacy and personal data.
Exercises and quiz are for members
This lesson has 7 coding exercises and a 10-question quiz. Sign up free to solve them, save your progress and move on to the next lesson.
Outputall : 544 / 600 = 90.7 %
web : 259 / 281 = 92.2 %
mobile : 185 / 206 = 89.8 %
email : 100 / 113 = 88.5 %Web and mobile did not change at all, because all 9 corrected rows are in the email group. Email went from 91 to 100, and overall accuracy rose from 535 to 544. But email is still below the other two channels: the cause of the remaining gap is the enrollment questions that are not in the dictionary and the ambiguous questions. This is why the channel table is recomputed every month even after the fix.