…
…
AI Fundamentals · Lesson 2 / 31 · A look at artificial intelligence
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.
In the last lesson Elena got her intern to agree that the help desk is an AI job, and now she asks the real question: which AI does the desk need? The intern sees three separate ideas: a system that sorts an incoming question into the right unit, a system that suggests a similar old question and its ready answer, and a system that writes an answer draft for the student. In this lesson you will first recognize these three kinds on your own phone, and then return to the desk.
In the previous lesson we defined AI as "a program that learns from examples and makes predictions". This definition fits every AI, but not all of them do the same job. Some name a decision, some give you a ranked list, and some write a text that did not exist before. In this lesson you will learn to tell these three kinds apart. This matters because each kind goes wrong in a different way: you cannot check a system that makes a wrong decision and a system that writes a wrong text with the same method.
By the end of the lesson you will have the whole table below. We picked eight moments from an ordinary day of a student named Alex. For now the last two columns are empty; we will fill them in during the lesson.
| Time | Moment | Kind | What does it predict? |
|---|---|---|---|
| 07:40 | The keyboard suggests the next word while typing | ||
| 08:10 | The map says "24 min to school" | ||
| 09:00 | In email, 3 messages landed in the spam folder | ||
| 12:30 | A "for you" list in a music app | ||
| 15:00 | Photos are grouped by person | ||
| 18:20 | The next video in a video app | ||
| 20:00 | A translation app translates a restaurant menu | ||
| 21:30 | A chat assistant summarizes lecture notes |
Look at the table carefully: of the eight moments, only one is a chat assistant. Most people think only of a chatbot when they hear "AI", but Alex is surrounded by AI from morning to night, and most of it goes unnoticed. In this lesson you will:
The most common kind is a system that looks at an input and gives a single answer. This answer is either a category (is this message spam, whose face is this) or a number (in how many minutes will you arrive at school). We will call this kind a predictive system. The email app looks at each incoming message and says "spam" or "normal"; the three messages Alex saw in the morning are the result of this decision. The map looks at the traffic at that hour and past trips and says "24 minutes"; this is a number prediction. The photo app looks at a face and says "this is person 3 in the album"; again a category.
The first idea at Elena's desk is of this kind too: read the incoming question and sort it into the "aid", "residence", or "enrollment" unit. The system does not write a new text and does not offer a ranked list; it picks a single label.
Pick what each moment is predicting.
For each row, pick its match from the list, then check.
A common misunderstanding is to think that a predictive system "thinks cleverly" and then decides. Remember from the previous lesson: a model picks the answer that looks most like the examples it saw. When the map says "24 minutes", it does not see the road; it looks at how long similar trips at similar hours took.
When Alex opens the music app at lunch, a list called "for you" appears. The app does not give a single decision here; it ranks hundreds of songs and puts at the top the ones it predicts Alex will listen to the most. We call this kind a recommender system. A recommender system looks at two things: your past behavior (what you listened to, what you skipped) and other users who are similar to you.
Let's see how this works with a small example. There are five listeners and five songs (A, B, C, D, E); 1 shows that the person liked the song.
| Listener | A | B | C | D | E |
|---|---|---|---|---|---|
| Alex | 1 | 1 | 1 | 0 | 0 |
| Maya | 1 | 1 | 1 | 1 | 0 |
| Marco | 0 | 0 | 0 | 1 | 1 |
| Lena | 1 | 0 | 1 | 0 | 1 |
| Kai | 0 | 1 | 1 | 1 | 1 |
What should the app recommend to Alex? The method has three steps. First, count how many likes each listener shares with Alex: Maya 3 (A, B, C), Marco 0, Lena 2 (A, C), Kai 2 (B, C). Then pick the listener with the most shared likes, that is, the one most similar to Alex: Maya. Finally, recommend the song Maya liked and Alex has not listened to yet: D. The idea is: "If the person whose taste is closest to yours liked this, you will probably like it too."
The code below does exactly these three steps. You do not need to understand the code; change Alex's likes and watch how the recommendation changes. The code skips a listener who has no new song, because there is no recommendation to learn from them.
Change the songs Alex likes. How do the most similar listener and the recommendation change?
Pick a value; predict the output first, then look.
1alex = "ABC"2likes = {3 "Maya": "ABCD",4 "Marco": "DE",5 "Lena": "ACE",6 "Kai": "BCDE",7}8most_similar, most_common, recommendation = None, -1, []9for person, songs in likes.items():10 shared = len([s for s in songs if s in alex])11 new = [s for s in songs if s not in alex]12 print(f"{person}: shared likes {shared}, new songs: {', '.join(new) or 'none'}")13 if new and shared > most_common:14 most_similar, most_common, recommendation = person, shared, new15print("Most similar listener:", most_similar)16print("Recommendation for Alex:", ", ".join(recommendation))
Maya: shared likes 3, new songs: D Marco: shared likes 0, new songs: D, E Lena: shared likes 2, new songs: E Kai: shared likes 2, new songs: D, E Most similar listener: Maya Recommendation for Alex: D
Faded lines didn't run with this value. The code does three steps: it counts the shared likes with each listener, picks the most similar one among those who have new songs, and recommends the songs that listener likes and Alex has not listened to.
If Alex had liked only D and E, the most similar listener would be Marco, but Marco has no new song to recommend to Alex; the code therefore moved on to the next most similar person, Kai. As the likes changed, the recommendation changed. This is the whole secret of a recommender system: it does not know you, it only compares your behavior with the behavior of others.
Let's correct an important misunderstanding here. A recommender system does not find "the best thing for you". What it finds is the most likely click: the probability that you will listen to this song, watch this video, click this product. These two often overlap, but not always. The app does not know what is good, true, or useful; the only data it has is what you clicked and how long you looked.
In the evening Alex watched a 40-second cat video to the end in a video app. What does the app use to choose the next video?
The waiter comparison brings us to the most important side effect of recommender systems. Say that in Alex's video feed five genres start with equal shares: sports, music, science, food, gaming. Alex clicks a bit more on gaming videos, and slightly more on music. In every round the system shows more of what was clicked; what is shown more is clicked more; what is clicked more is shown even more. The code below imitates this loop. Increase the number of rounds.
Change the number of rounds: how do the genre shares change as Alex clicks on videos in the feed?
Pick a value; predict the output first, then look.
1rounds = 102shares = {"sports": 20, "music": 20, "science": 20, "food": 20, "gaming": 20}3interest = {"sports": 1.0, "music": 1.1, "science": 1.0, "food": 1.0, "gaming": 1.3}45for round_number in range(rounds):6 clicks = {g: shares[g] * interest[g] for g in shares}7 total = sum(clicks.values())8 shares = {g: clicks[g] / total * 100 for g in shares}910print(f"Shares in the feed (rounds = {rounds}):")11for g, p in shares.items():12 print(f" {g}: {round(p)}%")
Shares in the feed (rounds = 10): sports: 5% music: 13% science: 5% food: 5% gaming: 71%
Faded lines didn't run with this value. Alex's interest (the interest values) never changes; what changes in every round is only the distribution of shares shown. A small difference grows over the rounds.
In one round almost nothing changed; in ten rounds about 70% of the feed became gaming videos. Alex's interest did not change: the interest values in the code are the same in every round. What changed is what Alex is shown. This result is sometimes called a filter bubble: a person sits inside a bubble woven by their own clicks and keeps seeing similar things. Here are round 1 and round 10 side by side in a chart.
% · Simulation in the lesson (fictional)
| — | Round 1 | Round 10 |
|---|
Whether this is a problem depends on the situation. Watching gaming videos is not a bad thing. The problem is that Alex almost never sees science or food videos anymore and does not realize it. The system is not neutral: it amplifies not what Alex "wants" but what Alex "clicks". So what can you do when the feed narrows?
Alex's video feed has filled up with almost only gaming videos. Alex notices missing other topics. What should Alex do?
Pick an option and see what happens. There are no points; you can try the other options too.
At 21:30 at night, Alex pastes the lecture notes into the chat assistant and says "summarize this". The assistant does not pick a category and does not rank existing summaries; it writes a new text that was never written before. We call this kind a generative system. Generative systems produce text, images, or sound. The working idea is this: looking at the many examples it saw in training, it writes a likely continuation that fits the input you gave.
The translation app Alex uses in the evening is also of this kind: it does not find and bring a ready translation of the menu sentence; it writes a likely English sentence that fits it. The keyboard suggestion in the morning is the smallest form of the same idea: when you type "I have an exam", the keyboard suggests "tomorrow", because this word is the most likely continuation after this sequence of words. You can also see the keyboard as "predicting", because it picks a single word; the border between the kinds is not always sharp. We put it as the seed of the "generating" kind, because what it does is continue a text. The third idea at Elena's desk is this too: a system that writes an answer draft for the student.
Where does the chat assistant get the summary of Alex's lecture notes?
This kind is where the misunderstanding "AI finds an answer somewhere and brings it" is seen most often. When a summary is written in a sure tone, people think it was taken from a source. But the system did not open and read a source; you need to check separately whether what it wrote is true. You will see how to do this in lesson 4.
Now we can go back to the three ideas at Elena's desk. Each one is of a different kind, and each one's most likely mistake is different.
| Desk idea | Kind | What does it predict? | Most likely mistake |
|---|---|---|---|
| Sorts the question into a unit | Predicting | The unit the question will go to | Sends the question to the wrong unit |
| Suggests a similar old question and its answer | Recommending | The most useful old answer | The old answer may no longer be current |
| Writes an answer draft | Generating | A likely answer text for the question | May make up a rule or a date that does not exist |
Match each idea at Elena's desk with its kind and its most likely mistake.
For each row, pick its match from the list, then check.
Finally, let's look at the recommender system once more, because the reason for the narrow circle is hidden in its steps. The system does not run just once, it turns like a loop: every time Alex clicks, new data is produced, and this data feeds the next recommendation.
Put the steps of a recommender system in the right order.
Click the lines in order; to undo one you placed wrong, click it in the list below.
Shuffled lines
Your order
This loop has one more result: when two people open the same app, they do not see the same thing. Alex's home page and a friend's home page are different, because their histories are different. Assuming that what comes in front of you is what "everyone sees" or what is "most important" is the most common sign of using recommender systems without understanding them.
The filled-in version of the table at the start of the lesson. If you wrote the keyboard as "predicting", it is not a problem as long as your reasoning is right.
OutputTime Moment Kind What does it predict?
07:40 Keyboard suggestion Generating The likely continuation of what you type
08:10 Map arrival time Predicting Number: in how many minutes you arrive
09:00 Spam messages Predicting Category: spam or normal
12:30 "For you" list Recommending Which song you will listen to
15:00 Grouping photos Predicting Category: which person the face belongs to
18:20 Next video Recommending Which video you will watch
20:00 Menu translation Generating The likely English version of the sentence
21:30 Lecture note summary Generating A likely summary text that describes the notesThis time let's calculate by hand, for Lena, with the likes table from the lesson. Lena liked A, C, and E.
OutputShared likes: Alex 2 (A, C) · Maya 2 (A, C) · Marco 1 (E) · Kai 2 (C, E)
There is a tie: Alex, Maya, and Kai are equal with two shared likes each.
Their new songs: Alex → B · Maya → B, D · Kai → B, D
The recommendation all three share is B; Maya and Kai also recommend D.
Recommendation: B (all three similar listeners liked it)When there is a tie, real systems also look at other clues (how long the person listened, when they listened). In this example, the song that the most similar people share is the safest recommendation.
It is common for all three kinds to work inside the same app.
OutputScreen Kind What does it predict?
"Today's activity: brisk walk" Predicting Category: walk, run, or bike
"Workouts picked for you" list Recommending Which workout you will open and do
A short summary paragraph about your week Generating A likely text that fits your weekly dataThinking that "what I am shown is what everyone is shown". Alex always sees gaming videos on the home page and thinks "everyone is watching games these days"; a friend who runs the same search sees completely different results. This happens because a recommender system builds a separate ranking for every user: your history, your clicks, the preferences of people similar to you. The right approach: read the feed in front of you not as "the state of the world" but as "what the system predicted for me"; and if you want a general idea on a topic, deliberately look at different sources.
Next lesson: We start with the first idea for the desk, the system that sorts a question into a unit; but first we need to answer this question: do we write the rules for this system ourselves, or do we show it examples?
Exercises and quiz are for members
This lesson has 6 coding exercises and a 10-question quiz. Sign up free to solve them, save your progress and move on to the next lesson.
| sports | 19 | 5 |
|---|
| music | 20 | 13 |
|---|
| science | 19 | 5 |
|---|
| food | 19 | 5 |
|---|
| gaming | 24 | 71 |
|---|