+
    œ°³jÈ.  ã                   óº   € ^ RI t ^ RIt^RIHt ^RIHtHt ^RIH	t	H
t
Ht ]P                  ! ]4      t ! R R]	4      t]! ]! RR7      4       ! R	 R
]
4      4       tR# )é    N)ÚTruncationStrategy)Úadd_end_docstringsÚlogging)ÚArgumentHandlerÚChunkPipelineÚbuild_pipeline_init_argsc                   ó0   a € ] tR t^t o RtR tR tRtV tR# )Ú%ZeroShotClassificationArgumentHandlerz}
Handles arguments for zero-shot for text classification by turning each possible label into an NLI
premise/hypothesis pair.
c                óÆ   € \        V\        4      '       dF   VP                  R 4       Uu. uF*  q"P                  4       '       g   K  VP                  4       NK,  	  ppV# u upi )Ú,)Ú
isinstanceÚstrÚsplitÚstrip)ÚselfÚlabelsÚlabels   && Úp/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/pipelines/zero_shot_classification.pyÚ_parse_labelsÚ3ZeroShotClassificationArgumentHandler._parse_labels   sG   € Ü�fœc×"Ò"Ø17·±¸cÔ1BÓTÑ1B¨ÇkÁkÇm”m�e—k‘k–mÑ1BˆFÐTØˆùò Us   ªAÁAc           
     ój  € \        V4      ^ 8X  g   \        V4      ^ 8X  d   \        R4      hVP                  V^ ,          4      V8X  d   \        RV R24      h\        V\        4      '       d   V.p. pV F4  pTP                  V Uu. uF  qeVP                  V4      .NK  	  up4       K6  	  WA3# u upi )r   z>You must include at least one label and at least one sequence.z"The provided hypothesis_template "z•" was not able to be formatted with the target labels. Make sure the passed template includes formatting syntax such as {} where the label should go.)ÚlenÚ
ValueErrorÚformatr   r   Úextend)r   Ú	sequencesr   Úhypothesis_templateÚsequence_pairsÚsequencer   s   &&&&   r   Ú__call__Ú.ZeroShotClassificationArgumentHandler.__call__   sÆ   € Üˆv‹;˜!Ôœs 9›~°Ô2ÜÐ]Ó^Ð^Ø×%Ñ% f¨Q¥iÓ0Ð4GÔGÜØ4Ð5HÐ4Ið Jqð qóð ô
 �i¤×%Ò%Ø"˜ˆIàˆÛ!ˆHØ×!Ñ!Ñ^dÓ"eÑ^dÐUZÐ.A×.HÑ.HÈÓ.OÓ#PÑ^dÑ"eÖfñ "ð Ð(Ð(ùò #fs   ÂB0
© N)	Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r
   r
      s   ø‡ € ñò
÷
)ð )ó    r
   T)Úhas_tokenizerc                   óÂ   a a€ ] tR t^+t oRtRtRtRtRt]	! 4       3V 3R llt
]R 4       tRR]P                  3R ltR tV3R lV 3R	 lltRR
 ltR tRR ltRtVtV ;t# )ÚZeroShotClassificationPipelinea£  
NLI-based zero-shot classification pipeline using a `ModelForSequenceClassification` trained on NLI (natural
language inference) tasks. Equivalent of `text-classification` pipelines, but these models don't require a
hardcoded number of potential classes, they can be chosen at runtime. It usually means it's slower but it is
**much** more flexible.

Any combination of sequences and labels can be passed and each combination will be posed as a premise/hypothesis
pair and passed to the pretrained model. Then, the logit for *entailment* is taken as the logit for the candidate
label being valid. Any NLI model can be used, but the id of the *entailment* label must be included in the model
config's :attr:*~transformers.PreTrainedConfig.label2id*.

Example:

```python
>>> from transformers import pipeline

>>> oracle = pipeline(model="facebook/bart-large-mnli")
>>> oracle(
...     "I have a problem with my iphone that needs to be resolved asap!!",
...     candidate_labels=["urgent", "not urgent", "phone", "tablet", "computer"],
... )
{'sequence': 'I have a problem with my iphone that needs to be resolved asap!!', 'labels': ['urgent', 'phone', 'computer', 'not urgent', 'tablet'], 'scores': [0.504, 0.479, 0.013, 0.003, 0.002]}

>>> oracle(
...     "I have a problem with my iphone that needs to be resolved asap!!",
...     candidate_labels=["english", "german"],
... )
{'sequence': 'I have a problem with my iphone that needs to be resolved asap!!', 'labels': ['english', 'german'], 'scores': [0.814, 0.186]}
```

