liveBook · Manning

Tokenizer

As explained in Domain-Specific Small Language Models

A model-specific component that converts concatenated instruction/output text into token sequences for fine-tuning.

A tokenizer converts raw text into model-specific tokens and numerical IDs that models consume during training and inference. Tokens may represent words, subwords, characters, punctuation, or special characters. section 2.1.1 section 2.6

Operationally, tokenization determines how text fits and flows through a model:

  • Match the tokenizer to the model architecture, because pretrained models expect specific token formats. section 2.1.1
  • Use padding and truncation to create consistent-length inputs within the model’s maximum token limit. section 2.1.1
  • Handle architecture-specific markers: BERT uses [CLS] and [SEP], while GPT workflows tokenize context for text generation. section 2.1.1 section 2.6
  • Account for token count when estimating processing time, memory use, and available prompt capacity. section 2.1.1

BERT classification input

Load BertTokenizer with bert-base-uncased, format text with [CLS] and [SEP], then request padded, truncated PyTorch tensors for model input.

Question-answering inference

Tokenize a question together with its context, pass the tensors to the model, select predicted start and end positions, and decode the answer tokens.

How Domain-Specific Small Language Models covers it

How deep it goes
Explains token types, model-specific formats, special tokens, padding, truncation, and IDs, but not tokenizer construction internals.
Examples
Demonstrates BERT sentiment inputs, question-answering preprocessing, GPT-Neo prompts, padding, truncation, and answer decoding.
What it assumes
Teaches tokens and numerical representations directly while assuming familiarity with pretrained models and basic machine-learning workflows.
What you can do after
Apply it via Hugging Face Transformers to prepare padded or truncated inputs and decode model outputs.
How it connects
Connects tokenizers with BERT, GPT, fine-tuning, inference, attention masks, and Hugging Face Transformers.

Also explained in

Compare how 16 books explain tokenizer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Domain-Specific Small Language Models. The section links point to the parts of the book it draws on.