Joelito's picture
uploaded dataset files
7c48587
raw
history blame contribute delete
696 Bytes
import json
import os
import pandas as pd
import datasets
from typing import Union
def save_and_compress(dataset: Union[datasets.Dataset, pd.DataFrame], name: str, idx=None):
if idx:
path = f"{name}_{idx}.jsonl"
else:
path = f"{name}.jsonl"
print("Saving to", path)
dataset.to_json(path, force_ascii=False, orient='records', lines=True)
print("Compressing...")
os.system(f'xz -zkf -T0 {path}') # -TO to use multithreading
entries = []
# read json file into a python dictionary
with open('all_v1.json') as f:
data = json.load(f)
for _, obj in data.items():
entries.append(obj)
save_and_compress(pd.DataFrame(entries), "data/train")