AI Dictionary of Terms

Token

The basic unit of text that AI language models process, where text is broken down into smaller pieces (words, subwords, or characters) that the model can understand and work with.

The Simple Version

Imagine you’re trying to teach a computer to read, but the computer can’t understand whole words like humans do. Instead, you need to break sentences into tiny puzzle pieces that the computer can handle.

These puzzle pieces are called “tokens.” Sometimes a token is a whole word like “cat.” Sometimes it’s part of a word like “ing” from “running.” Sometimes it’s even just a single letter or punctuation mark like “.” or “?”.

When you type a sentence into an AI, the first thing it does is chop your sentence into tokens. Then it processes each token, understands how they relate to each other, and generates its response — also as tokens — which it then stitches back together into words you can read.

It’s like the difference between seeing a whole photograph versus seeing it as individual pixels. The AI works with the “pixels” of language (tokens) to understand and create text.

Detailed Explanation

Tokens are the atomic units of text processing in language models. Before any text can be processed by an LLM, it must be converted into tokens through a process called tokenization.

How tokenization works:

  1. Text Input: Raw text string (e.g., “The quick brown fox jumps”)
  2. Tokenization: Text is split into tokens using a tokenizer algorithm
  3. Token IDs: Each token is mapped to a unique integer ID from the model’s vocabulary
  4. Embedding: Token IDs are converted to high-dimensional vectors (embeddings)
  5. Processing: Model processes the sequence of embeddings
  6. Detokenization: Output tokens are converted back to text

Types of tokenization:

Token examples:

Why tokens matter:

Key Characteristics

Business Context

Understanding tokens is critical for enterprise AI deployment because they directly impact cost, performance, and user experience:

Cost implications:

Performance considerations:

Operational impact:

Strategic decisions:

Real-World Analogy

Counting words in an essay for a class assignment. Your teacher says the essay must be “500 words.” But what counts as a word? Does “don’t” count as one word or two? Does a hyphenated word like “well-being” count as one or two?

Tokens are like that, but for AI. The tokenizer is the “word counter” that decides how to break text into pieces. Different tokenizers might count differently, just like different people might count “don’t” differently. The important thing is that the AI and the tokenizer agree on the rules.

Code Example

# Tokenization examples using Hugging Face Transformers
from transformers import AutoTokenizer

# Load GPT-2 tokenizer
tokenizer = AutoTokenizer.from_pretrained("gpt2")

# Example text
text = "The quick brown fox jumps over the lazy dog."

# Tokenize
tokens = tokenizer.tokenize(text)
print("Tokens:", tokens)

# Get token IDs
token_ids = tokenizer.encode(text)
print("Token IDs:", token_ids)
print("Number of tokens:", len(token_ids))

# Decode back to text
decoded = tokenizer.decode(token_ids)
print("Decoded:", decoded)

# Compare with a word that might be split into subwords
complex_word = "unbelievable"
tokens_complex = tokenizer.tokenize(complex_word)
print("Tokens for 'unbelievable':", tokens_complex)

# Count tokens for cost estimation
long_text = "This is a much longer document that would cost more to process..."
token_count = len(tokenizer.encode(long_text))
cost_per_1k = 0.03
estimated_cost = (token_count / 1000) * cost_per_1k
print("Token count:", token_count, "Estimated cost: $", round(estimated_cost, 4))

Common Misconceptions

Sources & Further Reading