Runs a sample's scorers and composes their results into a verdict.
{:ok, scorers} = Nous.Eval.Scoring.init(specs)
%{verdict: verdict, case_score: score} = Nous.Eval.Scoring.score(scorers, input)init/1 calls every scorer's Nous.Eval.Scorer.init/1 once, so bad
options fail the eval before any agent runs. score/3 runs each scorer in
its own task under Nous.TaskSupervisor with a time limit; a scorer that
raises, throws, exits or times out becomes a Nous.Eval.ScorerError and
never discards another scorer's result.
Result validation
Every Nous.Eval.Score is checked, never coerced: the name must be a
string, passed? a boolean, and the value :pass, :fail,
{:label, string} or a float in 0.0..1.0. A float outside that range is
a :non_finite error, any other shape :invalid_config. A required
scorer that skips without being declared skippable: true is an
:invalid_config error: "the gate did not look" must not read as "the
gate passed".
Verdict
Scores inherit required and weight from the Nous.Eval.Scorer.Spec
that declared their scorer (a scorer emitting several scores applies its
declaration to each).
:errorif any scorer returned an error:failif any required scorer's score haspassed?: false:failif the soft scores (required: false,weight > 0) exist and their weighted mean is below the threshold (the case'sthreshold, default0.5;Nous.Eval.run/2logs one warning per run naming the soft-scored cases that rely on the default):passotherwise
weight: 0 tracks a metric without affecting the verdict. Skipped soft
scorers are left out of the mean, as are labels without a float mapping
(see value_to_float/2).
case_score is the gated objective for optimizers: nil on :error,
0.0 when a required score failed, else the soft weighted mean, or 1.0
without soft scores. It ignores the threshold.
Summary
Functions
Initializes scorer specs. Calls each scorer's Nous.Eval.Scorer.init/1
once and stops at the first failure with {:error, {module, reason}}.
Scores one sample with initialized scorers and composes the verdict.
Converts a score value to a float for aggregation.
Types
@type result() :: %{ scores: [Nous.Eval.Score.t()], scorer_errors: [Nous.Eval.ScorerError.t()], skipped: [{String.t(), String.t()}], verdict: :pass | :fail | :error, case_score: float() | nil }
Functions
@spec init([Nous.Eval.Scorer.Spec.t()]) :: {:ok, [Nous.Eval.Scoring.Prepared.t()]} | {:error, {module(), term()}}
Initializes scorer specs. Calls each scorer's Nous.Eval.Scorer.init/1
once and stops at the first failure with {:error, {module, reason}}.
@spec score([Nous.Eval.Scoring.Prepared.t()], Nous.Eval.ScoreInput.t(), keyword()) :: result()
Scores one sample with initialized scorers and composes the verdict.
Options:
:timeout- per-scorer limit in ms, either one integer for every scorer or%{deterministic: ms, model_graded: ms}(default 5 000 ms deterministic, 60 000 ms model-graded):threshold- overrides the case's soft-group threshold:supervisor- theTask.Supervisorto run scorers under (defaultNous.TaskSupervisor)
Returns every score, scorer error and skip ({scorer_id, reason}), the
verdict and the gated case_score.
@spec value_to_float(Nous.Eval.Score.value(), %{optional(String.t()) => number()}) :: {:ok, float()} | :error
Converts a score value to a float for aggregation.
:pass is 1.0, :fail is 0.0, a float is itself, and
{:label, label} is label_values[label] when the scorer declared a
mapping (a scorer emitting labels puts it in the score's
metadata.label_values). A label without a mapping returns :error: it
is reported as a distribution, not averaged.
iex> Nous.Eval.Scoring.value_to_float(:pass)
{:ok, 1.0}
iex> Nous.Eval.Scoring.value_to_float({:label, "good"}, %{"good" => 0.75})
{:ok, 0.75}
iex> Nous.Eval.Scoring.value_to_float({:label, "odd"}, %{"good" => 0.75})
:error