Download baselines/base.py from Anonymous1611/Lattice_Spike: direct link, hf CLI and curl.
- Browser
- Download file 1.37 kB
-
https://huggingface.co/Anonymous1611/Lattice_Spike/resolve/main/baselines/base.py
- Command line
-
hf download hf://Anonymous1611/Lattice_Spike/baselines/base.py
-
curl -L -o base.py https://huggingface.co/Anonymous1611/Lattice_Spike/resolve/main/baselines/base.py
1.37 kB
| """Base interfaces for token-level hallucination baseline detectors. | |
| Concrete baseline implementations live in follow-up branches. | |
| """ | |
| from __future__ import annotations | |
| from abc import ABC, abstractmethod | |
| from pathlib import Path | |
| from typing import Sequence | |
| from .structs import BaselineExample, TokenScoreResult | |
| class TokenScoreDetector(ABC): | |
| """Interface for baselines that return one score per answer token.""" | |
| def score( | |
| self, | |
| prompt: str, | |
| answer: str, | |
| answer_token_ids: Sequence[int] | None = None, | |
| ) -> TokenScoreResult: | |
| """Score generated answer tokens conditioned on the original prompt.""" | |
| raise NotImplementedError | |
| class TrainableTokenScoreDetector(TokenScoreDetector): | |
| """Interface for token-score baselines that require fitting.""" | |
| def fit(self, examples: Sequence[BaselineExample]) -> "TrainableTokenScoreDetector": | |
| """Fit the detector on labelled prompt/answer examples.""" | |
| raise NotImplementedError | |
| def save(self, path: str | Path) -> None: | |
| """Persist the fitted detector.""" | |
| raise NotImplementedError | |
| def load(cls, path: str | Path) -> "TrainableTokenScoreDetector": | |
| """Load a fitted detector.""" | |
| raise NotImplementedError | |