HubCloneHubClone

Chapter 2 of 4 · 15 min

Tokenizers

Models do not read characters; they read token ids. A tokenizer splits text into pieces from a fixed vocabulary and maps each piece to an id.

Different tokenizers make different trade-offs between vocabulary size and sequence length, which affects both speed and quality.

Inspecting tokens

Try encoding a sentence and decoding each id back to text.

tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
print(tok.tokenize("HubClone hosts open models"))