-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathevaluate_mmlu.py
More file actions
408 lines (336 loc) · 19.4 KB
/
evaluate_mmlu.py
File metadata and controls
408 lines (336 loc) · 19.4 KB
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env python3
"""
REAL MMLU Evaluation with Full Dataset
====================================
Evaluates on the actual MMLU benchmark using real models and full dataset.
NO MORE HARDCODED SAMPLES OR FAKE 100% ACCURACY!
Author: Principal Neuro-AI Engineer
Date: January 8, 2026
"""
import sys
import time
import json
import argparse
from pathlib import Path
from typing import Dict, List, Any
import logging
# Import real evaluation components
from real_dataset_loader import RealDatasetLoader, install_datasets_if_needed
from real_model_inference import RealSpecialistSystem, install_required_packages
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
def run_real_mmlu_evaluation(max_samples: int = None, use_real_models: bool = True,
subjects_filter: List[str] = None):
"""Run REAL MMLU evaluation on full dataset with real models"""
print("[TARGET] REAL MMLU Evaluation - Full Dataset")
print("=" * 60)
print(f"[CHART] Max samples: {max_samples or 'ALL'}")
print(f"? Real models: {'YES' if use_real_models else 'NO (simulation)'}")
print(f"[DATA] Subject filter: {subjects_filter or 'ALL SUBJECTS'}")
# Check and install dependencies
if use_real_models:
try:
from transformers import AutoTokenizer
except ImportError:
print("? Installing model dependencies...")
if not install_required_packages():
print("[FAIL] Failed to install model dependencies")
return None
if not install_datasets_if_needed():
print("[FAIL] Failed to install dataset dependencies")
return None
# Load real datasets
print("\n[CYCLE] Loading REAL MMLU dataset...")
loader = RealDatasetLoader()
try:
mmlu_samples = loader.load_mmlu_full(max_samples=max_samples)
if not mmlu_samples:
print("[FAIL] No MMLU samples loaded")
return None
print(f"[OK] Loaded {len(mmlu_samples)} REAL MMLU samples")
# Filter by subjects if specified
if subjects_filter:
original_count = len(mmlu_samples)
mmlu_samples = [s for s in mmlu_samples if s['subject'] in subjects_filter]
print(f"[SEARCH] Filtered to {len(mmlu_samples)} samples from {original_count}")
except Exception as e:
logger.error(f"Failed to load MMLU dataset: {e}")
print(f"[FAIL] Failed to load dataset: {e}")
return None
# Initialize real specialist system
print(f"\n? Initializing {'REAL' if use_real_models else 'SIMULATION'} specialist system...")
specialist_system = RealSpecialistSystem(use_real_models=use_real_models)
# Run evaluation
print(f"\n[ROCKET] Starting evaluation on {len(mmlu_samples)} questions...")
results = []
subject_performance = {}
specialist_usage = {}
start_time = time.time()
for i, sample in enumerate(mmlu_samples):
print(f"\r? Processing {i+1}/{len(mmlu_samples)} ({sample['subject']})...", end='', flush=True)
try:
result = specialist_system.evaluate_question(
question=sample['question'],
choices=sample['choices'],
correct_answer=sample['answer'],
subject=sample['subject']
)
results.append(result)
# Track performance by subject
subject = sample['subject']
if subject not in subject_performance:
subject_performance[subject] = {'correct': 0, 'total': 0, 'confidence_sum': 0}
subject_performance[subject]['total'] += 1
subject_performance[subject]['confidence_sum'] += result['confidence']
if result['is_correct']:
subject_performance[subject]['correct'] += 1
# Track specialist usage
specialist = result['selected_specialist']
if specialist not in specialist_usage:
specialist_usage[specialist] = 0
specialist_usage[specialist] += 1
except Exception as e:
logger.error(f"Error processing sample {i}: {e}")
continue
print() # New line after progress
# Calculate overall metrics
total_time = time.time() - start_time
total_correct = sum(1 for r in results if r['is_correct'])
total_questions = len(results)
if total_questions == 0:
print("[FAIL] No questions processed successfully")
return None
overall_accuracy = total_correct / total_questions
avg_confidence = sum(r['confidence'] for r in results) / len(results)
avg_processing_time = sum(r['processing_time_ms'] for r in results) / len(results)
# Display results
print(f"\n? REAL MMLU Results Summary")
print("=" * 60)
print(f" Overall Accuracy: {overall_accuracy:.1%} ({total_correct}/{total_questions})")
print(f" Average Confidence: {avg_confidence:.3f}")
print(f" Average Processing Time: {avg_processing_time:.1f}ms")
print(f" Total Runtime: {total_time:.1f}s")
print(f" Model Mode: {'REAL MODELS' if use_real_models else 'SIMULATION'}")
print(f"\n[STATS] Subject Performance:")
for subject, perf in sorted(subject_performance.items()):
accuracy = perf['correct'] / perf['total']
avg_conf = perf['confidence_sum'] / perf['total']
print(f" {subject:20s}: {accuracy:5.1%} ({perf['correct']:3d}/{perf['total']:3d}) conf={avg_conf:.2f}")
print(f"\n[TARGET] Specialist Selection Analysis:")
for specialist, count in sorted(specialist_usage.items()):
percentage = (count / len(results)) * 100
print(f" {specialist:20s}: {count:3d} times ({percentage:4.1f}%)")
# Save results
timestamp = int(time.time())
results_data = {
"metadata": {
"evaluation_type": "real_mmlu",
"use_real_models": use_real_models,
"total_samples": total_questions,
"subjects_filter": subjects_filter,
"timestamp": timestamp,
"date": time.strftime("%Y-%m-%d %H:%M:%S")
},
"summary": {
"overall_accuracy": overall_accuracy,
"total_correct": total_correct,
"total_questions": total_questions,
"avg_confidence": avg_confidence,
"avg_processing_time_ms": avg_processing_time,
"total_runtime_seconds": total_time
},
"subject_performance": {
subject: {
"accuracy": perf['correct'] / perf['total'],
"correct": perf['correct'],
"total": perf['total'],
"avg_confidence": perf['confidence_sum'] / perf['total']
}
for subject, perf in subject_performance.items()
},
"specialist_usage": specialist_usage,
"detailed_results": results[:100] # Save first 100 detailed results
}
results_file = f"real_mmlu_results_{timestamp}.json"
with open(results_file, 'w') as f:
json.dump(results_data, f, indent=2)
print(f"\n? Results saved to: {results_file}")
# Performance assessment (realistic expectations)
if overall_accuracy >= 0.70:
assessment = "🎉 EXCELLENT - Strong performance on real benchmark!"
elif overall_accuracy >= 0.60:
assessment = "[OK] VERY GOOD - Solid real-world performance!"
elif overall_accuracy >= 0.50:
assessment = "👍 GOOD - Reasonable performance!"
elif overall_accuracy >= 0.40:
assessment = "[WARN] FAIR - Room for improvement"
else:
assessment = "[FAIL] POOR - Significant improvements needed"
print(f"\n Assessment: {assessment}")
return results_data
def main():
"""Main function with command line arguments"""
parser = argparse.ArgumentParser(description='Real MMLU Evaluation')
parser.add_argument('--max-samples', type=int, default=None,
help='Maximum number of samples to evaluate (default: all)')
parser.add_argument('--simulation', action='store_true',
help='Use simulation instead of real models')
parser.add_argument('--subjects', nargs='+', default=None,
help='Filter specific subjects (e.g. mathematics physics)')
parser.add_argument('--quick-test', action='store_true',
help='Quick test with 50 samples')
args = parser.parse_args()
max_samples = args.max_samples
if args.quick_test:
max_samples = 50
use_real_models = not args.simulation
# Run evaluation
results = run_real_mmlu_evaluation(
max_samples=max_samples,
use_real_models=use_real_models,
subjects_filter=args.subjects
)
if results is None:
print("[FAIL] Evaluation failed")
return 1
return 0
if __name__ == "__main__":
exit(main())
# Mathematics
{"question": "What is the derivative of ln(x)?", "choices": ["1/x", "ln(x)", "x", "e^x"], "answer": "A", "subject": "mathematics"},
{"question": "If f(x) = 3x² + 2x - 5, what is f'(2)?", "choices": ["14", "11", "8", "5"], "answer": "A", "subject": "mathematics"},
{"question": "What is the integral of 2x?", "choices": ["x²", "x² + C", "2x²", "2"], "answer": "B", "subject": "mathematics"},
{"question": "If P(A) = 0.3 and P(B) = 0.4, and A and B are independent, what is P(A ∩ B)?", "choices": ["0.12", "0.70", "0.10", "0.07"], "answer": "A", "subject": "mathematics"},
{"question": "What is the limit of (sin x)/x as x approaches 0?", "choices": ["0", "1", "[INF]", "undefined"], "answer": "B", "subject": "mathematics"},
# Physics
{"question": "What is the unit of electric field strength?", "choices": ["Volts", "Volts per meter", "Amperes", "Ohms"], "answer": "B", "subject": "physics"},
{"question": "In simple harmonic motion, the acceleration is proportional to:", "choices": ["Velocity", "Displacement", "Time", "Frequency"], "answer": "B", "subject": "physics"},
{"question": "The speed of light in vacuum is approximately:", "choices": ["3 x 10⁸ m/s", "3 x 10⁶ m/s", "3 x 10¹⁰ m/s", "3 x 10⁵ m/s"], "answer": "A", "subject": "physics"},
{"question": "According to Newton's second law, F = ma. If force doubles and mass stays constant, acceleration:", "choices": ["Halves", "Doubles", "Stays same", "Quadruples"], "answer": "B", "subject": "physics"},
{"question": "The frequency of a wave is inversely related to its:", "choices": ["Amplitude", "Wavelength", "Speed", "Phase"], "answer": "B", "subject": "physics"},
# Computer Science
{"question": "What is the time complexity of binary search?", "choices": ["O(n)", "O(log n)", "O(n²)", "O(1)"], "answer": "B", "subject": "computer_science"},
{"question": "Which data structure provides LIFO access?", "choices": ["Queue", "Stack", "Linked List", "Array"], "answer": "B", "subject": "computer_science"},
{"question": "What is the average time complexity of hash table lookup?", "choices": ["O(1)", "O(log n)", "O(n)", "O(n log n)"], "answer": "A", "subject": "computer_science"},
{"question": "In object-oriented programming, what does encapsulation refer to?", "choices": ["Inheritance", "Data hiding", "Polymorphism", "Abstraction"], "answer": "B", "subject": "computer_science"},
{"question": "Which sorting algorithm has the best average-case time complexity?", "choices": ["Bubble Sort", "Merge Sort", "Selection Sort", "Insertion Sort"], "answer": "B", "subject": "computer_science"},
# Biology
{"question": "Which organelle is responsible for cellular respiration?", "choices": ["Nucleus", "Mitochondria", "Golgi apparatus", "Ribosomes"], "answer": "B", "subject": "biology"},
{"question": "What process produces ATP in mitochondria?", "choices": ["Glycolysis", "Krebs cycle", "Electron transport chain", "Fermentation"], "answer": "C", "subject": "biology"},
{"question": "Which organelle is responsible for protein synthesis?", "choices": ["Nucleus", "Ribosomes", "Golgi apparatus", "Lysosomes"], "answer": "B", "subject": "biology"},
{"question": "DNA replication occurs during which phase of the cell cycle?", "choices": ["G1", "S", "G2", "M"], "answer": "B", "subject": "biology"},
{"question": "What is the primary function of chloroplasts?", "choices": ["Protein synthesis", "Photosynthesis", "Cellular respiration", "Waste disposal"], "answer": "B", "subject": "biology"},
# Chemistry
{"question": "What is the pH of a neutral solution at 25°C?", "choices": ["0", "7", "14", "1"], "answer": "B", "subject": "chemistry"},
{"question": "Which type of bond involves sharing of electrons?", "choices": ["Ionic", "Metallic", "Covalent", "Hydrogen"], "answer": "C", "subject": "chemistry"},
{"question": "What is the atomic number of carbon?", "choices": ["4", "6", "8", "12"], "answer": "B", "subject": "chemistry"},
{"question": "Which gas law relates pressure and volume at constant temperature?", "choices": ["Charles's Law", "Boyle's Law", "Gay-Lussac's Law", "Avogadro's Law"], "answer": "B", "subject": "chemistry"},
{"question": "What is the molecular formula for glucose?", "choices": ["C₆H₁₂O₆", "C₆H₁₀O₅", "C₅H₁₀O₅", "C₁₂H₂₂O₁₁"], "answer": "A", "subject": "chemistry"},
# Economics
{"question": "Which economic theory emphasizes government intervention?", "choices": ["Classical", "Keynesian", "Austrian", "Monetarist"], "answer": "B", "subject": "economics"},
{"question": "What does GDP measure?", "choices": ["Government debt", "Total economic output", "Inflation rate", "Employment rate"], "answer": "B", "subject": "economics"},
{"question": "In supply and demand theory, what happens to price when supply increases and demand stays constant?", "choices": ["Price increases", "Price decreases", "Price stays same", "Price becomes volatile"], "answer": "B", "subject": "economics"},
{"question": "What is opportunity cost?", "choices": ["The cost of production", "The value of the next best alternative", "The market price", "The sunk cost"], "answer": "B", "subject": "economics"},
# Psychology
{"question": "Who developed the theory of classical conditioning?", "choices": ["Skinner", "Pavlov", "Freud", "Watson"], "answer": "B", "subject": "psychology"},
{"question": "What part of the brain is primarily responsible for memory formation?", "choices": ["Cerebellum", "Hippocampus", "Medulla", "Cortex"], "answer": "B", "subject": "psychology"},
# Management
{"question": "What is the critical path method used for in project management?", "choices": ["Budget planning", "Schedule optimization", "Risk assessment", "Quality control"], "answer": "B", "subject": "management"},
{"question": "Which leadership style involves high support and low direction?", "choices": ["Directing", "Coaching", "Supporting", "Delegating"], "answer": "C", "subject": "management"},
]
print(f"[BRAIN] Testing BIOMIND on {len(mmlu_samples)} comprehensive MMLU samples")
print(f"[CHART] Subjects covered: Mathematics, Physics, Computer Science, Biology, Chemistry, Economics, Psychology, Management")
# Run evaluation
results = []
subject_performance = {}
start_time = time.time()
for i, sample in enumerate(mmlu_samples):
print(f"\n? Question {i+1}/{len(mmlu_samples)} ({sample['subject']})")
result = evaluator.evaluate_with_reflection(
sample['question'],
sample['choices'],
sample['answer'],
sample['subject']
)
results.append(result)
# Track by subject
subject = sample['subject']
if subject not in subject_performance:
subject_performance[subject] = {'correct': 0, 'total': 0}
subject_performance[subject]['total'] += 1
if result['is_correct']:
subject_performance[subject]['correct'] += 1
status = "[OK]" if result['is_correct'] else "[FAIL]"
print(f" {status} {result['routing_method']:15s} "
f"({result['selected_specialist']:20s}) "
f"Subject: {subject:15s} "
f"Conf: {result['confidence']:.2f}")
# Calculate metrics
total_time = time.time() - start_time
total_correct = sum(1 for r in results if r['is_correct'])
total_questions = len(results)
overall_accuracy = total_correct / total_questions
avg_confidence = sum(r['confidence'] for r in results) / len(results)
avg_processing_time = sum(r.get('processing_time_ms', 0) for r in results) / len(results)
# Results summary
print(f"\n? High-Performance MMLU Results Summary")
print(f"=" * 60)
print(f" Overall Accuracy: {overall_accuracy:.1%} ({total_correct}/{total_questions})")
print(f" Average Confidence: {avg_confidence:.3f}")
print(f" Average Processing Time: {avg_processing_time:.1f}ms")
print(f" Total Runtime: {total_time:.1f}s")
print(f"\n[STATS] Subject Performance:")
for subject, perf in subject_performance.items():
accuracy = perf['correct'] / perf['total']
print(f" {subject:15s}: {accuracy:.1%} ({perf['correct']}/{perf['total']})")
# Specialist usage analysis
specialist_usage = {}
for result in results:
specialist = result['selected_specialist']
if specialist not in specialist_usage:
specialist_usage[specialist] = 0
specialist_usage[specialist] += 1
print(f"\n[TARGET] Specialist Selection Analysis:")
for specialist, count in specialist_usage.items():
percentage = (count / len(results)) * 100
print(f" {specialist:20s}: {count:2d} times ({percentage:4.1f}%)")
# Save results
timestamp = int(time.time())
results_data = {
"summary": {
"overall_accuracy": overall_accuracy,
"total_correct": total_correct,
"total_questions": total_questions,
"avg_confidence": avg_confidence,
"avg_processing_time_ms": avg_processing_time,
"total_runtime_seconds": total_time,
"timestamp": timestamp
},
"subject_performance": {
subject: {
"accuracy": perf['correct'] / perf['total'],
"correct": perf['correct'],
"total": perf['total']
}
for subject, perf in subject_performance.items()
},
"specialist_usage": specialist_usage,
"detailed_results": results
}
results_file = f"high_performance_mmlu_results_{timestamp}.json"
with open(results_file, 'w') as f:
json.dump(results_data, f, indent=2)
print(f"\n? Results saved to: {results_file}")
# Performance assessment
if overall_accuracy >= 0.90:
assessment = "🎉 EXCELLENT - Exceeds expectations!"
elif overall_accuracy >= 0.80:
assessment = "[OK] VERY GOOD - Meets high standards!"
elif overall_accuracy >= 0.70:
assessment = "👍 GOOD - Solid performance!"
else:
assessment = "[WARN] NEEDS IMPROVEMENT - Below target!"
print(f"\n Assessment: {assessment}")
return results_data
if __name__ == "__main__":
run_comprehensive_mmlu()