Datasets:
create dataset file added
Browse files- create_dataset.py +26 -0
create_dataset.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datasets import DatasetDict, load_dataset
|
2 |
+
import csv
|
3 |
+
import json
|
4 |
+
|
5 |
+
def main():
|
6 |
+
for split in ["train", "val", "test"]:
|
7 |
+
input_file = csv.DictReader(open(f"{split}_df.csv"))
|
8 |
+
|
9 |
+
with open(f'{split}.jsonl', 'w') as fout:
|
10 |
+
for row in input_file:
|
11 |
+
fout.write(json.dumps({'id': row['id'], 'text': row['text'], 'label': row['label'], 'sentiment': row['sentiment']})+"\n")
|
12 |
+
|
13 |
+
|
14 |
+
"""
|
15 |
+
train_dset = load_dataset("csv", data_files="train_df.csv", split="train")
|
16 |
+
val_dset = load_dataset("csv", data_files="val_df.csv", split="val")
|
17 |
+
test_dset = load_dataset("csv", data_files="test_df.csv", split="test")
|
18 |
+
raw_dset = DatasetDict()
|
19 |
+
raw_dset["train"] = train_dset
|
20 |
+
raw_dset["test"] = test_dset
|
21 |
+
for split, dset in raw_dset.items():
|
22 |
+
dset.to_json(f"{split}.jsonl")
|
23 |
+
"""
|
24 |
+
|
25 |
+
if __name__ == "__main__":
|
26 |
+
main()
|