Update evaluator_module.py (#31)
Browse files- Update evaluator_module.py (617a05d32ef93621944bd34f378c84e6177f6afa)
Co-authored-by: Manay Porwal <manayporwal07@users.noreply.huggingface.co>
- evaluator_module.py +50 -50
evaluator_module.py
CHANGED
|
@@ -239,71 +239,71 @@ class AetherScoreEvaluator:
|
|
| 239 |
|
| 240 |
return result
|
| 241 |
# Batch Evaluation # Input of JSON/CSV file
|
| 242 |
-
# def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 243 |
-
# """Process a batch of evaluations in parallel."""
|
| 244 |
-
|
| 245 |
-
# results = []
|
| 246 |
-
|
| 247 |
-
# # Get Item function
|
| 248 |
-
# def process_item(item):
|
| 249 |
-
# # Calling our Evalution function for Single prompt response pair
|
| 250 |
-
# eval_result = self.evaluate_single(
|
| 251 |
-
# prompt=item.get('prompt', ''),
|
| 252 |
-
# response=item.get('response', ''),
|
| 253 |
-
# expected_answer=item.get('expected_answer',''),
|
| 254 |
-
# task_type=item.get('task_type', 'general'),
|
| 255 |
-
# eval_id=f"eval_{idx}",
|
| 256 |
-
# agent_name=agent_name
|
| 257 |
-
# )
|
| 258 |
-
# # Combining with original metadata
|
| 259 |
-
# eval_result.update({
|
| 260 |
-
# 'task_id': item.get('task_id', eval_result['scores']['eval_id']),
|
| 261 |
-
# 'agent_name': item.get('agent_name', 'Unknown'),
|
| 262 |
-
# })
|
| 263 |
-
# return eval_result
|
| 264 |
-
|
| 265 |
-
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 266 |
-
# future_to_item = {executor.submit(process_item, item): item for item in data}
|
| 267 |
-
# for future in concurrent.futures.as_completed(future_to_item):
|
| 268 |
-
# try:
|
| 269 |
-
# results.append(future.result())
|
| 270 |
-
# except Exception as exc:
|
| 271 |
-
# print(f'An item generated an exception: {exc}')
|
| 272 |
-
|
| 273 |
-
# return results
|
| 274 |
-
|
| 275 |
def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 276 |
"""Process a batch of evaluations in parallel."""
|
| 277 |
|
| 278 |
results = []
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
|
|
|
| 282 |
eval_result = self.evaluate_single(
|
| 283 |
-
prompt=item.get(
|
| 284 |
-
response=item.get(
|
| 285 |
-
expected_answer=item.get(
|
| 286 |
-
task_type=item.get(
|
|
|
|
|
|
|
| 287 |
)
|
|
|
|
| 288 |
eval_result.update({
|
| 289 |
-
|
| 290 |
-
|
| 291 |
})
|
| 292 |
return eval_result
|
| 293 |
-
|
| 294 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
for idx, item in enumerate(data, start=1)
|
| 298 |
-
}
|
| 299 |
-
for future in concurrent.futures.as_completed(future_to_idx):
|
| 300 |
try:
|
| 301 |
results.append(future.result())
|
| 302 |
except Exception as exc:
|
| 303 |
-
print(f
|
| 304 |
-
|
| 305 |
return results
|
| 306 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 307 |
# Instruction Following Evaluation (Prompt, Response)
|
| 308 |
def _evaluate_instruction_following(self, prompt: str, response: str) -> Tuple[float, str]:
|
| 309 |
score, checks, passed = 1.0, 0, 0
|
|
|
|
| 239 |
|
| 240 |
return result
|
| 241 |
# Batch Evaluation # Input of JSON/CSV file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 242 |
def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 243 |
"""Process a batch of evaluations in parallel."""
|
| 244 |
|
| 245 |
results = []
|
| 246 |
+
|
| 247 |
+
# Get Item function
|
| 248 |
+
def process_item(item):
|
| 249 |
+
# Calling our Evalution function for Single prompt response pair
|
| 250 |
eval_result = self.evaluate_single(
|
| 251 |
+
prompt=item.get('prompt', ''),
|
| 252 |
+
response=item.get('response', ''),
|
| 253 |
+
expected_answer=item.get('expected_answer',''),
|
| 254 |
+
task_type=item.get('task_type', 'general'),
|
| 255 |
+
eval_id=f"eval_{idx}",
|
| 256 |
+
agent_name=agent_name
|
| 257 |
)
|
| 258 |
+
# Combining with original metadata
|
| 259 |
eval_result.update({
|
| 260 |
+
'task_id': item.get('task_id', eval_result['scores']['eval_id']),
|
| 261 |
+
'agent_name': item.get('agent_name', 'Unknown'),
|
| 262 |
})
|
| 263 |
return eval_result
|
| 264 |
+
|
| 265 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 266 |
+
future_to_item = {executor.submit(process_item, item): item for item in data}
|
| 267 |
+
for future in concurrent.futures.as_completed(future_to_item):
|
|
|
|
|
|
|
|
|
|
| 268 |
try:
|
| 269 |
results.append(future.result())
|
| 270 |
except Exception as exc:
|
| 271 |
+
print(f'An item generated an exception: {exc}')
|
| 272 |
+
|
| 273 |
return results
|
| 274 |
|
| 275 |
+
# def evaluate_batch(self, data: List[Dict], mode: str = "comprehensive") -> List[Dict]:
|
| 276 |
+
# """Process a batch of evaluations in parallel."""
|
| 277 |
+
|
| 278 |
+
# results = []
|
| 279 |
+
|
| 280 |
+
# def process_item(item, idx):
|
| 281 |
+
# agent_name = item.get("agent_name", f"Agent-{idx}")
|
| 282 |
+
# eval_result = self.evaluate_single(
|
| 283 |
+
# prompt=item.get("prompt", ""),
|
| 284 |
+
# response=item.get("response", ""),
|
| 285 |
+
# expected_answer=item.get("expected_answer", ""),
|
| 286 |
+
# task_type=item.get("task_type", "general"),
|
| 287 |
+
# )
|
| 288 |
+
# eval_result.update({
|
| 289 |
+
# "task_id": item.get("task_id", eval_result["scores"]["eval_id"]),
|
| 290 |
+
# "agent_name": agent_name,
|
| 291 |
+
# })
|
| 292 |
+
# return eval_result
|
| 293 |
+
|
| 294 |
+
# with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 295 |
+
# future_to_idx = {
|
| 296 |
+
# executor.submit(process_item, item, idx): idx
|
| 297 |
+
# for idx, item in enumerate(data, start=1)
|
| 298 |
+
# }
|
| 299 |
+
# for future in concurrent.futures.as_completed(future_to_idx):
|
| 300 |
+
# try:
|
| 301 |
+
# results.append(future.result())
|
| 302 |
+
# except Exception as exc:
|
| 303 |
+
# print(f"An item generated an exception: {exc}")
|
| 304 |
+
|
| 305 |
+
# return results
|
| 306 |
+
|
| 307 |
# Instruction Following Evaluation (Prompt, Response)
|
| 308 |
def _evaluate_instruction_following(self, prompt: str, response: str) -> Tuple[float, str]:
|
| 309 |
score, checks, passed = 1.0, 0, 0
|