56m commited on
Commit
06a6a65
·
verified ·
1 Parent(s): 7e40cd9

Create eval.py

Browse files

A Python file to confirm the answer

Files changed (1) hide show
  1. eval.py +52 -0
eval.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import pandas as pd
3
+ import re
4
+ import argparse
5
+
6
+ # The above library is required
7
+
8
+ def evaluate_numpuzzle(csv_path):
9
+ # Loading CSV (target: Ans, prediction: AI's Ans)
10
+ df = pd.read_csv(csv_path)
11
+
12
+ total = len(df)
13
+ correct = 0
14
+
15
+ print(f"--- NumPuzzle-Easy Evaluation Report ---")
16
+ print(f"Total Samples: {total}\n")
17
+
18
+ for index, row in df.iterrows():
19
+ target = str(row['target']).strip()
20
+ # Remove all except numbers (spaces, line breaks, characters) from the AI answer
21
+ prediction_raw = str(row['prediction'])
22
+ prediction_digits = re.sub(r'\D', '', prediction_raw)
23
+
24
+ #[Judgment logic]
25
+ # 1. Because the answer is often written at the end of the sentence, get the "last 9 digits" of the extracted number sequence
26
+ # 2. However, if the total is less than 9 digits, it will be treated as it is (8 digits or less)
27
+ final_pred = prediction_digits[-9:] if len(prediction_digits) >= 9 else prediction_digits
28
+
29
+ is_match = (final_pred == target)
30
+
31
+ if is_match:
32
+ correct += 1
33
+ else:
34
+ # 失敗例のログ(デバッグ用:最初の10件のみ表示)
35
+ if correct < 5:
36
+ print(f"Sample {index} Failed:")
37
+ print(f" Input Target: {target}")
38
+ print(f" AI Extracted: {final_pred} (Raw: '{prediction_raw[:50]}...')")
39
+ print(f" Reason: {'Leading zero lost or calculation error' if len(final_pred) < 9 else 'Value mismatch'}")
40
+ print("-" * 30)
41
+
42
+ accuracy = (correct / total) * 100
43
+ print(f"\nFinal Results:")
44
+ print(f"✅ Accuracy: {accuracy:.4f}%")
45
+ print(f"✅ Correct: {correct} / {total}")
46
+ print(f"----------------------------------------")
47
+
48
+ if __name__ == "__main__":
49
+ parser = argparse.ArgumentParser()
50
+ parser.add_argument("--csv", type=str, required=True, help="Path to the prediction CSV file")
51
+ args = parser.parse_args()
52
+ evaluate_numpuzzle(args.csv)