Skip to main content

Command Palette

Search for a command to run...

Explain Tokenization

Explain Tokenization to a freshers in friendly way

Published
•4 min read•View as Markdown
Explain Tokenization
H

Hi, Thank-you for stopping by and having a look at my profile. Hi! I’m a web developer who loves working with the MERN stack . I enjoy making interactive and user-friendly websites and webapps. I’m great at taking ideas and bringing them to life through coding!

Welcome to the world of Artificial Intelligence (AI) and Natural Language Processing (NLP)! One of the first words you’ll hear here is “Token.”

What is a Token?

Think of a token as a small piece of text.
It can be:

  • A word → "hello"

  • A part of a word → "ing" from "running"

  • Even a symbol → "?", ",", "!"

  • Character → "h", "e", "l"

Why Tokens are Important?

AI works better with small, clear pieces of text.
For example:
Sentence: "I love programming."
Tokens might look like:
["I", "love", "programming", "."]

What is Tokenization ?

Let us break down tokenization , It is the process of breaking text into smaller pieces (tokens) so that a computer can understand and process it.

Context Behind Tokenization

Computer cannot directly understand the human language ( Word , Sentences and paragraph ), They only understand numbers.

Human language is complex — words can be long, rare, or have multiple meanings

for example if we say "bank" so what does it means that is riverbank or financial bank. If we give raw text to a computer, it won’t make sense right.

Hence the solution is Break text into tokens (small pieces), which can then be mapped to numbers that models understand right , that’s how this problem is solvable .

Explaining the example of tokenization to freshers -

Imagine you’re reading a book in a new language. If someone gives you the entire book in one line, you won’t understand right.

But if they split it into words or sentences, it becomes easier.

Let’s say we have a sentence like “Machine Learning Is Fun”

  • Word Based tokenization.

    ["Machine", "Learning", "Is", "Fun"]

  • Sub-word Based tokenization.

    ["Machine", "Learn", "ing", "Is", "Fun"]

If you look at the example, we have a sentence like “Machine Learning is Fun,” and that is tokenized in two ways: word and subword.

Types of Tokenization

  • Whitespace Tokenization –

    Split by spaces → "I love AI" → ["I", "love", "AI"]

  • Word Tokenization –

    More advanced, handles punctuation → "I love AI!" → ["I", "love", "AI", "!"]

  • Subword Tokenization –

    Used in modern NLP (like GPT, BERT)

    • Break rare words into smaller parts → "unhappiness" → ["un", "happiness"]
  • Character Tokenization – Each character is a token → "AI" → ["A", "I"]

How Tokenization Works in GPT ?

When you type text into GPT:

  1. Your text is split into tokens according to the model which you are using for tokenizer.

  2. Each token is mapped to a unique token ID.

  3. These IDs are passed into the neural network to process the tokens.

  4. That model predicts the next token’s ID, converts it back to text, and repeats until it finishes the job.

    Example:

    Input: "AI is"
    Tokens: ["AI", " is"]
    IDs: [320, 318]

Why not just split text by spaces?

Splitting by spaces (whitespace tokenization) looks easy, but it fails in real-world cases:

Punctuation

  • "I love AI!" → ["I", "love", "AI!"]

  • The exclamation mark is stuck to "AI". Models treat "AI!" differently from "AI".

Big or rare words

  • Word: "unbelievable"

  • Space split → just ["unbelievable"]

  • If the model doesn’t know this word, it gets stuck.

  • Smart tokenizers break it into smaller pieces → ["un", "believ", "able"] so the model can still understand.

Languages without spaces

  • Chinese: "我喜欢AI" (means “I like AI”)

  • No spaces at all → space-split doesn’t work.

Different writing styles

  • "USA", "U.S.A.", "U. S. A."

  • Space-split treats them as different, but they actually mean the same thing.

Quick Analogy

Think of tokenization like chopping vegetables before cooking.

  • Whole vegetable = Raw text

  • Chopped pieces = Tokens

  • Cooking = Feeding into AI model

Without chopping, cooking becomes messy. Without tokenization, AI can’t "cook" (process) text. 🍲✨

Summary

Tokenization is the process of breaking text into smaller units called tokens (like words, subwords, or characters) so that a computer can understand and process it. Since machines work with numbers, tokens are later converted into numeric IDs before feeding them into models. It’s like chopping vegetables before cooking — smaller, manageable pieces make it easier to process.


I’m truly thankful for your time and effort in reading this.