DEV Community

Cover image for How ChatGPT Actually Predicts Words (Explained Simply)
Rajkiran
Rajkiran

Posted on • Originally published at rajkiran89.hashnode.dev

How ChatGPT Actually Predicts Words (Explained Simply)

Many people believe ChatGPT is a search engine or a giant database of pre-written answers. In reality, it is neither. ChatGPT is a prediction engine. It generates text by calculating the most statistically probable "token" that should come next in a sequence.

  1. Tokenization: The Language of Numbers ChatGPT doesn't see "words"; it sees tokens. Through a process called Tokenization, the model slices text into pieces and assigns each a unique ID.

Common words (like "the") get their own ID because they appear frequently in the vocabulary.

Rare or complex words (like "bioluminescence") are sliced into sub-tokens, each with its own ID.

This isn't a random dictionary. It is built using Byte-Pair Encoding (BPE), a sub-word algorithm trained on massive datasets (with a vocabulary of 50,000 to 100,000 tokens) that iteratively merges common character sequences into single tokens.

  1. The Giant Game of "Fill in the Blanks" Text generation is essentially a high-stakes game of probability powered by Weights and Attention. When you provide a prompt, the model uses its Attention mechanism to see which parts of your context matter most.

It then calculates a probability score for every single token in its vocabulary. For example, if the input is: "The capital of France is..."

Paris: 92%

Lyon: 3%

Baguette: 0.1%

Once it selects "Paris," it appends that word to the text and reruns the entire loop to predict the next token (like a period or a new sentence).

  1. Temperature: The Creativity Dial You can control how "risky" the model's guesses are using a setting called Temperature:

Low Temp (The Reliable Specialist): It focuses strictly on the highest-scoring tokens. It will almost always pick "Paris." This is best for factual tasks like coding or math.

Medium Temp (The Balanced Conversationalist): The default setting. It allows for more variety, making the text feel natural and human-like. Perfect for emails and articles.

High Temp (The Wild Artist): The model takes risks, often choosing lower-probability tokens. It might skip "Paris" for something more poetic or abstract. This is best for brainstorming and creative writing.

Conclusion: Math, Not Magic

Understanding that ChatGPT is a prediction engine—not a conscious mind—changes how we interact with it. By mastering tokens, context, and temperature, you can stop "guessing" what the AI will say and start "steering" it toward the results you need. Next time you get a strange answer, remember: it’s just the math taking a creative risk!

Top comments (0)