Policies¶
A policy is the questions, the fitted heads and their calibration in one file. The policies guide covers signing and routing.
fit_policy ¶
fit_policy(
model,
rows: Any,
questions: Optional[Mapping] = None,
*,
folds: int = 5,
target_precision: float = 0.95,
alpha: float = 0.1,
calibration_rows: Any = None,
) -> Policy
Heads, calibration, review band and off-topic limit from your labelled rows, as a Policy.
A small head per question over the frozen features (seconds on a GPU for a few hundred rows;
the reader is never touched), then a temperature and conformal threshold per question and a
review band held to target_precision, all measured on rows the heads never saw: a quarter
of rows taken evenly across the first question's labels, or calibration_rows if you
give them. Calibrating on the fitting rows is refused: a head is right on its own rows, so
every confidence becomes 1.000 and the review line cannot be placed.
The off-topic limit is the largest residual of the routing head (the first question) over the calibration rows; a record past it goes to review. Studio also raises it to the residual of generic off-topic messages, which a few hundred of your own rows cannot measure.
load_policy ¶
load_policy(
path,
model=None,
verify: Union[bool, str] = True,
trusted=None,
**load_kw,
) -> Policy
Install a trained policy from a folder or Studio's downloaded .zip, verified first.
model is a loaded :class:vegaml.Vega; without one, the reader the policy names is
loaded (load_kw go to :func:vegaml.load, e.g. device="cpu"). verify=True
checks hashes, signature and engine; verify="signed" also refuses an unsigned policy;
verify=False checks nothing. Returns a :class:Policy; policy.verified says what
was checked.
save_policy ¶
save_policy(
model,
path,
calibration=None,
questions: Optional[Mapping] = None,
novelty: Optional[Tuple[str, float]] = None,
) -> Dict[str, Any]
The model's fitted heads, the calibration and the questions to a folder, with a manifest
of hashes (unsigned) so :func:load_policy can tell if the folder was changed.
Policy ¶
Policy(
model,
calibration=None,
questions: Optional[Mapping] = None,
novelty: Optional[Tuple[str, float]] = None,
verified: Optional[Dict[str, Any]] = None,
source: Optional[str] = None,
manifest: Optional[Dict[str, Any]] = None,
)
A model with a trained policy installed. Built by :func:load_policy or :func:fit_policy.
decide ¶
decide(
state: Any = None,
questions: Optional[Mapping] = None,
*,
image: Any = None,
audio: Any = None,
video: Any = None,
review_below: Optional[float] = None,
alpha: Optional[str] = None,
**kw,
) -> Dict
Answer the questions about one record, with a route on every answer and on the record.
One of state (text or a JSON-able object), image, audio or video.
questions defaults to the policy's own. review_below replaces the policy's own
routing with your line (outbound still applies). Other keywords go to the model's decide
(views, asr, language, sampling_rate, frames).
The heads and the calibration were trained on text. A picture, or a clip decided from its
frames, is answered by the vision tower's zero-shot readout, which they do not cover: those
answers come back calibrated: False and go to review unless you give review_below.
thresholds ¶
What decides route right now, per question, so nothing about it is hidden.
save ¶
The policy to a folder that :func:load_policy reads. See :func:save_policy.