-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprepare_data1.py
More file actions
23 lines (19 loc) · 773 Bytes
/
prepare_data1.py
File metadata and controls
23 lines (19 loc) · 773 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os
import json
from datasets import load_dataset
from utilities.data_tools import *
# load data from FinGPT
dataset = load_dataset("FinGPT/fingpt-fineval")
# store the pre knowledgement before answer the question
pre_knowledgements = dataset["train"][:5]
print(pre_knowledgements)
# get current dir
current_dir = os.path.dirname(__file__)
#modify the dataset
modified_dataset = dataset.map(lambda batch: concatenate_pre_knowledgement(batch, pre_knowledgements), batched=True)
modified_train_data = modified_dataset['train']
with open(current_dir + '/data/' + 'modified_fineval_with_first_5_items.json', 'w') as file:
all_data = []
for line in modified_train_data:
all_data.append(line)
json.dump(all_data, file, indent=2, ensure_ascii=False)