What Happens Between Hitting Send and a Chatbot’s First Word?
You type, “Write a thank-you note to Aunt Jo for the drum kit. My parents say thanks, too.” You hit Send. For a moment there’s only a blinking dot. What has the chatbot got to do before it can give you so much as a “Dear”?
An online chatbot lets you trade messages with a computer. Its language model learned to predict the next bit of text by practicing on passages people had written. When it uses that practice to answer a new request, engineers call that inference. Before it can get to work on Aunt Jo’s note, your message has to reach the computers that run it.
What goes into the envelope
Your app can send along instructions for the assistant and some earlier turns in the chat. If you mentioned two messages ago that Aunt Jo loves bad jokes, those words can travel along, too. The whole package the model receives is its prompt.
A program called a tokenizer breaks the text into tokens, which can be whole words, parts of words or punctuation. Each token has a number the model can work with. The app can include special markers that show who said what and where the assistant’s answer should begin.
There’s a limit to how many tokens fit in the prompt and reply together. That space is the model’s context window. As a chat grows, the app may shorten older messages or leave them out. There goes the tip about the jokes.
- Jay Alammar and Maarten Grootendorst draw what happens when a model breaks a sentence into tokens.
- Their Python examples let you follow a prompt through a model and watch it pick what comes next.
At a busy service, your message may have to wait its turn. A computer chip can work on a group of requests at once, a trick called batching. The requests keep their own text and answers. Think of an elevator ride. Several people share the trip, and each gets off at the floor they chose.
The work behind the blinking dot
When the request about Aunt Jo reaches the front of the line, the model makes a first pass over the prompt. Engineers call this prefill. Since the whole message has arrived, the chip can work on many tokens at once. “Jo” follows “Aunt,” the drum kit is a gift, and you’ve asked for a note. Those clues can all influence how the reply starts.
The model gives each possible next token a score, and the service uses those scores to pick one. Suppose it picks Dear. That token joins the text on hand, and the model works out what should follow. Now Aunt makes more sense than it did before. This part of the job is called decoding. At each step, the model can use your request and everything it’s written so far.
It would be a waste to redo all the math for your original message every time another token appears. The service can keep some of those results in a cache, a temporary store. When it’s time to write Jo, the model can reuse work it already did on your note. The model learned how to write a letter long before you hit Send. The cache saves it some math on this one.
Where the Time Goes Before a Chatbot Replies
Why the words arrive in little bursts
The service can send text to your screen while the model is still writing. That’s streaming. Your app may display a few tokens together. When “Dear Aunt Jo” appears, the model may still be working on what your parents have to say about the drums.
This gives you two different waits. Send a long letter for the model to read, and you may wait longer for the first word. Ask for a three-page reply, and you’ll give it more work between the first word and the last. A busy service or a slow connection can stretch either wait.
For Aunt Jo, two sentences ought to do it. By the time you see “Dear,” the computer has already read who gave you the drum kit and who else sends their thanks. While you read the first line, it can still be working out how to thank her for the cymbals.
What Happens While an AI Model Is “Thinking”?
How AI Predicts the Next Word, Starting With “Peanut Butter and…”
QUOTE:
"Amateurs hack systems, professionals hack people."
