-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdataset.py
More file actions
45 lines (32 loc) · 1.03 KB
/
dataset.py
File metadata and controls
45 lines (32 loc) · 1.03 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
import json
def filter_mcqs(verdicts, mcqs):
accepted = []
for verdict, mcq in zip(verdicts, mcqs):
if verdict["verdict"] == "YES":
accepted.append(mcq)
return accepted
def format_for_lora(chunk, mcq):
return {
"instruction": "Generate a multiple-choice question from the transcript.",
"input": chunk,
"output": json.dumps(mcq, ensure_ascii=False)
}
with open("chunks.json", "r") as f:
chunks = json.load(f)
with open("questions.json", "r") as f:
all_mcqs = json.load(f)
with open("verdicts.json", "r") as f:
all_verdicts = json.load(f)
all_data = []
counter = 1
for chunk in chunks:
mcqs = all_mcqs[5*(counter-1):5*counter]
verdicts = all_verdicts[5*(counter-1):5*counter]
accepted_mcqs = filter_mcqs(verdicts, mcqs)
for mcq in accepted_mcqs:
formatted = format_for_lora(chunk, mcq)
all_data.append(formatted)
counter += 1
with open("lora_dataset.jsonl", "w") as f:
for item in all_data:
f.write(json.dumps(item) + "\n")