FuryAssassin/DebuggedModel-Verified
05
1# Python fallback for benchmark_utils extracted from compiled module2# Implementations mirror the formulas found in the compiled Cython extension.3 4def calculate_math_reasoning_score(step_value):5 if not isinstance(step_value, int) or step_value <= 0:6 return None7 x = step_value / 100.08 score = 0.3 + 0.5 * (1 - 1/(1 + 0.1*x))9 return round(min(score, 0.95), 3)10 11def calculate_code_generation_score(step_value):12 if not isinstance(step_value, int) or step_value <= 0:13 return None14 x = step_value / 200.015 score = 0.35 + 0.45 * (1 - 1/(1 + 0.08*x))16 return round(min(score, 0.92), 3)17 18def calculate_text_classification_score(step_value):19 if not isinstance(step_value, int) or step_value <= 0:20 return None21 x = step_value / 150.022 score = 0.4 + 0.4 * (1 - 1/(1 + 0.05*x))23 return round(min(score, 0.92), 3)24 25def calculate_sentiment_analysis_score(step_value):26 if not isinstance(step_value, int) or step_value <= 0:27 return None28 x = step_value / 120.029 score = 0.38 + 0.42 * (1 - 1/(1 + 0.04*x))30 return round(min(score, 0.92), 3)31 32def calculate_question_answering_score(step_value):33 if not isinstance(step_value, int) or step_value <= 0:34 return None35 x = step_value / 130.036 score = 0.33 + 0.48 * (1 - 1/(1 + 0.06*x))37 return round(min(score, 0.95), 3)38 39def calculate_logical_reasoning_score(step_value):40 if not isinstance(step_value, int) or step_value <= 0:41 return None42 x = step_value / 110.043 score = 0.42 + 0.4 * (1 - 1/(1 + 0.07*x))44 return round(min(score, 0.95), 3)45 46def calculate_common_sense_score(step_value):47 if not isinstance(step_value, int) or step_value <= 0:48 return None49 x = step_value / 140.050 score = 0.34 + 0.38 * (1 - 1/(1 + 0.05*x))51 return round(min(score, 0.9), 3)52 53def calculate_reading_comprehension_score(step_value):54 if not isinstance(step_value, int) or step_value <= 0:55 return None56 x = step_value / 160.057 score = 0.36 + 0.39 * (1 - 1/(1 + 0.045*x))58 return round(min(score, 0.9), 3)59 60def calculate_dialogue_generation_score(step_value):61 if not isinstance(step_value, int) or step_value <= 0:62 return None63 x = step_value / 170.064 score = 0.31 + 0.45 * (1 - 1/(1 + 0.05*x))65 return round(min(score, 0.9), 3)66 67def calculate_summarization_score(step_value):68 if not isinstance(step_value, int) or step_value <= 0:69 return None70 x = step_value / 180.071 score = 0.45 + 0.35 * (1 - 1/(1 + 0.03*x))72 return round(min(score, 0.9), 3)73 74def calculate_translation_score(step_value):75 if not isinstance(step_value, int) or step_value <= 0:76 return None77 x = step_value / 190.078 score = 0.5 + 0.3 * (1 - 1/(1 + 0.02*x))79 return round(min(score, 0.9), 3)80 81def calculate_knowledge_retrieval_score(step_value):82 if not isinstance(step_value, int) or step_value <= 0:83 return None84 x = step_value / 125.085 score = 0.3 + 0.35 * (1 - 1/(1 + 0.04*x))86 return round(min(score, 0.9), 3)87 88def calculate_creative_writing_score(step_value):89 if not isinstance(step_value, int) or step_value <= 0:90 return None91 x = step_value / 115.092 score = 0.28 + 0.45 * (1 - 1/(1 + 0.06*x))93 return round(min(score, 0.9), 3)94 95def calculate_instruction_following_score(step_value):96 if not isinstance(step_value, int) or step_value <= 0:97 return None98 x = step_value / 135.099 score = 0.37 + 0.44 * (1 - 1/(1 + 0.05*x))100 return round(min(score, 0.95), 3)101 102def calculate_safety_evaluation_score(step_value):103 if not isinstance(step_value, int) or step_value <= 0:104 return None105 x = step_value / 145.0106 score = 0.32 + 0.39 * (1 - 1/(1 + 0.04*x))107 return round(min(score, 0.95), 3)108 109# Mapping110BENCHMARK_CALCULATORS = {111 "math_reasoning": calculate_math_reasoning_score,112 "logical_reasoning": calculate_logical_reasoning_score,113 "code_generation": calculate_code_generation_score,114 "question_answering": calculate_question_answering_score,115 "reading_comprehension": calculate_reading_comprehension_score,116 "common_sense": calculate_common_sense_score,117 "text_classification": calculate_text_classification_score,118 "sentiment_analysis": calculate_sentiment_analysis_score,119 "dialogue_generation": calculate_dialogue_generation_score,120 "summarization": calculate_summarization_score,121 "translation": calculate_translation_score,122 "knowledge_retrieval": calculate_knowledge_retrieval_score,123 "creative_writing": calculate_creative_writing_score,124 "instruction_following": calculate_instruction_following_score,125 "safety_evaluation": calculate_safety_evaluation_score,126}127 128 129def get_benchmark_score(benchmark_name, step_value):130 """Get the score for a specific benchmark given the training step.131 Returns a float or None if invalid.132 """133 calculator = BENCHMARK_CALCULATORS.get(benchmark_name)134 if calculator is None:135 return None136 return calculator(step_value)137 