Datasets:
Download code/src/pvr_eval/schema.py from wenjieshu/solveedit_benchmark_2728: direct link, hf CLI and curl.
- Browser
- Download file 4.26 kB
-
https://huggingface.co/datasets/wenjieshu/solveedit_benchmark_2728/resolve/main/code/src/pvr_eval/schema.py
- Command line
-
hf download hf://datasets/wenjieshu/solveedit_benchmark_2728/code/src/pvr_eval/schema.py
-
curl -L -o schema.py https://huggingface.co/datasets/wenjieshu/solveedit_benchmark_2728/resolve/main/code/src/pvr_eval/schema.py
4.26 kB
| """Lightweight schema normalization for PVR eval specs and observations.""" | |
| from __future__ import annotations | |
| from dataclasses import dataclass, field | |
| from pathlib import Path | |
| from typing import Any | |
| DEFAULT_WEIGHTS: dict[str, dict[str, float]] = { | |
| "exact_state_gt": { | |
| "instruction": 0.60, | |
| "spatial": 0.10, | |
| "attribute": 0.05, | |
| "invariant": 0.20, | |
| "visual_quality": 0.05, | |
| }, | |
| "constraint_gt": { | |
| "instruction": 0.45, | |
| "spatial": 0.20, | |
| "attribute": 0.10, | |
| "invariant": 0.20, | |
| "visual_quality": 0.05, | |
| }, | |
| "open_edit": { | |
| "instruction": 0.40, | |
| "spatial": 0.10, | |
| "attribute": 0.20, | |
| "invariant": 0.25, | |
| "visual_quality": 0.05, | |
| }, | |
| "quality_stress": { | |
| "instruction": 0.25, | |
| "spatial": 0.10, | |
| "attribute": 0.20, | |
| "invariant": 0.25, | |
| "visual_quality": 0.20, | |
| }, | |
| } | |
| CHECK_DIMENSION_BY_TYPE = { | |
| "presence": "instruction", | |
| "absence": "instruction", | |
| "count": "instruction", | |
| "assignment": "instruction", | |
| "connectivity": "instruction", | |
| "route": "instruction", | |
| "spatial_relation": "spatial", | |
| "attribute": "attribute", | |
| "invariant": "invariant", | |
| "no_extra_change": "invariant", | |
| "visual_quality": "visual_quality", | |
| } | |
| class EvalSpec: | |
| """Normalized eval specification.""" | |
| path: Path | |
| case_dir: Path | |
| case_id: str | |
| task_family: str | |
| eval_type: str | |
| instruction: str = "" | |
| input_image: str = "images/input.png" | |
| reference_gt_image: str | None = None | |
| mask_paths: dict[str, str] = field(default_factory=dict) | |
| entities: list[dict[str, Any]] = field(default_factory=list) | |
| atomic_checks: list[dict[str, Any]] = field(default_factory=list) | |
| scoring_weights: dict[str, float] = field(default_factory=dict) | |
| parser_strategy: dict[str, Any] = field(default_factory=dict) | |
| human_review_triggers: list[str] = field(default_factory=list) | |
| thresholds: dict[str, float] = field(default_factory=dict) | |
| def from_dict(cls, payload: dict[str, Any], path: str | Path) -> "EvalSpec": | |
| spec_path = Path(path) | |
| case_dir = spec_path.parent.parent if spec_path.parent.name == "metadata" else spec_path.parent | |
| eval_type = str(payload.get("eval_type", "constraint_gt")) | |
| weights = dict(DEFAULT_WEIGHTS.get(eval_type, DEFAULT_WEIGHTS["constraint_gt"])) | |
| weights.update(payload.get("scoring_weights", {})) | |
| return cls( | |
| path=spec_path, | |
| case_dir=case_dir, | |
| case_id=str(payload.get("case_id") or case_dir.name), | |
| task_family=str(payload.get("task_family", "")), | |
| eval_type=eval_type, | |
| instruction=str(payload.get("instruction", "")), | |
| input_image=str(payload.get("input_image", "images/input.png")), | |
| reference_gt_image=payload.get("reference_gt_image"), | |
| mask_paths=dict(payload.get("mask_paths", {})), | |
| entities=list(payload.get("entities", [])), | |
| atomic_checks=list(payload.get("atomic_checks", [])), | |
| scoring_weights=weights, | |
| parser_strategy=dict(payload.get("parser_strategy", {})), | |
| human_review_triggers=list(payload.get("human_review_triggers", [])), | |
| thresholds=dict(payload.get("thresholds", {})), | |
| ) | |
| def resolve(self, rel_or_abs: str | Path | None) -> Path | None: | |
| if rel_or_abs is None: | |
| return None | |
| path = Path(rel_or_abs) | |
| if path.is_absolute(): | |
| return path | |
| return self.case_dir / path | |
| def normalize_observations(payload: dict[str, Any] | None) -> dict[str, Any]: | |
| if not payload: | |
| return {} | |
| return { | |
| "entities": dict(payload.get("entities", {})), | |
| "atomic_checks": dict(payload.get("atomic_checks", {})), | |
| "dimension_scores": dict(payload.get("dimension_scores", {})), | |
| "visual_quality": payload.get("visual_quality"), | |
| "notes": payload.get("notes"), | |
| "detected_failures": list(payload.get("detected_failures", [])), | |
| "evidence": dict(payload.get("evidence", {})), | |
| "judge_meta": dict(payload.get("judge_meta", {})), | |
| } | |