-
Notifications
You must be signed in to change notification settings - Fork 8
/
run_random_guess.py
53 lines (43 loc) · 1.43 KB
/
run_random_guess.py
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
from typing import Dict, Any
import os
import json
from tqdm import tqdm
from datetime import datetime
import openai
from time import sleep
import argparse
from util import extract_answer
parser = argparse.ArgumentParser()
parser.add_argument("--start", default=0, type=int)
parser.add_argument("--end", default=-1, type=int)
parser.add_argument("--answered", default=None, type=str)
parser.add_argument("--dry_run", default=False, action='store_true')
args = parser.parse_args()
def create_reader_request(example: Dict[str, Any]) -> str:
string = f'Question: {example["Question"]}\nLet\'s think step by step.'
return string
if __name__ == "__main__":
with open('theoremqa_test.json', 'r') as f:
test_set = json.load(f)
filename = f'outputs/random_guess.jsonl'
print(filename)
writer = open(filename, 'w')
inputs = []
for example in tqdm(test_set):
full_prompt = create_reader_request(example)
if example['Answer_type'] == 'bool':
prediction = 'True'
elif example['Answer_type'] == 'option':
prediction = '(a)'
else:
prediction = '1000'
tmp = {
'id': example['id'],
'question': example['Question'],
'prediction': prediction,
'answer': example['Answer'],
'answer_type': example['Answer_type'],
}
writer.write(json.dumps(tmp) + '\n')
writer.close()
print()