Understanding AI · lesson 42 of 60 · about 5 minutes
Chances, Not Certainties
A chatbot doesn't just pick one next word; it gives every possible word a chance. Turn counts into chances.
What you'll learn
- Turn counts into chances
- Explain why chances add up to 1
- Read a chatbot's next-word chances
From counts to chances
If cats followed like 3 times out of 4, the chance of cats next is 3 out of 4: 0.75, or 75%. Dogs is 1 out of 4: 0.25.
A chatbot's final layer does the same job: it gives every token it knows a chance of coming next. All the chances add up to 1.
Counts after like, turned into chances. `values()` gives just the numbers from a dictionary.
counts = {"cats": 3, "dogs": 1}
total = sum(counts.values())
for word, count in counts.items():
print(word, count / total)Output
cats 0.75
dogs 0.25Tip
However the chances are spread, they always add up to 1.
Now try it yourself
This lesson is free in Codiqo, with 6 questions on what you just read. You can only learn to code by writing code, so it ends with a short program you write yourself, which we run and check straight away.