-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathverifier.py
36 lines (31 loc) · 1.59 KB
/
verifier.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
import torch
import torch.nn.functional as F
def logprobs_from_logits(logits, labels):
"""
See: https://github.com/pytorch/pytorch/issues/563#issuecomment-330103591
"""
logp = F.log_softmax(logits, dim=2)
logpy = torch.gather(logp, 2, labels.unsqueeze(2)).squeeze(-1)
return logpy
def tracking_shuffled_objects_three_objects(prefix, response, target):
prompt = ""
neg_prompt = ""
correct = 0
final_answer_context = response
if response.replace(" ", "").replace(".", "").lower() == str(
target
).lower().replace("\n", " ").replace(" ", "").replace(".", ""):
# if str(target).lower().replace('\n', ' ').replace(' ', '').replace('.', '') in response.replace(' ', '').replace('.', '').lower() and len(response.replace(' ', '').replace('.', '').lower()) - len(str(target).lower().replace('\n', ' ').replace(' ', '').replace('.', '')) < 4:
prompt = prompt + " Solve question with correct answer."
neg_prompt = neg_prompt + " Solve the question with wrong answer."
correct = 1
else:
if "Bob" in response or "Alice" in response or "Claire" in response:
# prompt = prompt + " Solve the question with only people names."
prompt = prompt + " Solve the question with wrong answer."
neg_prompt = neg_prompt + " Solve the question with correct answer."
else:
prompt = prompt + " Solve the question with wrong answer."
neg_prompt = neg_prompt + " Solve the question with correct answer."
# print(response, target, correct)
return prompt, neg_prompt, correct