-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_judgments.py
More file actions
40 lines (36 loc) · 1.49 KB
/
load_judgments.py
File metadata and controls
40 lines (36 loc) · 1.49 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
import os
import json
from pathlib import Path
def load_judgments(root: str) -> dict[str, dict]:
"""Walks `<root>/**/judgment.json`, loads JSON, and returns `{conversation_id: {metric_name: value, ...}}`."""
judgments = {}
root_path = Path(root)
if not root_path.is_dir():
print(f"Error: Root directory not found at '{root}'")
return judgments
judgment_files = list(root_path.rglob('judgment.json'))
if not judgment_files:
print(f"Warning: No 'judgment.json' files found in '{root}'")
return judgments
for path in judgment_files:
with open(path, 'r') as f:
try:
content = f.read()
if not content:
print(f"Warning: Empty judgment.json file at {path}")
continue
data = json.loads(content)
conversation_id = path.parent.name
judgments[conversation_id] = data
except json.JSONDecodeError:
print(f"Error decoding JSON from {path}")
except Exception as e:
print(f"An unexpected error occurred with file {path}: {e}")
return judgments
if __name__ == '__main__':
conversation_judgments = load_judgments('auto_eval_gen/results/transcripts/')
teacher_judgments = load_judgments('auto_eval_gen/results_debiased/transcripts/')
print("Conversation Judgments:")
print(conversation_judgments)
print("\nTeacher Judgments:")
print(teacher_judgments)