-
Notifications
You must be signed in to change notification settings - Fork 5
/
baseline.py
24 lines (20 loc) · 934 Bytes
/
baseline.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
import pickle as pkl
import torch
from model import T5ZeroShotClfQA
import os
import sys
from path_utils import get_name_from_path_name, testing_dicts_dir
device = 'cuda' if torch.cuda.is_available() else 'cpu'
size = sys.argv[1]
if __name__ == '__main__':
model_name = "allenai/unifiedqa-t5-{size}".format(size=size)
m = T5ZeroShotClfQA(model_name).to(device)
eval_dataset_paths = [os.path.join(testing_dicts_dir, p) for p in os.listdir(testing_dicts_dir)]
for eval_dataset_path in eval_dataset_paths:
name = get_name_from_path_name(eval_dataset_path)
label_q2input_answer = pkl.load(open(eval_dataset_path, 'rb'))
label_q2preds = {}
for (label, q), input_answer in label_q2input_answer.items():
all_preds = m.get_logits_from_qc(input_answer)
label_q2preds[(label, q)] = all_preds
pkl.dump(label_q2preds, open('results/' + name + model_name, 'wb'))