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

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-a-train-test-split-for-an-iterable-dataset%2F41831%3E%5C
**Category:** 🤗Datasets\
**Created:** [June 1, 2023, 11:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-a-train-test-split-for-an-iterable-dataset%2F41831 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fsurya-narayanan)%5C
**Post date:** [June 1, 2023, 11:42pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-a-train-test-split-for-an-iterable-dataset%2F41831%2F1 "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](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fmariosasko)%5C
**Post date:** [June 6, 2023, 6:45pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fhow-to-create-a-train-test-split-for-an-iterable-dataset%2F41831%2F2 "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.
