# How to train target tokenizer

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-target-tokenizer%2F22291%3E%5C
**Category:** 🤗Tokenizers\
**Created:** [August 30, 2022, 2:48am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-target-tokenizer%2F22291 "2022-08-30T02:48:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nubol23](https://avatars.discourse-cdn.com/v4/letter/n/90db22/32.png) [@nubol23](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fnubol23)%5C
**Post date:** [August 30, 2022, 2:48am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-train-target-tokenizer%2F22291%2F1 "2022-08-30T02:48:51Z")

</div>

I’m trying to retrain `t5-small` with a japanese to spanish dataset, I want to retrain the tokenizer to handle the words in those languages

Currently I’ve done this:

```python
def get_training_corpus(lang: str):
    ds = dataset["train"]
    for start_idx in range(0, len(ds), 1000):
        samples = ds[start_idx : start_idx + 1000]
        yield samples[lang]

tokenizer = AutoTokenizer.from_pretrained("t5-small")
new_tokenizer = tokenizer.train_new_from_iterator(
    get_training_corpus("ja"), 
    52000,
)

```

but I don’t know how to also train the target side of the tokenizer, I would like to be able to tokenize in japanese like

```python
model_inputs = tokenizer(examples["ja"], max_length=max_input_length, truncation=True)

```

and in spanish using

```python
with tokenizer.as_target_tokenizer():
        labels = tokenizer(examples["es"], max_length=max_target_length, truncation=True)

```
