Ai Engineering Core / Transformers, Tokens & Context Windows

What are Tokens?

๐Ÿ“Œ What Are Tokens?

Tokens are the basic units of text that language models process โ€” not full words, not single characters, but meaningful chunks in between.

A token can be a character, a word fragment, a full word, or even multiple common words combined.

Text

Tokens

hello

hello

playing

play + ing

New York

New York

unbelievable

un + believ + able

LLMs do not directly understand raw text. They first convert text into tokens, and each token gets a unique Token ID.


๐Ÿ•ฐ๏ธ Evolution of Text Processing

1๏ธโƒฃ Character-Level Models

Early networks processed text one character at a time: h โ†’ e โ†’ l โ†’ l โ†’ o

โœ… Advantages

  • Very small vocabulary

  • Only ~100 characters needed : uppercase, lowercase, punctuation

โŒ Problems

The neural network had to learn:

  • how characters form words

  • grammar

  • meaning

This was too difficult and inefficient.


2๏ธโƒฃ Word-Level Models

Each word became a separate input: "hello" = one unit

  • โœ… Easier to associate meaning with words

  • โŒ Vocabulary exploded โ€” millions of words, names, rare terms, spelling variations


3๏ธโƒฃ Tokens โœ… (The Breakthrough)

The solution was a clever middle ground โ€” not too small, not too big.

Instead of breaking text into only characters ๐Ÿ”ก or keeping it as only full words ๐Ÿ“–, the answer was to use chunks of text called tokens.

๐Ÿง  How Tokenization Works

A token can be many things:

Type

Example

๐Ÿ”ค Character

a

๐Ÿ”ง Word Fragment

ing

๐Ÿ  Full Word

house

๐Ÿ”— Multiple Words

in the

This balance creates a manageable vocabulary , better efficiency , and faster learning .

โšก Why Tokens Work So Well

โœ… 1. Efficient Vocabulary Size

Uncommon words simply break into smaller, familiar pieces โ€” so the vocabulary never explodes in size.

๐Ÿ”ฌ electromagnetism โ†’ electro + magnet + ism

โœ… 2. Faster Learning

Models quickly pick up on the meaning of reusable fragments:

Token

Meaning

un ๐Ÿšซ

negation

ing ๐Ÿ”„

ongoing action

tion ๐Ÿท๏ธ

noun formation

This helps models generalize across language far more effectively ๐ŸŒ.

โœ… 3. Better Understanding of Word Stems

Tokens naturally uncover root words and how modifiers shift meaning:

play + ing โ†’ in progressa

play + ed โ†’ in the past

play + er โ†’ a person

The model learns that play is the core idea ๐Ÿ’ก, and suffixes are just meaning-shapers โ€” a structure that mirrors human language beautifully ๐Ÿ—ฃ๏ธ.


๐Ÿ”„ Tokens vs Characters vs Words

Approach

Advantage

Problem

Characters

Small vocabulary

Hard to learn meaning

Words

Semantic meaning

Huge vocabulary

Tokens

Balanced approach

Best practical compromise


๐Ÿ” How a Model Processes Tokens

Raw Text โ†’ Tokenizer โ†’ Token IDs โ†’ Neural Network โ†’ Predicted Next Token

Example:"Hello world" โ†’ [15496, 995]

The numbers are Token IDs โ€” the actual input the model receives.


โš ๏ธ Tokens Are NOT Vectors

This is a common confusion.

Concept

What It Is

When It Appears

Token

A text chunk

Input to the model

Token ID

Numeric identifier

During tokenization

Vector / Embedding

Mathematical representation of meaning

Inside the network, after input

Vectors are generated after the token is passed into the neural network. They encode semantic meaning โ€” tokens do not.


๐Ÿ” GPT Tokenizer

GPT models use a tokenizer to convert text into tokens โ€” and you can watch it happen live! ๐Ÿ‘€

๐Ÿ› ๏ธ Tools to Try

๐Ÿ‘๏ธ What You Can Visualize

  • โœ‚๏ธ How text splits into tokens

  • ๐Ÿ”ข Token counts

  • ๐Ÿชช Token IDs

Lets try OpenAI Tokenizer Playground

As seen in the example above, a sentence doesn't stay whole โ€” it gets broken down into small chunks ๐Ÿงฉ, each one a token. And every single token carries its own unique ID ๐Ÿชช, like a fingerprint for that piece of text.