liveBook · Manning

Log probability

As explained in Build AI-Enhanced Web Apps

A log probability is the logarithm of the probability assigned to an event, such as a language-model token.

A log probability expresses how likely a language model considers an event, such as a generated token. Token-level scores expose confidence signals that applications can use when grounding responses and deciding whether to trust or verify them. section 7.2.6

A practical integration can:

  • Request per-token scores and alternative candidates by enabling logprobs and topLogprobs in an OpenAI chat configuration. section 7.2.6
  • Inspect token, token_logprobs, and top_logprobs values to see generated-token likelihoods and competing choices. section 7.2.6
  • Combine confidence metrics with a threshold and an ask-user fallback in an enhanced RAG query. section 7.2.6

Confidence-aware grounded response

A conversation handler can perform an enhanced retrieval query with a confidence threshold of 85, log returned confidence metrics, and ask the user for clarification when confidence is insufficient. section 7.2.6

"logprobs": {
        "tokens": ["Regular", "exercise", "improves", 
"physical", "health", ",", "boosts", "mental", 
"well-being", ",", "and", "enhances", "overall", 
"quality", "of", "life", "."],
        "token_logprobs": [-0.5, -0.7, -0.6, -0.8, 
-0.9, -1.0, -0.4, -0.5, -0.6, -0.7, -0.8, -0.9, -1.0, 
-1.1, -1.2, -1.3],
        "top_logprobs": [
          {"token": "Regular", "logprob": -0.5},
          {"token": "Consistent", "logprob": -0.6},
          {"token": "Daily", "logprob": -0.7},
          {"token": "exercise", "logprob": -0.7},
          {"token": "activity", "logprob": -0.8},
          {"token": "workout", "logprob": -0.9}
        ]
      }

Inspect a representative response containing generated tokens, per-token log probabilities, and alternative top-log-probability candidates. section 7.2.6

How Build AI-Enhanced Web Apps covers it

How deep it goes
Explains per-token scores and integration patterns, but stops short of formal probability mathematics and standardized framework support.
Examples
Uses OpenAI configuration, token-score response data, and a confidence-threshold RAG conversation handler.
What you can do after
Apply it via an API configuration to inspect token confidence and trigger grounded-response fallbacks.
How it connects
Connects log probabilities with language models, grounding, retrieval-augmented generation, confidence metrics, and fallback strategies.

Also explained in

Compare how 8 books explain log probability →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build AI-Enhanced Web Apps. The section links point to the parts of the book it draws on.