> For the complete documentation index, see [llms.txt](https://blog.sunilgudivada.dev/notebook/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://blog.sunilgudivada.dev/notebook/transformers-and-llms/tokenization.md).

# Tokenization

Models understand numbers not text, we need to do something that makes the models to understand Natural language text&#x20;

Ex:  A Cute teddy bear is reading&#x20;

Unit of text is called token

**Arbitrary**: `A`, `cute`, `teddy bear`, `is`, `reading`, `.`&#x20;

**Word**:  `A`, `cute`, `teddy`, `bear` , `is`, `reading`, `.`&#x20;

**Sub word:** leveraging the roots of words,&#x20;

con -> make the sequence longer

&#x20;`A`, `cute`, `ted`,`##dy` ,`bear` , `is`, `read`,`##ing` ,`.`&#x20;

**Character level tokenizer:** each character is split into token

| Method          | Pros                                                                               | Cons                                                                            |
| --------------- | ---------------------------------------------------------------------------------- | ------------------------------------------------------------------------------- |
| Word Level      | <ul><li>Simple</li><li>Interpretable</li></ul>                                     | <ul><li>Risk of OOV</li><li>Does not leverage knowledge of root</li></ul>       |
| Sub word level  | <ul><li>Leverages common prefix and suffix</li><li>Learned from the data</li></ul> | <ul><li>Risk of OOV, though less than word-level</li></ul>                      |
| character level | <ul><li>Small change of OOV</li><li>RoBUsT tO CASinG anD misPeliNgS</li></ul>      | <ul><li>Makes computation slower</li><li>Embeddings not interpretable</li></ul> |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://blog.sunilgudivada.dev/notebook/transformers-and-llms/tokenization.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
