Spaces:
Sleeping
Sleeping
Update evaluator_module.py
Browse files- evaluator_module.py +26 -49
evaluator_module.py
CHANGED
|
@@ -167,60 +167,37 @@ class AetherScoreEvaluator:
|
|
| 167 |
|
| 168 |
return result
|
| 169 |
# Batch Evaluation # Input of JSON/CSV file
|
| 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 |
-
# return results
|
| 200 |
-
def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 201 |
-
"""Process a batch of evaluations sequentially (no threading)."""
|
| 202 |
-
|
| 203 |
-
results = []
|
| 204 |
-
|
| 205 |
-
for item in data:
|
| 206 |
-
try:
|
| 207 |
-
# Evaluate a single prompt-response pair
|
| 208 |
-
eval_result = self.evaluate_single(
|
| 209 |
-
prompt=item.get('prompt', ''),
|
| 210 |
-
response=item.get('response', ''),
|
| 211 |
-
expected_answer=item.get('expected_answer', ''),
|
| 212 |
-
task_type=item.get('task_type', 'general')
|
| 213 |
-
)
|
| 214 |
-
# Combine with original metadata
|
| 215 |
-
eval_result.update({
|
| 216 |
-
'task_id': item.get('task_id', eval_result['scores']['eval_id']),
|
| 217 |
-
'agent_name': item.get('agent_name', 'Unknown'),
|
| 218 |
-
})
|
| 219 |
-
results.append(eval_result)
|
| 220 |
-
except Exception as exc:
|
| 221 |
-
print(f'An item generated an exception: {exc}')
|
| 222 |
-
|
| 223 |
return results
|
|
|
|
| 224 |
|
| 225 |
# Instruction Following Evaluation (Prompt, Response)
|
| 226 |
def _evaluate_instruction_following(self, prompt: str, response: str) -> Tuple[float, str]:
|
|
|
|
| 167 |
|
| 168 |
return result
|
| 169 |
# Batch Evaluation # Input of JSON/CSV file
|
| 170 |
+
def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 171 |
+
"""Process a batch of evaluations in parallel."""
|
| 172 |
|
| 173 |
+
results = []
|
| 174 |
|
| 175 |
+
# Get Item function
|
| 176 |
+
def process_item(item):
|
| 177 |
+
# Calling our Evalution function for Single prompt response pair
|
| 178 |
+
eval_result = self.evaluate_single(
|
| 179 |
+
prompt=item.get('prompt', ''),
|
| 180 |
+
response=item.get('response', ''),
|
| 181 |
+
expected_answer=item.get('expected_answer',''),
|
| 182 |
+
task_type=item.get('task_type', 'general')
|
| 183 |
+
)
|
| 184 |
+
# Combining with original metadata
|
| 185 |
+
eval_result.update({
|
| 186 |
+
'task_id': item.get('task_id', eval_result['scores']['eval_id']),
|
| 187 |
+
'agent_name': item.get('agent_name', 'Unknown'),
|
| 188 |
+
})
|
| 189 |
+
return eval_result
|
| 190 |
|
| 191 |
+
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 192 |
+
future_to_item = {executor.submit(process_item, item): item for item in data}
|
| 193 |
+
for future in concurrent.futures.as_completed(future_to_item):
|
| 194 |
+
try:
|
| 195 |
+
results.append(future.result())
|
| 196 |
+
except Exception as exc:
|
| 197 |
+
print(f'An item generated an exception: {exc}')
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
return results
|
| 200 |
+
|
| 201 |
|
| 202 |
# Instruction Following Evaluation (Prompt, Response)
|
| 203 |
def _evaluate_instruction_following(self, prompt: str, response: str) -> Tuple[float, str]:
|