# Load pre-existing in-memory splits into a Dataset

**URL:** </static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-pre-existing-in-memory-splits-into-a-dataset%2F11743%3E%5C
**Category:** 🤗Datasets\
**Created:** [November 15, 2021, 2:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-pre-existing-in-memory-splits-into-a-dataset%2F11743 "2021-11-15T14:12:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bercher](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@bercher](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbercher)%5C
**Post date:** [November 15, 2021, 2:12pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-pre-existing-in-memory-splits-into-a-dataset%2F11743%2F1 "2021-11-15T14:12:38Z")

</div>

Hello,

For some experiments I have made, I have already divided my local private data into “train”, “test”, and “valid” and saved them into a single .json file with the following stucture:  
{  
“train”: [  
{  
“text”: “this is the first example”  
“label”: 2  
},  
{  
“text”: “this is the second example”  
“label”: 1  
},  
],  
“test”: …  
“valid”: …  
}

but I struggle to create a Dataset out of it. In this tutorial (in memory section):

[https://huggingface.co/docs/datasets/loading\_datasets.html#from-a-python-dictionary](https://huggingface.co/docs/datasets/loading_datasets.html#from-a-python-dictionary)

It isn’t clear how to proceed. I looked at the source code of arrow\_dataset.py for this method from\_dict, but I didn’t manage to find out the solution to my problem.

Does anyone have an idea (except splitting the original file into several files and reformating them)?

---

<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:** [November 15, 2021, 4:03pm UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-pre-existing-in-memory-splits-into-a-dataset%2F11743%2F2 "2021-11-15T16:03:11Z")

</div>

Hi,

this is possible but not nearly as clean as the approach which involves converting data to JSON Lines and splitting it to have one file per split:

```python
import datasets
ddict = datasets.DatasetDict()
for split in ["train", "test", "valid"]:
   ddict.update(datasets.load_dataset("json", data_files={split: "path/to/data/file.json"}, field=split)

```

---

<div class="post-metadata">

**Author:** ![bercher](https://avatars.discourse-cdn.com/v4/letter/b/258eb7/32.png) [@bercher](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Fu%2Fbercher)%5C
**Post date:** [November 16, 2021, 9:30am UTC](/static-proxy?url=https%3A%2F%2Fdiscuss.huggingface.co%2Ft%2Fload-pre-existing-in-memory-splits-into-a-dataset%2F11743%2F3 "2021-11-16T09:30:29Z")

</div>

Thank you very much!
