The phone that guesses your next word
Artificial intelligence, or AI, is a computer program that finds patterns in examples and uses them to guess. Your phone does it when it suggests the next word of a message.
AI is in apps you use every day. Knowing what it is, and what it is not, helps you use it well.
By the end of this lesson
Note
I can explain what AI is and what it is not.
Key words
| Word | What it means |
|---|---|
| AI | a program that makes guesses from patterns in examples |
| Pattern | something that happens again and again |
| Example | one piece of data the program learns from |
| Training | showing a program many examples |
| Guess | an answer that may be right or wrong |
The cells students fill in are left blank in this preview.
AI finds patterns and makes a guess
An ordinary program follows rules that a person wrote. An AI program is shown thousands of examples instead. This is called training. The program finds the patterns, then uses them to guess.
A junk mail filter is one. It has seen many messages marked junk or not junk. It guesses which kind a new message is.
A tiny pattern-finder you can run
The program below has four messages that a person already sorted. For a new message, it counts the words it shares with each sorted one. The side with more shared words wins.
Press Run. Then change the last message to one of your own and run it again.
Guess junk or not junk
# Messages a person has already sorted.
examples = [
["win a free phone now", "junk"],
["free prize click now", "junk"],
["are you at football tonight", "ok"],
["see you at the bus stop", "ok"],
]
def guess(message):
junk = 0
ok = 0
for example in examples:
for word in message.split():
if word in example[0].split():
if example[1] == "junk":
junk = junk + 1
else:
ok = ok + 1
if junk > ok:
return "junk"
if ok > junk:
return "ok"
return "not sure"
print(guess("free phone"))
print(guess("football tonight"))
print(guess("hello there"))
A new example changes the guess
A pattern-finder only knows its examples. Give it a new one and its guesses can change.
Below, an ok message about a phone has been added. Press Run. In the first Run, a message about a phone was guessed as junk.
Add one more example
examples = [
["win a free phone now", "junk"],
["free prize click now", "junk"],
["are you at football tonight", "ok"],
["see you at the bus stop", "ok"],
# The new example.
["my new phone is great", "ok"],
]
def guess(message):
junk = 0
ok = 0
for example in examples:
for word in message.split():
if word in example[0].split():
if example[1] == "junk":
junk = junk + 1
else:
ok = ok + 1
if junk > ok:
return "junk"
if ok > junk:
return "ok"
return "not sure"
print(guess("new phone"))
What AI is not
AI is not a person. It has no feelings, no opinions and no idea what is true. It does not understand a message the way you do.
It can only be as good as its examples. Wrong examples give wrong guesses. One-sided examples give one-sided guesses.
Worked example: where you meet AI
| Where | What it guesses |
|---|---|
| A phone keyboard | The next word you will type |
| A music app | A song you may like |
| A maps app | How long the bus will take |
| A junk mail filter | Whether a message is junk |
| A chatbot | The words of a reply |
| A shop website | What you may want to buy next |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think AI understands them like a person does. It does not. It matches patterns from examples, so it can sound clever and still get simple things wrong.
Going further: what if the examples are one-sided?
In the Run, both junk examples are about prizes and phones. So a real message about a new phone could be marked junk.
Add two more examples to the list, one junk and one ok. Which new messages does the program now guess better?