Grokking LLM Essentials
Vote

0% completed

​

The Life of a Prompt

Part 1: The Text Is Cut Into Tokens

Part 2: Each Token Becomes a List of Numbers

Part 3: The Model Uses the Other Words as Context

Part 4: Every Possible Next Token Gets a Chance

Part 5: One Token Is Chosen, and the Loop Repeats

Key Takeaways

The five steps from a prompt to the next token, shown for the sentence about the chef
The five steps from a prompt to the next token, shown for the sentence about the chef

Look at the diagram from top to bottom. Each row is one step, and the right side of each row shows what the step does to the sentence about the chef.

The text that a person sends to a model is called a prompt. A prompt can be a question, an instruction, or an unfinished sentence such as this one:

The chef tasted the soup and said it needed more

What a Large Language Model Is described the model as a program that reads text and predicts the next word. This lesson divides that work into five steps. Each part below describes one step in a few sentences and names the lesson that explains it in full.

Part 1: The Text Is Cut Into Tokens

A model calculates only with numbers, so it cannot use letters directly. The first step prepares the text by cutting it into small pieces called tokens. A common word is usually one token, and a long or rare word is cut into several tokens.

The sentence about the chef has 10 words. One widely used program for this step cuts it into exactly 10 tokens, one for each word. In the diagram, each box in the first row is one token.

A separate program does this step before the model starts its calculation. Tokens: How Text Becomes Numbers explains where that program cuts a text and why.

Part 2: Each Token Becomes a List of Numbers

In the second step, each token is replaced by a long list of numbers. The list holds what the model learned about the meaning of that token. In a real model, one list has hundreds or thousands of numbers.

The lists follow a pattern. Tokens with similar meanings have similar lists, so the list for "soup" is close to the list for "stew" and far from the list for "car". The diagram shows the first three numbers of the list for "chef", and those three numbers are illustrative.

After this step, the sentence is 10 lists of numbers. Embeddings: How Numbers Hold Meaning explains where the lists come from and how two lists are compared.

Part 3: The Model Uses the Other Words as Context

Each list from step 2 describes one token and holds nothing about the rest of the sentence. That is not enough, because the meaning of a word often depends on the words around it, which are called its context. In the sentence about the chef, the word "it" has no clear meaning until it is connected to "soup".

The third step makes that connection. The model changes the list of every token by using information from the other tokens. After this step, the list for "it" holds information that came mostly from "soup".

The model does this work many times and not once. Each repeat starts from the lists that the repeat before it produced. Attention: How Words Use Context explains how one token takes information from another. The Transformer in One Picture shows how the repeats are arranged inside the model.

Part 4: Every Possible Next Token Gets a Chance

The fourth step uses the lists from step 3 to calculate a chance for every token the model can produce. This is the list of chances that the previous lesson introduced.

For the sentence about the chef, "salt" gets 0.62, "pepper" gets 0.11, and "seasoning" gets 0.07. Thousands of other tokens share the rest, and all the chances add up to 1. These are the same illustrative numbers as before.

Nothing has been chosen at this point. The output of the model is the whole list and not one token. Choosing the Next Word describes this list in more detail.

Part 5: One Token Is Chosen, and the Loop Repeats

The fifth step chooses one token from the list. A token with a high chance is chosen more often, so "salt" is the most likely result for this sentence. The program then adds the chosen token to the end of the text. Choosing the Next Word also explains how the choice is made and why the same prompt can receive different answers.

One token is not an answer, so the steps run again on the longer text. The added piece is already a token, so the loop returns to step 2 and skips step 1. Each pass through steps 2 to 5 adds one token: first "salt", then "and", then "pepper". The loop ends when the chosen token is the stop signal.

The five steps do not show where the model's parameters come from. Every parameter that the model uses in steps 2 to 4 was learned before any prompt arrived. Learning by Predicting the Next Word explains how the model learned them.

Key Takeaways

  • A prompt is the text that a person sends to a model. The model turns it into an answer in five steps.
  • Steps 1 and 2 turn text into numbers. The prompt is cut into tokens, and each token becomes a list of numbers that holds its meaning.
  • Step 3 connects the tokens to each other. The list of each token takes information from the other tokens, and the model repeats this work many times.
  • Steps 4 and 5 produce one token. The model gives every possible next token a chance, one token is chosen and added, and the loop repeats.

Return to the diagram at the top of this lesson whenever you need to see where a later lesson fits. The next lesson, Tokens: How Text Becomes Numbers, starts with step 1 and shows how a sentence is cut into tokens.

Reading Progress

0%


Vote for new content

On This Page

Part 1: The Text Is Cut Into Tokens

Part 2: Each Token Becomes a List of Numbers

Part 3: The Model Uses the Other Words as Context

Part 4: Every Possible Next Token Gets a Chance

Part 5: One Token Is Chosen, and the Loop Repeats

Key Takeaways