DISC-Assignment / Experiment /TriviaQA /TriviaQA_test_format.py
KashiwaByte's picture
initial commit
7c93e9d
import json
import csv
csvin = 'C:/Users/94427/kashiwa/DISC-Assignment/Experiment/TriviaQA/val_triviaqa.csv'
import csv
# 打开CSV文件
with open(csvin, newline='',encoding='utf-8') as csvfile:
reader = csv.DictReader(csvfile)
files = 'C:/Users/94427/kashiwa/DISC-Assignment/Experiment/TriviaQA/TriviaQA_test_format1k.jsonl'
with open(files, 'w', newline='',encoding='utf-8') as outfile:
messages = []
# 逐行读取CSV文件
for index,row in enumerate(reader):
if index<=1000:
context = row['context']
question = row['question']
answers = row['answers']
message = {
"Data":
{
"Answer":answers,
"Question":question,
"Context":context,
},
}
messages.append(message)
for message in messages:
outfile.write(json.dumps(message, ensure_ascii=False) + '\n')