From eeeab1ff27b11e6ed77d1e5d08408346a9d0eaa5 Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Thu, 20 Nov 2025 11:10:17 +0100 Subject: [PATCH 1/2] fix zero shot classification output parsing --- src/huggingface_hub/inference/_client.py | 12 ++---------- .../inference/_generated/_async_client.py | 5 +---- 2 files changed, 3 insertions(+), 14 deletions(-) diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index 56ca203779..c86253deaa 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -101,12 +101,7 @@ ZeroShotImageClassificationOutputElement, ) from huggingface_hub.inference._providers import PROVIDER_OR_POLICY_T, get_provider_helper -from huggingface_hub.utils import ( - build_hf_headers, - get_session, - hf_raise_for_status, - validate_hf_hub_args, -) +from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status, validate_hf_hub_args from huggingface_hub.utils._auth import get_token @@ -3196,10 +3191,7 @@ def zero_shot_classification( ) response = self._inner_post(request_parameters) output = _bytes_to_dict(response) - return [ - ZeroShotClassificationOutputElement.parse_obj_as_instance({"label": label, "score": score}) - for label, score in zip(output["labels"], output["scores"]) - ] + return ZeroShotClassificationOutputElement.parse_obj_as_list(output) def zero_shot_image_classification( self, diff --git a/src/huggingface_hub/inference/_generated/_async_client.py b/src/huggingface_hub/inference/_generated/_async_client.py index 080c3fd8e5..feab3a230e 100644 --- a/src/huggingface_hub/inference/_generated/_async_client.py +++ b/src/huggingface_hub/inference/_generated/_async_client.py @@ -3246,10 +3246,7 @@ async def zero_shot_classification( ) response = await self._inner_post(request_parameters) output = _bytes_to_dict(response) - return [ - ZeroShotClassificationOutputElement.parse_obj_as_instance({"label": label, "score": score}) - for label, score in zip(output["labels"], output["scores"]) - ] + return ZeroShotClassificationOutputElement.parse_obj_as_list(output) async def zero_shot_image_classification( self, From 9c603b075ba541d73e03615199bd218b7e96256f Mon Sep 17 00:00:00 2001 From: Celina Hanouti Date: Thu, 20 Nov 2025 11:11:41 +0100 Subject: [PATCH 2/2] nit --- src/huggingface_hub/inference/_client.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/huggingface_hub/inference/_client.py b/src/huggingface_hub/inference/_client.py index c86253deaa..791259e039 100644 --- a/src/huggingface_hub/inference/_client.py +++ b/src/huggingface_hub/inference/_client.py @@ -101,7 +101,12 @@ ZeroShotImageClassificationOutputElement, ) from huggingface_hub.inference._providers import PROVIDER_OR_POLICY_T, get_provider_helper -from huggingface_hub.utils import build_hf_headers, get_session, hf_raise_for_status, validate_hf_hub_args +from huggingface_hub.utils import ( + build_hf_headers, + get_session, + hf_raise_for_status, + validate_hf_hub_args, +) from huggingface_hub.utils._auth import get_token