File size: 2,983 Bytes
a585ba3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from datetime import datetime, timedelta
import json
import math
def analyze_time_difference(ground_truth: str, to_assess: str) -> dict:
    def time_to_minutes(time_str: str) -> int:
        """Convert HH:MM to total minutes since midnight"""
        hours, minutes = map(int, time_str.split(':'))
        return hours * 60 + minutes
    
    def minutes_to_time(minutes: int) -> str:
        """Convert total minutes to HH:MM format"""
        hours = (minutes // 60) % 24
        mins = minutes % 60
        return f"{hours:02d}:{mins:02d}"
    
    def get_minute_difference(time1: str, time2: str) -> int:
        """Calculate absolute minute difference between two times"""
        minutes1 = time_to_minutes(time1)
        minutes2 = time_to_minutes(time2)
        
        # Handle cases crossing midnight
        diff = abs(minutes1 - minutes2)
        return min(diff, 1440 - diff)  # 1440 = 24*60
    
    # Calculate normal difference
    normal_diff = get_minute_difference(ground_truth, to_assess)
    
    # Switch hour and minute hands for to_assess
    hours, minutes = map(int, to_assess.split(':'))
    if minutes >= 12:  # Convert minute hand position to valid hour
        minutes = minutes % 12
    switched_time = f"{minutes:02d}:{hours:02d}"
    
    # Calculate difference with switched hands
    switched_diff = get_minute_difference(ground_truth, switched_time)
    
    return {
        "normal_diff_minutes": normal_diff,
        "switched_diff_minutes": switched_diff
    }





with open('molmo-answers-72b.json', 'r') as file:
    input_data = json.load(file)
    

with open('benchmark.json', 'r') as file:
    ground_truth = json.load(file)



in_5_mins = 0
in_4_mins = 0
in_3_mins = 0
in_2_mins = 0
in_1_min = 0
exact = 0

i = 0

while i < len(ground_truth):
    human_answer = ground_truth[i]['human_time']
    smallest = 10000000
    to_use = {'normal_diff_minutes': 10000000}
    for t in input_data[i]['reported_times']:
        assessment = analyze_time_difference(human_answer, t)
        to_use['normal_diff_minutes'] = min(to_use['normal_diff_minutes'], assessment['normal_diff_minutes'])

    assessment = to_use
    if assessment['normal_diff_minutes'] == 0:
        exact += 1
    if assessment['normal_diff_minutes'] <= 1:
        in_1_min += 1
    if assessment['normal_diff_minutes'] <= 2:
        in_2_mins += 1
    if assessment['normal_diff_minutes'] <= 3:
        in_3_mins += 1
    if assessment['normal_diff_minutes'] <= 4:
        in_4_mins += 1
    if assessment['normal_diff_minutes'] <= 5:
        in_5_mins += 1

    i += 1

print('Molmo 72b benchmark')
print('Within 5 mins ->', f'{in_5_mins/len(ground_truth):.2f}')
print('Within 4 mins ->', f'{in_4_mins/len(ground_truth):.2f}')
print('Within 3 mins ->', f'{in_3_mins/len(ground_truth):.2f}')
print('Within 2 mins ->', f'{in_2_mins/len(ground_truth):.2f}')
print('Within 1 min ->', f'{in_1_min/len(ground_truth):.2f}')
print('Exact ->', f'{exact/len(ground_truth):.2f}')