Skip to Content

What is an LLM?

A large language model does one thing. It looks at the text so far and predicts the next token, then does it again. Watch it happen, and change the temperature yourself.

10 minFree

Inside an LLM
  1. Tokenize
  2. Token IDs
  3. Embeddings
  4. Transformer
  5. Probabilities
  6. Sample
  7. Append
Prompt

The weather in Chennai is

Next-token probabilities

These appear once the transformer has run.

Output

The weather in Chennai is

Text

This is the prompt. Press Play to see how a large language model works out what comes next.

Token IDs, embeddings, scores and attention weights here are illustrative. The softmax and sampling are the real maths.

Background: the idea in plain words1 min read

ChatGPT, Gemini and Claude can seem to understand you, reason, and write code. That raises a fair question: what is really happening inside?

Underneath, each one is a large language model (LLM): a program that has learned patterns from a huge amount of text. It does the same small job over and over: given some text, predict what comes next.

It doesn't plan the whole answer first. It predicts one small piece of text (a token, which can be a word, part of a word or a punctuation mark), adds it to the text, and predicts again. A paragraph is just hundreds of these predictions in a row.

Here is one round, step by step. The model reads the text so far. It gives every possible next token a probability (a chance, such as 60%). One token is picked. That token is added to the end of the text, and the round starts again.

A tiny example, with made-up numbers. The text so far is "The weather in Chennai is". The model might give "hot" a high chance, "humid" a smaller one and "purple" almost none. Say "hot" is picked. The text is now "The weather in Chennai is hot", and the model predicts the next token after that.

A setting called temperature controls how adventurous the pick is. Low temperature keeps picking the safest token. High temperature takes more chances.

Press Play below to watch one sentence get finished. Then move the temperature slider while the probabilities are on screen, and press Resample to see a different continuation.

The five ideas to take away

  1. Tokens, not words. Models read and write tokens: whole words, pieces of words, or punctuation. Pricing and context limits are counted in tokens too.
  2. Everything becomes numbers. Each token becomes an ID, and each ID becomes an embedding (a long list of numbers). The model only ever does maths on those numbers.
  3. Attention is how it uses context. Inside the transformer, each token weighs how much every other token matters. That's how “weather” and “Chennai” shape the word that comes next.
  4. The output is a probability for every token. The model doesn't output an answer. It outputs how likely each possible next token is, and a sampler picks one.
  5. Temperature controls risk. Low temperature keeps picking the safest token, which is predictable and repetitive. High temperature takes chances, which can be creative or nonsense. For agents and factual answers, keep it low.
Go deeper

Why this matters for agents

1 min read

When an ADK agent “decides” to call a tool, it's this same process. The model predicts the tokens of a function call instead of the tokens of a sentence. Everything in the later tracks (tools, memory, evaluation) is built on top of next-token prediction.

Go deeper

Words to know

1 min read
WordMeaning in simple words
LLMA large language model: a program trained on huge amounts of text to predict what comes next
TokenA small piece of text: a word, part of a word or a punctuation mark
ProbabilityHow likely something is, as a number or a percentage
SamplerThe step that picks one token from the model's probabilities
TemperatureA setting for risk: low picks the safest token, high takes more chances

Check your understanding

1. What does an LLM produce at each step?
2. Why is “Chennai” shown as two tokens (Chen + nai)?
3. You want an agent to give the same factual answer every time. What temperature should you use?
Sources: the official documentation1 link

This lesson is based on the official documentation. Check it for the latest details.

Something wrong or unclear in this lesson? Tell us, it gets fixed.