| from __future__ import annotations |
|
|
| from collections import defaultdict |
| from statistics import mean |
|
|
| from .io import metadata_path, read_jsonl |
|
|
|
|
| METRICS = [ |
| "video_quality_score", |
| "progress_consistency_score", |
| "implicit_rule_score", |
| "progress_goal_score", |
| "last_frame_goal_score", |
| ] |
|
|
| MME_METRICS = [ |
| "instruction_alignment", |
| "temporal_consistency", |
| "visual_stability", |
| "content_fidelity", |
| "focus_relevance", |
| ] |
|
|
|
|
| def _aggregate(rows: list[dict], metrics: list[str]) -> dict: |
| values = {metric: [] for metric in metrics} |
| sample_scores = [] |
| for row in rows: |
| present = [] |
| for metric in metrics: |
| value = row.get(metric) |
| if value is None: |
| continue |
| number = float(value) |
| values[metric].append(number) |
| present.append(number) |
| if present: |
| sample_scores.append(mean(present)) |
| return { |
| "num_results": len(rows), |
| "metrics": { |
| metric: { |
| "mean": mean(metric_values) if metric_values else None, |
| "count": len(metric_values), |
| "missing": len(rows) - len(metric_values), |
| } |
| for metric, metric_values in values.items() |
| }, |
| "sample_macro_average": mean(sample_scores) if sample_scores else None, |
| } |
|
|
|
|
| def summarize_vwg(dataset_root, results_path) -> dict: |
| metadata = {row["id"]: row for row in read_jsonl(metadata_path(dataset_root))} |
| results = read_jsonl(results_path) |
| by_dimension = defaultdict(list) |
| by_task_group = defaultdict(list) |
| unknown_ids = [] |
| known_results = [] |
| for row in results: |
| sample = metadata.get(int(row["id"])) |
| if sample is None: |
| unknown_ids.append(row["id"]) |
| continue |
| known_results.append(row) |
| by_dimension[sample["dimension_id"]].append(row) |
| by_task_group[sample["task_group_id"]].append(row) |
|
|
| return { |
| "overall": _aggregate(known_results, METRICS), |
| "by_dimension": { |
| key: _aggregate(rows, METRICS) |
| for key, rows in sorted(by_dimension.items()) |
| }, |
| "by_task_group": { |
| key: _aggregate(rows, METRICS) |
| for key, rows in sorted(by_task_group.items()) |
| }, |
| "unknown_result_ids": unknown_ids, |
| } |
|
|
|
|
| def summarize_mme(results_path) -> dict: |
| return _aggregate(read_jsonl(results_path), MME_METRICS) |
|
|