# 2 tokens for one character in T5

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F2-tokens-for-one-character-in-t5%2F14960%3E%5C
**Category:** 🤗Tokenizers\
**Created:** [February 21, 2022, 8:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F2-tokens-for-one-character-in-t5%2F14960 "2022-02-21T08:14:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![borgr](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/borgr/32/24353_2.png) [@borgr](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fborgr)%5C
**Post date:** [February 21, 2022, 8:14am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F2-tokens-for-one-character-in-t5%2F14960%2F1 "2022-02-21T08:14:47Z")

</div>

When tokenizing text, T5(small?) tokenizer adds an eos\_token, that’s expected.

A bit weird is that for the character\string\sentence “0”, it tokenizes it to three tokens! One of them is a token that is detokenized to an empty string.

Is that an error on my part? Is it a bug? How does that happen? T5 is char based, right, so at the bare minimum, each character should be in the dictionary.

```auto
tokenizer_name = "t5-small"
tokenizer = AutoTokenizer.from_pretrained(tokenizer_name, use_fast=True)
print(tokenizer.encode("0")) # [3, 632, 1]
print(tokenizer.encode("1"))
print(tokenizer.encode("2"))
print(tokenizer.encode("3"))

```

Outputs:  
[3, 632, 1]  
[209, 1]  
[204, 1]  
[220, 1]

---

<div class="post-metadata">

**Author:** ![hyesunyun](https://avatars.discourse-cdn.com/v4/letter/h/85f322/32.png) [@hyesunyun](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fhyesunyun)%5C
**Post date:** [August 10, 2023, 3:10pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F2-tokens-for-one-character-in-t5%2F14960%2F2 "2023-08-10T15:10:03Z")

</div>

I have the same exact question. I can just call something like `tokenizer.encode("0", add_special_tokens = False)` to get rid of the special tokens such as eos\_token. However, I am puzzled by the empty string tokens that you are seeing as well.

---

<div class="post-metadata">

**Author:** ![dblakely](https://avatars.discourse-cdn.com/v4/letter/d/54ee81/32.png) [@dblakely](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fdblakely)%5C
**Post date:** [August 10, 2023, 5:25pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2F2-tokens-for-one-character-in-t5%2F14960%2F3 "2023-08-10T17:25:25Z")

</div>

The extra token is a SentencePiece underline token, which is a space token to indicate that the proceeding token is either the start of a word or a standalone token. You can check what the actual tokens are like this:

```python
ids = tokenizer.encode("0")
tokens = tokenizer.convert_ids_to_tokens(ids)
print(tokens)

```

Which shows:

```auto
['▁', '0', '</s>']

```

The `'▁'` is the 3 token you’re seeing. When you look at the tokens themselves or the token ids, you can see what’s going on, though when you decode or print, they’re omitted.

In fact, when you use the T5 tokenizer, all words start with a space like this, just most of them have the space built into the token itself. For example, the token for “1” is actually this: `'▁1'` (it’s just one token, but contains a space and the character for the 1).

Meanwhile, for words that contain multiple tokens, the first one in the word will have the space while the others won’t. For example:

```auto
ids = tokenizer.encode("Onomatopoeia")
tokens = tokenizer.convert_ids_to_tokens(ids)
print(tokens)

```

You get:

```auto
['▁On', 'omato', 'p', 'o', 'e', 'i', 'a', '</s>']

```

Why the tokenizer adds a separate space token in front of “0”, but has it merged into the token for 1, is probably just a statistical quirk of how the SentencePiece algorithm worked when it was run on the corpus the Google people used to create the T5Tokenizer. There’s no real a priori reason.
