# Unable to use custom dataset when training a tokenizer

**URL:** <https://discuss.huggingface.co/t/unable-to-use-custom-dataset-when-training-a-tokenizer/9120>\
**Category:** Beginners\
**Created:** [August 10, 2021, 10:31am UTC](https://discuss.huggingface.co/t/unable-to-use-custom-dataset-when-training-a-tokenizer/9120 "2021-08-10T10:31:26Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon58275033](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon58275033](https://discuss.huggingface.co/u/anon58275033)\
**Post date:** [August 10, 2021, 10:31am UTC](https://discuss.huggingface.co/t/unable-to-use-custom-dataset-when-training-a-tokenizer/9120/1 "2021-08-10T10:31:26Z")

</div>

Hello,

I am following this tutorial here: [notebooks/tokenizer\_training.ipynb at master · huggingface/notebooks · GitHub](https://github.com/huggingface/notebooks/blob/master/examples/tokenizer_training.ipynb)

So, using this code, I add my custom dataset:

```auto
from datasets import load_dataset
dataset = load_dataset('csv', data_files=['/content/drive/MyDrive/mydata.csv'])

```

Then, I use this code to take a look at the dataset:

```auto
dataset

```

Access an element:

```auto
dataset['train'][1]

```

Access a slice directory:

```auto
dataset['train'][:5]

```

**After executing the above code successfully, I try to execute this here:**

```auto
new_tokenizer = tokenizer.train_new_from_iterator(batch_iterator(), vocab_size=25000)

```

**However, I get this error:**

```auto
KeyError: "Invalid key: slice(0, 1000, None). Please first select a split. For example: `my_dataset_dictionary['train'][slice(0, 1000, None)]`. Available splits: ['train']"

```

How do I fix this?

I am trying to train my own tokenizer, and this seems to be an issue.

Any help would be appreciated!

---

<div class="post-metadata">

**Author:** ![sgugger](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/sgugger/32/2291_2.png) [@sgugger](https://discuss.huggingface.co/u/sgugger)\
**Post date:** [August 10, 2021, 3:50pm UTC](https://discuss.huggingface.co/t/unable-to-use-custom-dataset-when-training-a-tokenizer/9120/2 "2021-08-10T15:50:25Z")

</div>

When asking for help on the forum, please paste all relevant code. In this case, you did not past the definition of `batch_iterator`.

If you are following the notebook, you did not load one dataset, but several (with a split for train/validation/test) which is why you get this error. You should add the `split="train"` argument when you load your dataset, or adapt the code of `batch_iterator` to index in your dataset dictionary.

---

<div class="post-metadata">

**Author:** ![anon58275033](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@anon58275033](https://discuss.huggingface.co/u/anon58275033)\
**Post date:** [August 11, 2021, 5:00pm UTC](https://discuss.huggingface.co/t/unable-to-use-custom-dataset-when-training-a-tokenizer/9120/3 "2021-08-11T17:00:50Z")

</div>

Okay, thanks for that. I have trained my own tokenizer from scratch, so how do I use it in the masked language task?