Learn more about the basics of using a pipeline in the [pipeline tutorial](../pipeline_tutorial)

This NLI pipeline can currently be loaded from [`pipeline`] using the following task identifier:
`"zero-shot-classification"`.

The models that this pipeline can use are models that have been fine-tuned on an NLI task. See the up-to-date list
of available models on [huggingface.co/models](https://huggingface.co/models?search=nli).
FTc                ó„   <€ Wn         \        SV `  ! R/ VB  V P                  R8X  d   \        P                  R4       R# R# )é   z¼Failed to determine 'entailment' label id from the label2id mapping in the model config. Setting to -1. Define a descriptive label2id mapping in the model config to ensure correct outputs.Nr"   éÿÿÿÿ)Ú_args_parserÚsuperÚ__init__Úentailment_idÚloggerÚwarning)r   Úargs_parserÚkwargsÚ	__class__s   &&,€r   r4   Ú'ZeroShotClassificationPipeline.__init__Y   s>   ø€ Ø'ÔÜ‰ÒÑ"˜6Ò"Ø×Ñ Ô#Ü�N‰Nðköñ $r+   c                óÆ   € V P                   P                  P                  P                  4        F.  w  rVP	                  4       P                  R 4      '       g   K,  Vu # 	  R# )Úentailr1   )ÚmodelÚconfigÚlabel2idÚitemsÚlowerÚ
startswith)r   r   Úinds   &  r   r5   Ú,ZeroShotClassificationPipeline.entailment_idb   sJ   € àŸ*™*×+Ñ+×4Ñ4×:Ñ:Ö<‰JˆEØ�{‰{‹}×'Ñ'¨×1Ô1Ø’
ñ =ð ˆ	r+   c           	     óz  € RpV P                   P                  f;   \        P                  R4       V P                   P                  V P                   n         V P                  VVVVVR7      pV#   \
         dB   pR\        T4      9   d+   T P                  TTTT\        P                  R7      p Rp?T# ThRp?ii ; i)zU
Parse arguments and tokenize only_first so that hypothesis (label) is not truncated
ÚptNzfTokenizer was not supporting padding necessary for zero-shot, attempting to use  `pad_token=eos_token`)Úadd_special_tokensÚreturn_tensorsÚpaddingÚ
truncationz	too short)	Ú	tokenizerÚ	pad_tokenr6   ÚerrorÚ	eos_tokenÚ	Exceptionr   r   ÚDO_NOT_TRUNCATE)	r   r   rJ   rH   rK   r9   rI   ÚinputsÚes	   &&&&&,   r   Ú_parse_and_tokenizeÚ2ZeroShotClassificationPipeline._parse_and_tokenizei   sÆ   € ð ˆØ�>‰>×#Ñ#Ò+ä�L‰Lð)ôð (,§~¡~×'?Ñ'?ˆD�N‰NÔ$ð	Ø—^‘^ØØ#5Ø-ØØ%ð $ó ˆFð2 ˆøô% ô 	Øœc !›fÔ$ð Ÿ™Ø"Ø'9Ø#1Ø#Ü1×AÑAð (ó ”ð ˆð �ûð!	ús   ÁA. Á.B:Á94B5Â3B5Â5B:c                ó¸   € / pR V9   d&   V P                   P                  VR ,          4      VR &   RV9   d   VR,          VR&   / pRV9   d   VR,          VR&   V/ V3# )Úcandidate_labelsr   Úmulti_label)r2   r   )r   r9   Úpreprocess_paramsÚpostprocess_paramss   &,  r   Ú_sanitize_parametersÚ3ZeroShotClassificationPipeline._sanitize_parameters“   sz   € ØÐØ Ô'Ø48×4EÑ4E×4SÑ4SÐTZÐ[mÕTnÓ4oÐÐ0Ñ1Ø  FÔ*Ø7=Ð>SÕ7TÐÐ3Ñ4àÐØ˜FÔ"Ø06°}Õ0EÐ˜}Ñ-Ø  "Ð&8Ð8Ð8r+   c                ó@   <€ V ^8„  d   QhRS[ S[S[ ,          ,          /# )é   r   )r   Úlist)r   r*   s   "€r   Ú__annotate__Ú+ZeroShotClassificationPipeline.__annotate__Ÿ   s   ø€ ÷ +5ñ +5á™™c�•?ñ+5r+   c                ó¬   <€ \        V4      ^ 8X  d   M2\        V4      ^8X  d   RV9  d   V^ ,          VR&   M\        RV 24      h\        SV `  ! V3/ VB # )aJ  
Classify the sequence(s) given as inputs. See the [`ZeroShotClassificationPipeline`] documentation for more
information.

Args:
    sequences (`str` or `list[str]`):
        The sequence(s) to classify, will be truncated if the model input is too large.
    candidate_labels (`str` or `list[str]`):
        The set of possible class labels to classify each sequence into. Can be a single label, a string of
        comma-separated labels, or a list of labels.
    hypothesis_template (`str`, *optional*, defaults to `"This example is {}."`):
        The template used to turn each label into an NLI-style hypothesis. This template must include a {} or
        similar syntax for the candidate label to be inserted into the template. For example, the default
        template is `"This example is {}."` With the candidate label `"sports"`, this would be fed into the
        model like `"<cls> sequence to classify <sep> This example is sports . <sep>"`. The default template
        works well in many cases, but it may be worthwhile to experiment with different templates depending on
        the task setting.
    multi_label (`bool`, *optional*, defaults to `False`):
        Whether or not multiple candidate labels can be true. If `False`, the scores are normalized such that
        the sum of the label likelihoods for each sequence is 1. If `True`, the labels are considered
        independent and probabilities are normalized for each candidate by doing a softmax of the entailment
        score vs. the contradiction score.

Return:
    A `dict` or a list of `dict`: Each result comes as a dictionary with the following keys:

    - **sequence** (`str`) -- The sequence for which this is the output.
    - **labels** (`list[str]`) -- The labels sorted by order of likelihood.
    - **scores** (`list[float]`) -- The probabilities for each of the labels.
rW   z%Unable to understand extra arguments )r   r   r3   r    )r   r   Úargsr9   r:   s   &&*,€r   r    Ú'ZeroShotClassificationPipeline.__call__Ÿ   s^   ø€ ôH ˆt‹9˜Œ>ØÜ�‹Y˜!Œ^Ð 2¸&Ô @Ø)-¨a­ˆFÐ%Ò&äÐDÀTÀFÐKÓLÐLä‰wÒ 	Ñ4¨VÑ4Ð4r+   c           
   #  óæ   "  € V P                  WV4      w  rE\        \        W$4      4       F@  w  pw  rxV P                  V.4      p	R VRV^ ,          RV\	        V4      ^,
          8H  /V	Cx € KB  	  R# 5i)Úcandidate_labelr   Úis_lastN)r2   Ú	enumerateÚziprT   r   )
r   rR   rW   r   r   r   Úirf   Úsequence_pairÚmodel_inputs
   &&&&      r   Ú
preprocessÚ)ZeroShotClassificationPipeline.preprocessÌ   s„   é € Ø$(×$5Ñ$5°fÐPcÓ$dÑ!ˆä3<¼SÐAQÓ=bÖ3cÑ/ˆAÑ/�Ø×2Ñ2°M°?ÓCˆKð " ?Ø˜I a�LØ˜1¤Ð$4Ó 5¸Õ 9Ñ9ðð ð	ô ó 4dùs   ‚A/A1c                óP  € VR ,          pVR,          pV P                   P                   Uu/ uF  qDW,          bK  	  ppV P                  P                  pR\        P
                  ! V4      P                  9   d   RVR&   V P                  ! R/ VB pR VRVRVR,          /VCpV# u upi )rf   r   Ú	use_cacheFrg   r"   )rL   Úmodel_input_namesr>   ÚforwardÚinspectÚ	signatureÚ
parameters)	r   rR   rf   r   ÚkÚmodel_inputsÚmodel_forwardÚoutputsÚmodel_outputss	   &&       r   Ú_forwardÚ'ZeroShotClassificationPipeline._forwardÙ   s³   € Ø Ð!2Õ3ˆØ˜*Õ%ˆØ.2¯n©n×.NÒ.NÓOÑ.N¨˜6�9šÑ.NˆÐOàŸ
™
×*Ñ*ˆØœ'×+Ò+¨MÓ:×EÑEÔEØ(-ˆL˜Ñ%Ø—*’*Ñ,˜|Ñ,ˆð ˜Ø˜Ø�v˜iÕ(ð
ð ð	
ˆð Ðùò Ps   «B#c                ó  € V Uu. uF  q3R ,          NK  	  ppV Uu. uF  q3R,          NK  	  pp\         P                  ! V Uu. uF'  qfR,          P                  4       P                  4       NK)  	  up4      pVP                  ^ ,          p\        V4      p	W‰,          p
VP                  W©R34      pV'       g   \        V4      ^8X  dp   V P                  pV^ 8X  d   RM^ pVRWÜ.3,          p\         P                  ! V4      \         P                  ! V4      P                  RRR7      ,          pVR	,          pMWVRV P                  3,          p\         P                  ! V4      \         P                  ! V4      P                  RRR7      ,          p\        \        V^ ,          P                  4       4      4      pRV^ ,          RV Uu. uF  pVV,          NK  	  upRV^ V3,          P                  4       /# u upi u upi u upi u upi )
rf   r   Úlogits.T)Úkeepdimsr   Úscoresr1   ).r0   )ÚnpÚconcatenateÚfloatÚnumpyÚshaper   Úreshaper5   ÚexpÚsumr_   ÚreversedÚargsortÚtolist)r   rz   rX   ry   rW   r   Úoutputr~   ÚNÚnÚnum_sequencesÚreshaped_outputsr5   Úcontradiction_idÚentail_contr_logitsr€   Úentail_logitsÚtop_indsrj   s   &&&                r   ÚpostprocessÚ*ZeroShotClassificationPipeline.postprocessë   sÏ  € ÙFSÓTÁm¸7Ð$5×6Ð6ÁmÐÐTÙ8EÓF¹¨W˜Z×(Ð(¹ˆ	ÐFÜ—’ÑP]Ó ^ÑP]Àf¨Õ!1×!7Ñ!7Ó!9×!?Ñ!?Ö!AÑP]Ñ ^Ó_ˆØ�L‰L˜�OˆÜÐ Ó!ˆØ�ˆØ!Ÿ>™>¨=¸RÐ*@ÓAÐçœ#Ð.Ó/°1Ô4à ×.Ñ.ˆMØ%2°aÔ%7™r¸QÐØ"2°3Ð9IÐ8YÐ3YÕ"ZÐÜ—V’VÐ/Ó0´2·6²6Ð:MÓ3N×3RÑ3RÐSUÐ`dÐ3RÓ3eÕeˆFØ˜F•^‰Fð -¨S°$×2DÑ2DÐ-DÕEˆMÜ—V’V˜MÓ*¬R¯VªV°MÓ-B×-FÑ-FÀrÐTXÐ-FÓ-YÕYˆFäœ ¨¥×!2Ñ!2Ó!4Ó5Ó6ˆà˜	 !�Ø±HÓ=±H¨qÐ'¨×*Ð*±HÑ=Ø�f˜Q ˜[Õ)×0Ñ0Ó2ð
ð 	
ùò+ UùÚFùÚ ^ùò* >s   …G4œG9Á-G>ÇH
)r2   )NzThis example is {}.)F)r#   r$   r%   r&   r'   Ú_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr
   r4   Úpropertyr5   r   Ú
ONLY_FIRSTrT   r[   r    rm   r{   r•   r(   r)   Ú__classcell__)r:   r*   s   @@r   r.   r.   +   s|   ù‡ € ñ%ðN €OØ!ÐØ#ÐØ€Oá#HÓ#J÷ ð ñó ðð '+¸tÐPb×PmÑPmô(òT
9÷+5ó +5ôZò÷$
ô 
r+   r.   )rs   r„   r�   Útokenization_pythonr   Úutilsr   r   Úbaser   r   r   Ú
get_loggerr#   r6   r
   r.   r"   r+   r   Ú<module>r¢      s_   ðÛ ã å 4ß /ß JÑ Jð 
×	Ò	˜HÓ	%€ô)¨Oô )ñ< Ñ,¸4Ô@ÓAôY
 ]ó Y
ó BòY
r+   