liveBook · Manning

Tokenization

As explained in Coding with AI

Tokenization is the process of breaking text into smaller units such as words, punctuation marks, or phrases.

Tokenization breaks text into smaller units—usually words, punctuation marks, or phrases—so computers can process and analyze its structure. NLP systems use these tokens to examine word frequency, word types, co-occurrence, and text categories. section 2.4

Turning a sentence into tokens

The sentence “My name is Jeremy, and I like apples.” becomes separate tokens for each word and punctuation mark: My, Name, is, Jeremy, comma, and, I, like, apples, period. These tokens become building blocks for later text analysis. section 2.5

A practical word-frequency workflow combines tokenization with normalization:

  • Read a text file, convert its contents to lowercase, and remove punctuation before counting words. section 2.5
  • Tokenize the cleaned text, count unique and repeated words, and identify the most frequent terms. section 2.5
  • Normalization prevents variants such as “truck,” “Truck,” and “truck!” from being counted as different words. section 2.5
Figure 2.11 Word-based tokenization breaks whole words and punctuation into chunks that can be processed and analyzed.

Shows word-based tokenization visually, including the separation of words and punctuation into processable chunks. section 2.4

How Coding with AI covers it

How deep it goes
Defines word-based tokenization and demonstrates preprocessing and counting, while deferring deeper NLP treatment.
Examples
Uses a sentence-token list and a truck-frequency example to demonstrate punctuation handling, normalization, and word counting.
What it assumes
Teaches tokenization from a basic definition and assumes only text that can be read and prepared for analysis.
What you can do after
Apply it in a Python workflow that cleans text, counts word frequencies, and displays the most frequent words.
How it connects
Connects tokenization to natural language processing, word frequency, text classification, sentiment analysis, and text summarization.

Also explained in

Compare how 25 books explain tokenization →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Coding with AI. The section links point to the parts of the book it draws on.