Hugging Face, End to EndLesson 12 of 75

Module 2 · Transformers, from characters to output

Your text is integers, and the count is not the word count

In this lesson

  • 10 min read
  • 6 reading sections
  • Knowledge check
  • Lesson 3 of 9 in this chapter

This chapter’s goalTrace a piece of text from characters through a tokenizer to logits and back to text with the transformers library, and say which of the Auto class, the tokenizer, the padding side, the chat template or the generation config is at fault when a model loads without error and produces nonsense.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableWatch4:51
Full audiobookNot availableNot available
One question, two tokenizersGPT-2, English5GPT-2, Hindi30XLM-R, English5XLM-R, Hindi6tokens per questionThe exact English and Hindi parcel questions give different counts under these pinned vocabularies.Special tokens are excluded. A different sentence could give a different ratio.
The exact English and Hindi parcel questions give different counts under these pinned vocabularies. Special tokens are excluded. A different sentence could give a different ratio.

Figure

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 8Free · no account needed
Lesson steps

Count tokens before drawing a conclusion

A tokenizer uses a vocabulary and splitting rules to turn text into integer IDs. One word can be one token or several. Spaces and punctuation can change the split, and another tokenizer can assign a different count or ID to the same text.

Compare the two versions of one parcel question, in English and Hindi. Use the GPT-2 tokenizer and the XLM-R tokenizer, which comes from a multilingual model trained on text in 100 languages.

In a Python environment with tokenizers==0.22.2 and huggingface-hub==1.33.0, run the example below. It downloads only the two revision-pinned tokenizer files, about 10.5 MB in total. No account, model weights or inference are needed.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Image Generation, in Practice exam.

Stuck on something?Ask Arjun, your AI tutor

How to cite: Addaly (2026) ‘Your text is integers, and the count is not the word count’, in Hugging Face, End to End. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/hugging-face/tokenizers-in-practice (Accessed: 29 November 2026).