---
title: "Tokenization in Transformers v5: Simpler, Clearer, and More Modular"
description: "Transformers v5 redesigns tokenizers so that tokenizer architecture (normalizer, pre-tokenizer, model, post-processor, decoder) is separated from the trained vocabulary, much as PyTorch separates model architecture from weights."
url: "https://swe.quest/articles/tokenization-in-transformers-v5-simpler-clearer-and-more-modular-71df3b1e7d817d35"
canonical: "https://huggingface.co/blog/tokenizers"
source: "Hugging Face"
published: "2025-12-18"
difficulty: "medium"
kind: "Deep dive"
reading_minutes: 14
tags: ["llms","python","open-source"]
---

# Tokenization in Transformers v5: Simpler, Clearer, and More Modular

A post on [Hugging Face](https://swe.quest/sources/hugging-face.md), published 2025-12-18, 14 min read, Deep dive. Original: [https://huggingface.co/blog/tokenizers](https://huggingface.co/blog/tokenizers)

## Summary

Transformers v5 redesigns tokenizers so that tokenizer architecture (normalizer, pre-tokenizer, model, post-processor, decoder) is separated from the trained vocabulary, much as PyTorch separates model architecture from weights. The walkthrough covers the tokenization pipeline stages, the BPE, Unigram and WordPiece algorithms, and how the transformers wrapper adds chat templates, special tokens, truncation and padding on top of the Rust tokenizers library. It also lays out the class hierarchy: PreTrainedTokenizerBase as the common interface, with TokenizersBackend, PythonBackend and SentencePieceBackend beneath it. The v5 changes consolidate on a single fast backend and make tokenizers easier to inspect, customize and train from scratch.

Written by swe.quest, not by the author.

**Difficulty:** Medium: assumes a working developer; shows how it is built or done

## Topics

- [LLMs](https://swe.quest/tags/llms.md) (AI & ML)
- [Python](https://swe.quest/tags/python.md) (Languages)
- [Open source](https://swe.quest/tags/open-source.md) (Engineering practices)

## Prerequisites

- Python ([easy posts on Python](https://swe.quest/tags/python.md?difficulty=easy))
- basic LLM concepts ([easy posts on LLMs](https://swe.quest/tags/llms.md?difficulty=easy))
- Hugging Face Transformers usage

## Keywords

Transformers v5, Hugging Face tokenizers, AutoTokenizer, BPE, SentencePiece, WordPiece, Unigram

## Related posts

- [tokenizers v1: encode, decode and scaling, measured](https://swe.quest/articles/tokenizers-v1-encode-decode-and-scaling-measured-49d0c7f94c7739e1.md): Hugging Face · 2026-09-21 · Medium · 10 min read · Performance engineering, Rust, LLMs, Algorithms
  tokenizers v1 encodes text 3 to 30 times faster than v0.23 single-threaded on an Apple M4 Max and scales at 76% of linear across eight cores, while producing identical token IDs and keeping the same API.
- [Train and Fine-Tune Sentence Transformers Models](https://swe.quest/articles/train-and-fine-tune-sentence-transformers-models-49bc0c36b2cdc22e.md): Hugging Face · 2022-08-10 · Medium · 11 min read · Model training, Machine learning, Python, Search
  Sentence Transformers models map text to fixed-size embeddings by running a pre-trained Transformer and pooling its token embeddings, and training them depends on matching the dataset format to the right loss.
- [Announcing pg\_tiktoken: A Postgres Extension for Fast BPE Tokenization](https://swe.quest/articles/announcing-pg-tiktoken-a-postgres-extension-for-fast-bpe-tokenization-f53006f2756f2730.md): Neon · 2023-03-14 · Medium · 5 min read · PostgreSQL, LLMs, SQL
  pg\_tiktoken is a Postgres extension on Neon that wraps OpenAI's tiktoken BPE tokenizer, exposing tiktoken\_encode (returns token IDs) and tiktoken\_count (returns token counts) for encodings such as cl100k\_base, p50k\_base, p50k\_edit and r50k\_base or their model names.
- [Native-speed vLLM transformers modeling backend](https://swe.quest/articles/native-speed-vllm-transformers-modeling-backend-cb3f698fe9046ce3.md): Hugging Face · 2026-07-08 · Hard · 5 min read · Inference & serving, LLMs, Performance engineering, Python
  The transformers modeling backend in vLLM now matches or beats vLLM's hand-written native implementations in throughput.
- [How Specializing the Vocabulary of SLMs Can Cut Inference Cost by 77% in Real Applications](https://swe.quest/articles/how-specializing-the-vocabulary-of-slms-can-cut-inference-cost-by-77-in-real-c0f4e920b37cfe6d.md): Hugging Face · 2026-10-21 · Hard · 11 min read · Inference & serving, LLMs, Cost optimization, Model training
  VocabX rebuilds a fine-tuned small model's tokenizer by choosing tokens for the cost they save rather than how often they appear.

Browse: [Latest posts](https://swe.quest/index.md) · [Topics](https://swe.quest/tags.md) · [Sources](https://swe.quest/sources.md) · [Topic map](https://swe.quest/map.md) · [Site guide (llms.txt)](https://swe.quest/llms.txt)
