Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Multimodal Uncertainty Quantification (multimodal-uncertainty)

PyPI version License: Apache 2.0 CI Status

End-to-End (E2E) Extraction Uncertainty Quantification in Multimodal Agent Pipelines.

multimodal-uncertainty quantifies extraction risk across vision-language models (Gemini, Qwen2.5-VL, Llama-Vision, vLLM, and local OpenAI-compatible endpoints) by isolating value-only log-probabilities and computing semantic entropy. Low-confidence fields can be automatically routed to Human-in-the-Loop (HITL) review or triggered for fallback verification.


Key Features

  • 🎯 Value-Only Logprob Filtering: Strips out fixed structural JSON characters ({, }, "key":) to eliminate false precision and compute pure extraction uncertainty.
  • ⚡ Multi-Provider Support: Built-in engines for Google Gemini (google-genai), vLLM (GuidedDecodingParams), Ollama, MLX-VLM, and local OpenAI-compatible endpoints.
  • 🧠 Semantic Entropy Sampling: Quantifies semantic variance across stochastic generations (Kuhn et al., 2023).
  • ⚖️ Decision Matrix Engine: Evaluates field-level and node-level perplexities to route payloads (AUTO_ACCEPT, NEEDS_REVIEW, REJECT).
  • 🌐 FastAPI Middleware: Middleware to inject uncertainty header scores (X-Extraction-Uncertainty-Score) into microservice responses.

Scientific Foundations

  1. Semantic Uncertainty in LLMs (Kuhn et al., 2023): Measures unpredictability by clustering generated answers into semantic equivalence classes rather than strict string matching.
  2. Length-Normalized Token Perplexity (Malinin & Gales, 2020): Prevents joint probability penalties on long fields by normalizing per-token log probabilities.
  3. Stepwise Perplexity Reasoning (Cui et al., 2025): Isolates intermediate token log-probabilities to pinpoint precise operational bottlenecks in agentic workflows.

Quickstart

Installation

pip install multimodal-uncertainty

For vLLM or FastAPI support:

pip install "multimodal-uncertainty[all]"

Basic Gemini Usage

from pydantic import BaseModel
from multimodal_uncertainty import GeminiUncertaintyEngine, PipelineDecisionEngine

class DocumentSchema(BaseModel):
    document_id: str
    total_amount: float
    vendor_name: str

# Initialize Gemini engine
engine = GeminiUncertaintyEngine()

# Read input image/pdf bytes
with open("invoice.pdf", "rb") as f:
    payload = f.read()

# Extract and evaluate field-level perplexities & semantic entropy
node_result = engine.extract_and_evaluate(
    image_or_pdf_bytes=payload,
    mime_type="application/pdf",
    prompt="Extract invoice metadata.",
    schema_cls=DocumentSchema,
)

# Route decisions
decision_engine = PipelineDecisionEngine(ppl_threshold=2.2, entropy_threshold=0.5)
result = decision_engine.evaluate([node_result])

print(f"Action: {result.action}")
print(f"Bottleneck PPL: {result.bottleneck_perplexity}")
for field in node_result.fields:
    print(f"Field: {field.field_name} | Val: {field.extracted_value} | PPL: {field.perplexity} | Entropy: {field.semantic_entropy}")

Local VLM Testing Harness

Test uncertainty scoring locally using LM Studio, Ollama, vLLM, or MLX-VLM on a local Qwen model. The demo defaults to LM Studio and qwen/qwen3-vl-4b:

# In LM Studio: load qwen/qwen3-vl-4b, then start the local server (port 1234).
# This makes real requests; it does not fall back to mock output on failure.
python utils/demo_cat_dog_test.py

# Optional: use the deterministic mock demo without a server.
python utils/demo_cat_dog_test.py --mock

For a different local OpenAI-compatible endpoint, pass its model identifier and API base explicitly:

python utils/demo_cat_dog_test.py --api-base http://localhost:11434/v1 --model qwen2.5-vl

Documentation & Project Portal

Release files for multimodal-uncertainty 0.1.0a1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for multimodal-uncertainty 0.1.0a1
File Size Uploaded
multimodal_uncertainty-0.1.0a1.tar.gz 133.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for multimodal-uncertainty 0.1.0a1
File Interpreter ABI Platform
multimodal_uncertainty-0.1.0a1-py3-none-any.whl Python 3 none any Details

Total release size: 159.5 kB

Release files / multimodal_uncertainty-0.1.0a1.tar.gz

Download URL multimodal_uncertainty-0.1.0a1.tar.gz
Size 133.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9f6479f7acd956e71693331a79f8cfc436818c63b557da2891de38dc641f7e8a
BLAKE2b-256 checksum
How to use checksums
97b86205642de7b108ec8a13d4bd2748c3fa6d526764abcc6d09c077ba90e720
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / multimodal_uncertainty-0.1.0a1-py3-none-any.whl

Download URL multimodal_uncertainty-0.1.0a1-py3-none-any.whl
Size 25.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e7f29f7f979fe6af8f1e788badea1164d506be51106d03dd727601c1fbe892eb
BLAKE2b-256 checksum
How to use checksums
5c7d1d1b1f5a082eaf26af5cd212bb9efc72ee43bc2c658f59dd0b847073e9a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.0a1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page