score_answer.py
Tested 2026-11-30 · Python 3.15.2 · standard library only
# Score free-text answers against a RoadData.AI reward check: the sensors measured the impact, so the answer can be graded.
# usage: python score_answer.py records.json "Yes, it hits an SUV at about 5.5 s."
import json, re, sys
check = json.load(open(sys.argv[1]))["reward_check"]
measured = check["measured"]["impact_s"] # crash-pulse peak from the car's IMU
TOLERANCE_S = 0.5 # a collision time counts within half a second
for text in sys.argv[2:]:
said_no = re.search(r"\bno\b", text, re.I) and not re.search(r"\byes\b", text, re.I)
m = re.search(r"(\d+(?:\.\d+)?)\s*s\b", text)
score = 0 if said_no or not m else int(abs(float(m.group(1)) - measured) <= TOLERANCE_S)
print(f"{score} {text}")
print(f"measured impact {measured} s ({check['measured']['source']}), tolerance {TOLERANCE_S} s")python score_answer.py records.json "Yes, it hits an SUV at about 5.5 s." "Yes, around 8 s." "No, the car keeps its lane."
What it printed when we ran it
1 Yes, it hits an SUV at about 5.5 s.
0 Yes, around 8 s.
0 No, the car keeps its lane.
measured impact 5.6 s (IMU + GPS), tolerance 0.5 s