liveBook · Manning

Tokenizer

As explained in Deep Learning with Python, Third Edition

A component that converts text into a sequence of integer token IDs using a vocabulary and tokenization rules.

A tokenizer converts text into a sequence of integer token IDs. The practical pipeline has three stages: standardize input lightly, split it into tokens, and index those tokens through a vocabulary. The term often covers the entire process, while the tokenizer object specifically maps text to token indices. section 14.2

Build the idea from a short sentence:

  • Character splitting produces one token per character, including spaces. section 14.2
  • Word splitting keeps words and selected punctuation as separate tokens. section 14.2
  • Vocabulary lookup maps known tokens to fixed integers and sends unknown tokens to a special [UNK] index. section 14.2
  • Pretrained models require their matching tokenizer because different token IDs do not correspond to the learned token representations. section 15.4.2

From sentence to IDs

For “The quick brown fox jumped over the lazy dog.”, a word tokenizer emits words and punctuation, then vocabulary lookup produces [0, 2, 3, 4, 5, 6, 1, 0, 7, 8]. Here, “The” and “lazy” become [UNK] because they are absent from the demonstrated vocabulary. section 14.2

Listing 15.20 Loading the RoBERTa pretrained model with KerasHub
import keras_hub
 
tokenizer = keras_hub.models.Tokenizer.from_preset("roberta_base_en")
backbone = keras_hub.models.Backbone.from_preset("roberta_base_en")

Load a tokenizer together with the matching RoBERTa pretrained model through KerasHub’s from_preset() interface. section 15.4.2

How Deep Learning with Python, Third Edition covers it

How deep it goes
Explains standardization, splitting, vocabulary indexing, unknown tokens, and pretrained-tokenizer compatibility, but not tokenizer training internals.
Examples
Uses character and word splitting, vocabulary lookup with [UNK], and RoBERTa tokenization through KerasHub.
What it assumes
Assumes basic text handling and vocabulary lookup while building splitting, indexing, and tokenizer-model matching concretely.
What you can do after
Apply it via KerasHub by loading a matching RoBERTa tokenizer and converting text into integer arrays.
How it connects
Connects text preprocessing, vocabulary, subword tokenization, pretrained models, and Transformer architecture.

Also explained in

Compare how 16 books explain tokenizer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Deep Learning with Python, Third Edition. The section links point to the parts of the book it draws on.