← Back to course
2/6
Week 08 Β· How Generative AI Makes Things

Tuesday

Predict the next word
// From sorting to making
⏱ about 20 min

Tuesday: Predict the Next Word

Raven flips through the crew's mission log. "Look how often we write the same kinds of sentences."

She reads aloud. "Rocket spots a comet. Raven spots a planet. Rocket spots a comet again."

Rocket laughs. "We are not very creative log writers."

Nova taps the page with a beam of light. "But you are very predictable," she says.

"If I say 'Rocket', what word do you expect next?"

"Spots!" Rocket and Raven answer together.

"Then you just did a tiny version of next-word prediction," Nova says. "Let us count it carefully."

A pattern you can count

NIST explains that generative models make outputs that approximate the statistical patterns of their training data.

For example, large language models predict the next word in a sentence.

You can try a tiny paper version. Count which word follows which in some text, then pick the most common next word.

Mission log line
Rocket spots a comet.
Raven spots a planet.
Rocket spots a star.
Rocket logs a comet.
Raven logs a star.
Rocket spots a comet.

Here is a tally of the word that comes right after "Rocket" and the word that comes right after "spots a".

After thisNext wordTally
Rocketspots3
Rocketlogs1
spots acomet2
spots aplanet1
spots astar1
How many times does "Rocket" come right before "spots"?
After "spots a", which next word has the highest tally?
How many log lines are in the training text?
BE THE PREDICTOR
  • Read the question.
  • Tap your answer.
The sentence so far is "Rocket". What is the most likely next word?
The sentence so far is "Rocket spots a". What comes next?
Did the predictor need to know what a comet really is?
STEPS OF A PAPER NEXT-WORD PREDICTOR
  • ?Collect training text.
  • ?Count which word follows each word.
  • ?Start a sentence with one word.
  • ?Pick the next word with the highest count.
  • ?Repeat until the sentence ends.
WHY THIS EXERCISECounting patterns first, then choosing the most common next word, builds a sentence one word at a time.
Out of 4 times "Rocket" appears, "logs" follows once. How many times does "spots" follow? Type a number.
WHY THIS EXERCISE4 minus 1 is 3, which matches the tally table.
StatementTrue or false?
Large language models predict the next word in a sentence.?
The paper predictor can choose a word it never saw in training.?
A bigger tally means a word is more likely to be picked.?
WHY THIS EXERCISEThe predictor picks from words it counted, favoring the most common ones.
Try it
Copy three sentences from a page of any book you have nearby.
Pick one word that appears more than once. Tally the words that follow it each time.

Great predicting. Tomorrow in the Explorer Lab, you build a full paper predictor and let it write.

← Monday