"""Prediction and label-spec types for localization given labels.""" from __future__ import annotations from dataclasses import dataclass from typing import Any from pydantic import BaseModel, Field @dataclass(frozen=True, slots=True) class LabelSpec: label: str multiplicity: int def to_dict(self) -> dict[str, Any]: return {"label": self.label, "multiplicity": self.multiplicity} @classmethod def from_dict(cls, raw: dict[str, Any]) -> LabelSpec: return cls(label=str(raw["label"]), multiplicity=int(raw["multiplicity"])) @dataclass(frozen=True, slots=True) class GoldSegment: start_sec: float end_sec: float label: str def to_dict(self) -> dict[str, Any]: return { "start_sec": float(self.start_sec), "end_sec": float(self.end_sec), "label": self.label, } @classmethod def from_dict(cls, raw: dict[str, Any]) -> GoldSegment: return cls( start_sec=float(raw["start_sec"]), end_sec=float(raw["end_sec"]), label=str(raw["label"]), ) class PredictedInterval(BaseModel): label_echo: str start_sec: float end_sec: float class LabelPrediction(BaseModel): label: str intervals: list[PredictedInterval] = Field(default_factory=list) class PredictionResult(BaseModel): """Structured model output for localization given labels.""" labels: list[LabelPrediction] = Field(default_factory=list)