LLM fundamentals

5 concepts · 10 practice questions

Tokens

A model reads and writes tokens, not characters or words. A token is a chunk of text from the model's vocabulary, often a word piece. Limits, latency and price are all counted in tokens, and the count depends on the tokenizer, so the same text costs a different number of tokens on different models. Count with the provider's tokenizer or count endpoint instead of guessing from characters.

# Rough rule for English: 1 token is about 4 characters.
# Never rely on it for limits. Ask the tokenizer.
n = client.count_tokens(model=MODEL, messages=messages)
if n > INPUT_BUDGET:
    messages = trim_oldest_turns(messages, INPUT_BUDGET)

Also covered

The context window
Sampling and temperature
Prompt structure
Structured output

Sign in to read the rest and take the 10-question test.

Sign in to continue