Imp.Logprobs (Imp v0.5.0)

Copy Markdown View Source

Extracts joint token logprob for one enum-constrained JSON field.

The overlap rule comes from llm-structured-confidence 0.4.5 as used by GEPA commit 65df4325e3fb4781cf2ab17dd144d6ce2f7b98fe: token span [a, b) contributes when max(field_start, a) < min(field_end, b). String quotes are excluded.

Unlike the upstream helper, an empty overlap is an error. It is never turned into joint logprob 0.0 (raw confidence 1.0), because that would represent missing evidence as maximal confidence.

Summary

Functions

Extracts confidence for a dot-separated JSON field path.

Types

alternative()

@type alternative() :: %{
  token: String.t(),
  logprob: number(),
  raw_confidence: float(),
  resolved_value: String.t() | nil
}

extraction()

@type extraction() :: %{
  value: String.t(),
  joint_logprob: float(),
  raw_confidence: float(),
  tokens: [map()],
  top_alternatives: [alternative()]
}

Functions

extract(content, logprobs, field_path, enum_values)

@spec extract(String.t(), [map()], atom() | String.t(), [String.t()]) ::
  {:ok, extraction()} | {:error, term()}

Extracts confidence for a dot-separated JSON field path.