# Loading Dataset

**URL:** <https://discuss.huggingface.co/t/loading-dataset/73338>\
**Category:** 🤗Datasets\
**Created:** [February 15, 2024, 3:02pm UTC](https://discuss.huggingface.co/t/loading-dataset/73338 "2024-02-15T15:02:21Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Pekka10](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/pekka10/32/23889_2.png) [@Pekka10](https://discuss.huggingface.co/u/Pekka10)\
**Post date:** [February 15, 2024, 3:02pm UTC](https://discuss.huggingface.co/t/loading-dataset/73338/1 "2024-02-15T15:02:21Z")

</div>

Can anyone help me how to split the dataset into training and test like the way it was defined earlier-:

**# load dataset**  
**train\_dataset, test\_dataset = load\_dataset(dataset\_name, split=[‘train’, ‘test’])**

This is not working and i am using **b-mc2/sql-create-context** dataset and need to split it into train and test.

---

<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:** [February 15, 2024, 5:06pm UTC](https://discuss.huggingface.co/t/loading-dataset/73338/2 "2024-02-15T17:06:20Z")

</div>

Hi! `b-mc2/sql-create-context` has a single `train` split (built from a single JSON file), so you need to use `Dataset.train_test_split` to achieve that:

```python
train_dataset = load_dataset("b-mc2/sql-create-context ", split="train")
train_test_dataset = train_dataset.train_test_split(test_size=0.2)
train_dataset, test_dataset = train_test_dataset["train"], train_test_dataset["test"]

```
