Submissions / #2 / scripts/para_recall.py
scripts/para_recall.py
Preview
"""Recall of the paraphrase detector on known LLM rephrasings: MetaMathQA GSM_Rephrased
(query) vs its stated original_question (a GSM8K train item). Usage: python para_recall.py <MetaMathQA-395K.json>"""
import json, os, sys
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from para import feats, THRESH
out = {}
for typ in ("GSM_Rephrased", "GSM_AnsAug"):
el = numeq = hit = 0; js = []
for r in json.load(open(sys.argv[1])):
if r["type"] != typ: continue
n1, w1 = feats(r["original_question"]); n2, w2 = feats(r["query"])
if len(n1) < 3: continue
el += 1
if n1 == n2:
numeq += 1; j = len(w1 & w2) / max(1, len(w1 | w2)); js.append(j); hit += j >= THRESH
js.sort()
out[typ] = {"eligible_pairs": el, "numbers_equal": numeq, "recall": round(hit / el, 4),
"median_jaccard_when_numbers_equal": round(js[len(js) // 2], 3)}
print(json.dumps(out))