MCPcopy Create free account
hub / github.com/FastMAS/KVCOMM / clean_answer

Function clean_answer

KVCOMM/utils/utils.py:26–54  ·  view source on GitHub ↗
(model_pred)

Source from the content-addressed store, hash-verified

24 return model_answer == gt_answer
25
26def clean_answer(model_pred):
27 model_pred = model_pred.lower()
28 preds = model_pred.split(ANSWER_TRIGGER.lower())
29 answer_flag = True if len(preds) > 1 else False
30 if answer_flag:
31
32 pred = preds[1]
33 else:
34
35 pred = preds[-1]
36
37 pred = pred.replace(",", "")
38 pred = [s for s in re.findall(r"-?\d+\.?\d*", pred)]
39
40 if len(pred) == 0:
41 return INVALID_ANS
42
43 if answer_flag:
44
45 pred = pred[0]
46 else:
47
48 pred = pred[-1]
49
50
51 if pred[-1] == ".":
52 pred = pred[:-1]
53
54 return pred
55
56def nuclear_norm(matrix):
57 _, S, _ = torch.svd(matrix)

Callers

nothing calls this directly

Calls 1

splitMethod · 0.80

Tested by

no test coverage detected