docling-project/docling · error · TypeError
Unsupported score value type: {type(value)!r}
Error message
Unsupported score value type: {type(value)!r} What it means
Raised as TypeError by HfVisionModelMixin._as_float when the score value is neither a Python Real (int/float), a numpy ndarray, nor a torch Tensor. The converter only accepts those three shapes of scalar-like values.
Source
Thrown at docling/models/inference_engines/common/hf_vision_base.py:133
return float(value)
if isinstance(value, np.ndarray):
if value.size != 1:
raise TypeError(
f"Expected scalar-like ndarray with size 1, got shape={value.shape}"
)
return float(value.reshape(-1)[0])
import torch
if isinstance(value, torch.Tensor):
if value.numel() != 1:
raise TypeError(
f"Expected scalar-like tensor with one element, got shape={tuple(value.shape)}"
)
return float(value.item())
raise TypeError(f"Unsupported score value type: {type(value)!r}")
@staticmethod
def _as_int(value: Any) -> int:
if isinstance(value, Integral):
return int(value)
if isinstance(value, np.ndarray):
if value.size != 1:
raise TypeError(
f"Expected scalar-like ndarray with size 1, got shape={value.shape}"
)
return int(value.reshape(-1)[0])
import torch
if isinstance(value, torch.Tensor):
if value.numel() != 1:
raise TypeError(View on GitHub (pinned to 61d76f1ff3)
Solutions
- Convert to float before passing: float(value) for lists of length 1, or index element [0].
- Convert third-party tensors to numpy first (value.numpy()).
- Keep your post-processor emitting only Python scalars, np.ndarray size-1, or torch.Tensor numel-1 values.
Example fix
# before conf = model._as_float([0.93]) # list -> TypeError # after conf = model._as_float(0.93) # or float(scores[i])
Defensive patterns
Strategy: validation
Validate before calling
import numbers
import numpy as np
ok = isinstance(value, numbers.Real) or isinstance(value, np.ndarray) or _is_torch_tensor(value)
assert ok, f'unsupported score type {type(value)!r}' Type guard
import numbers
import numpy as np
def is_convertible_score(value) -> bool:
if isinstance(value, (numbers.Real, np.ndarray)):
return True
try:
import torch
return torch.is_tensor(value)
except ImportError:
return False Prevention
- Normalize scores to plain Python floats right after inference.
- Convert third-party tensors to numpy at the boundary.
- Never pass raw containers (lists/dicts) into result construction.
When it happens
Trigger: Passing e.g. a Python list, dict, string, or a third-party array type (jax, tf.Tensor) as a score value.
Common situations: Swapping inference backends so outputs arrive as an unsupported container; test fixtures injecting plain lists as fake scores.
Related errors
- Expected scalar-like ndarray with size 1, got shape={value.s
- Expected scalar-like tensor with one element, got shape={tup
- Unsupported label value type: {type(value)!r}
- Unsupported input type: {type(self.path_or_stream)}
- Unexpected: {type(self.path_or_stream)=}
AI-assisted analysis of docling-project/docling@61d76f1ff3 (2026-08-14).
Data as JSON: /api/errors/7d4e635edb5ac12d.
Report an issue: GitHub.