Personal tools

Tokenization in AI Systems

Boston_Massachusetts_Forbes_110820A
[Boston, Massachusetts - Forbes]

- Overview

Tokenization is the essential first step in artificial intelligence (AI) where raw text, code, or data is broken down into smaller, manageable pieces called tokens before being converted into numbers for a model to process.

1. What is a Token? 

A token is a small chunk of data, typically a word fragment, a word, or a punctuation mark that an AI model uses as its basic unit of reading and writing. Before the model can process your question, it converts your text into a sequence of these numbered chunks.

1. Common Tokenization Methods:

  • Byte-Pair Encoding (BPE): Merges frequent character pairs iteratively; used by GPT models.
  • WordPiece: Optimizes splits based on training data likelihood; used by BERT.
  • SentencePiece: Processes raw text directly without space pre-tokenization; used by LLaMA.


2. Why Tokenization Matters:

  • Math translation: Neural networks operate strictly on numbers, requiring unique numerical IDs for each token.
  • Cost efficiency: API providers price services based on input and output token counts.
  • Context limits: Models have a fixed maximum context window of total tokens they can handle at once. 
 
 

- Tokenization in NLP

Tokenization in Natural Language Processing (NLP) is the foundational step of breaking down raw, unstructured text into smaller, manageable pieces called tokens. These tokens can be words, subwords, characters, or entire sentences. 

1. How It Works:

  • Segmentation: A computer program (called a tokenizer) scans text and splits it using rules like spaces (for words) or punctuation marks (for sentences).
  • Conversion: Each token is usually assigned a unique numerical ID. This allows artificial intelligence models to process text as numbers.

 

2. Main Types of Tokenization:

  • Word Tokenization: Splits a sentence into individual words (e.g., "Cats love fish" becomes ["Cats", "love", "fish"]).
  • Sentence Tokenization: Splits a large paragraph into individual sentences.
  • Subword Tokenization: Breaks down rare or complex words into smaller meaningful parts (e.g., "unfriendly" becomes ["un", "friend", "ly"]).
  • Character Tokenization: Splits text into every single letter or character. 

 

3. Why It Matters: 

Computers cannot read human language directly. Tokenization turns continuous text into discrete, countable units that machine learning models and large language models (LLMs) can analyze, index, and use for tasks like translation and sentiment analysis.

 

 

[More to come ...]


Document Actions