File size: 888 Bytes
dacf049
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
from datasets import DatasetDict, load_dataset
import csv
import json

def main():
    for split in ["train", "val", "test"]:
        input_file = csv.DictReader(open(f"{split}_df.csv"))

        with open(f'{split}.jsonl', 'w') as fout:
            for row in input_file:
                fout.write(json.dumps({'id': row['id'], 'text': row['text'], 'label': row['label'], 'sentiment': row['sentiment']})+"\n")
               

    """
    train_dset = load_dataset("csv", data_files="train_df.csv", split="train")
    val_dset = load_dataset("csv", data_files="val_df.csv", split="val")
    test_dset = load_dataset("csv", data_files="test_df.csv", split="test")
    raw_dset = DatasetDict()
    raw_dset["train"] = train_dset
    raw_dset["test"] = test_dset
    for split, dset in raw_dset.items():
        dset.to_json(f"{split}.jsonl")
    """

if __name__ == "__main__":
    main()