add assess.py, pass the json from run.py here
Browse files
assess.py
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from datetime import datetime, timedelta
|
| 2 |
+
import json
|
| 3 |
+
import math
|
| 4 |
+
def analyze_time_difference(ground_truth: str, to_assess: str) -> dict:
|
| 5 |
+
def time_to_minutes(time_str: str) -> int:
|
| 6 |
+
"""Convert HH:MM to total minutes since midnight"""
|
| 7 |
+
hours, minutes = map(int, time_str.split(':'))
|
| 8 |
+
return hours * 60 + minutes
|
| 9 |
+
|
| 10 |
+
def minutes_to_time(minutes: int) -> str:
|
| 11 |
+
"""Convert total minutes to HH:MM format"""
|
| 12 |
+
hours = (minutes // 60) % 24
|
| 13 |
+
mins = minutes % 60
|
| 14 |
+
return f"{hours:02d}:{mins:02d}"
|
| 15 |
+
|
| 16 |
+
def get_minute_difference(time1: str, time2: str) -> int:
|
| 17 |
+
"""Calculate absolute minute difference between two times"""
|
| 18 |
+
minutes1 = time_to_minutes(time1)
|
| 19 |
+
minutes2 = time_to_minutes(time2)
|
| 20 |
+
|
| 21 |
+
# Handle cases crossing midnight
|
| 22 |
+
diff = abs(minutes1 - minutes2)
|
| 23 |
+
return min(diff, 1440 - diff) # 1440 = 24*60
|
| 24 |
+
|
| 25 |
+
# Calculate normal difference
|
| 26 |
+
normal_diff = get_minute_difference(ground_truth, to_assess)
|
| 27 |
+
|
| 28 |
+
# Switch hour and minute hands for to_assess
|
| 29 |
+
hours, minutes = map(int, to_assess.split(':'))
|
| 30 |
+
if minutes >= 12: # Convert minute hand position to valid hour
|
| 31 |
+
minutes = minutes % 12
|
| 32 |
+
switched_time = f"{minutes:02d}:{hours:02d}"
|
| 33 |
+
|
| 34 |
+
# Calculate difference with switched hands
|
| 35 |
+
switched_diff = get_minute_difference(ground_truth, switched_time)
|
| 36 |
+
|
| 37 |
+
return {
|
| 38 |
+
"normal_diff_minutes": normal_diff,
|
| 39 |
+
"switched_diff_minutes": switched_diff
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
with open('molmo-answers-72b.json', 'r') as file:
|
| 47 |
+
input_data = json.load(file)
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
with open('benchmark.json', 'r') as file:
|
| 51 |
+
ground_truth = json.load(file)
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
in_5_mins = 0
|
| 56 |
+
in_4_mins = 0
|
| 57 |
+
in_3_mins = 0
|
| 58 |
+
in_2_mins = 0
|
| 59 |
+
in_1_min = 0
|
| 60 |
+
exact = 0
|
| 61 |
+
|
| 62 |
+
i = 0
|
| 63 |
+
|
| 64 |
+
while i < len(ground_truth):
|
| 65 |
+
human_answer = ground_truth[i]['human_time']
|
| 66 |
+
smallest = 10000000
|
| 67 |
+
to_use = {'normal_diff_minutes': 10000000}
|
| 68 |
+
for t in input_data[i]['reported_times']:
|
| 69 |
+
assessment = analyze_time_difference(human_answer, t)
|
| 70 |
+
to_use['normal_diff_minutes'] = min(to_use['normal_diff_minutes'], assessment['normal_diff_minutes'])
|
| 71 |
+
|
| 72 |
+
assessment = to_use
|
| 73 |
+
if assessment['normal_diff_minutes'] == 0:
|
| 74 |
+
exact += 1
|
| 75 |
+
if assessment['normal_diff_minutes'] <= 1:
|
| 76 |
+
in_1_min += 1
|
| 77 |
+
if assessment['normal_diff_minutes'] <= 2:
|
| 78 |
+
in_2_mins += 1
|
| 79 |
+
if assessment['normal_diff_minutes'] <= 3:
|
| 80 |
+
in_3_mins += 1
|
| 81 |
+
if assessment['normal_diff_minutes'] <= 4:
|
| 82 |
+
in_4_mins += 1
|
| 83 |
+
if assessment['normal_diff_minutes'] <= 5:
|
| 84 |
+
in_5_mins += 1
|
| 85 |
+
|
| 86 |
+
i += 1
|
| 87 |
+
|
| 88 |
+
print('Molmo 72b benchmark')
|
| 89 |
+
print('Within 5 mins ->', f'{in_5_mins/len(ground_truth):.2f}')
|
| 90 |
+
print('Within 4 mins ->', f'{in_4_mins/len(ground_truth):.2f}')
|
| 91 |
+
print('Within 3 mins ->', f'{in_3_mins/len(ground_truth):.2f}')
|
| 92 |
+
print('Within 2 mins ->', f'{in_2_mins/len(ground_truth):.2f}')
|
| 93 |
+
print('Within 1 min ->', f'{in_1_min/len(ground_truth):.2f}')
|
| 94 |
+
print('Exact ->', f'{exact/len(ground_truth):.2f}')
|