|
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}') |
|
|
|
|
|
entries = [] |
|
|
|
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") |
|
|