confidence

package
v0.206.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: Apache-2.0 Imports: 3 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package confidence derives a decision-confidence signal from a grammar- constrained model's per-token logprobs. With a grammar active, llama.cpp reports the RAW (pre-mask) distribution, so at the decision-value position the top alternatives reveal the model's genuine preference among the legal options. We aggregate that raw mass by legal class (folding spelling variants like "Yes"/"yes", dropping grammar-illegal tokens) and return the normalized margin between the top two classes — a low margin means the model was genuinely torn (e.g. an "eager-YES" borderline call) and the pipeline should escalate to a larger tier rather than accept it.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Margin

func Margin(toks []llamaclient.TokenLogprob, jsonKey string, classes []string) (float64, bool)

Margin returns a 0..1 separation between the model's top-1 and top-2 legal decision classes at the value position of jsonKey (e.g. "decision" / "label"), computed on the raw logprob distribution. ok=false when the position or a usable class distribution can't be resolved — the caller then falls back to other signals (self-reported confidence) rather than escalating blindly.

func MarginFull added in v0.206.0

func MarginFull(toks []llamaclient.TokenLogprob, jsonKey string, classes []string) (margin float64, declaredMass float64, ok bool)

MarginFull is the full-denominator margin and the declared (matched) mass share, for callers that need only those two numbers.

Types

type Detail added in v0.206.0

type Detail struct {
	Margin        float64
	MatchedMargin float64
	DeclaredMass  float64
	Ambiguous     int
}

Detail is the full view of one decision position. Margin and MatchedMargin are the SAME numerator over two different denominators, and they are NOT comparable to each other: a stored history of one scale must never be read as the other (register D-130).

MatchedMargin = (first - second) / mass on MATCHED class tokens  (today's gate)
Margin        = (first - second) / mass on EVERY alternative      (full scale)
DeclaredMass  = matched / all, in 0..1 — measured ~0.097 on llama.cpp, i.e.
                the matched scale inflates the margin by about 10x.
Ambiguous     = alternatives credited to NO class because they prefix more
                than one (classOf returns -1). On taxonomy-shaped label sets
                like {billing, billing_dispute} that silently zeroes real
                mass; counting it is what makes the zeroing rate measurable.

func MarginDetail added in v0.206.0

func MarginDetail(toks []llamaclient.TokenLogprob, jsonKey string, classes []string) (Detail, bool)

MarginDetail returns the full decision-position view at the value position of jsonKey. ok=false when the position or a usable raw distribution can't be resolved (no alternatives, or every alternative clamped to the -inf sentinel) — the caller then falls back to other signals rather than escalating blindly, exactly as with Margin.

ok here means "the RAW distribution was usable", which is weaker than Margin's ok ("matched class mass was usable"): a position where the model put all of its mass outside the legal classes yields ok=true with DeclaredMass == 0 and both margins 0 — that is a fact worth recording, not an absence of data.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL