# How to create a train test split for an iterable dataset

**URL:** <https://discuss.huggingface.co/t/how-to-create-a-train-test-split-for-an-iterable-dataset/41831>\
**Category:** 🤗Datasets\
**Created:** [June 1, 2023, 11:42pm UTC](https://discuss.huggingface.co/t/how-to-create-a-train-test-split-for-an-iterable-dataset/41831 "2023-06-01T23:42:08Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![surya-narayanan](https://avatars.discourse-cdn.com/v4/letter/s/d2c977/32.png) [@surya-narayanan](https://discuss.huggingface.co/u/surya-narayanan)\
**Post date:** [June 1, 2023, 11:42pm UTC](https://discuss.huggingface.co/t/how-to-create-a-train-test-split-for-an-iterable-dataset/41831/1 "2023-06-01T23:42:08Z")

</div>

Just curious- how do I create a train test split from a dataset that doesn’t have a length function? I don’t want to download & tokenize the whole dataset before I split it into training and testing.

---

<div class="post-metadata">

**Author:** ![mariosasko](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/mariosasko/32/31548_2.png) [@mariosasko](https://discuss.huggingface.co/u/mariosasko)\
**Post date:** [June 6, 2023, 6:45pm UTC](https://discuss.huggingface.co/t/how-to-create-a-train-test-split-for-an-iterable-dataset/41831/2 "2023-06-06T18:45:37Z")

</div>

Hi! I think the only option is to sample the input dataset while iterating over it (e.g., in the training loop) to generate the test split.
