-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDataset.py
More file actions
60 lines (47 loc) · 1.66 KB
/
Dataset.py
File metadata and controls
60 lines (47 loc) · 1.66 KB
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from datasets import load_dataset
import os
import json
from record import base_path
def read_dataset(name, split):
if name == "ScienceQA":
data = load_dataset("derek-thomas/ScienceQA", split = split)
elif name == "mm-vet":
meta_data = os.path.join(base_path, "dataset/mm-vet/mm-vet.json")
with open(meta_data, "r") as f:
data = json.load(f)
return data
def create_options(options):
if options != None:
letters = ["(A) ", "(B) ", "(C) ", "(D) ", "(E) ", "(F) ", "(G) "]
strs = "Options:\n"
for i in range(len(options)):
strs += letters[i]
strs += options[i]
strs += "\n"
strs += "\n"
else:
strs = ""
return strs
def create_lecture(lecture = None):
strs = ""
if lecture != None:
strs = "Lecture:\n" + lecture + "\n\n"
return strs
def create_context(context = None):
strs = ""
if context != None and context != "":
strs = "Context:\n" + context + "\n\n"
return strs
def create_prompt(question, options = None, context = None, lecture = None, if_options = True, post = True):
prompt = "Question:\n" + question + "\n\n"
if if_options and options != None:
prompt += create_context(context)
prompt += create_options(options)
prompt += create_lecture(lecture)
postfix = '''Only one option is correct. Please choose the right option and explain why you choose it. You must answer in the following format. For example, if the right answer is A, you should answer:
The answer is A.
Because ...
'''
if post:
prompt += postfix
return prompt