+
    œ°³jC  ã                   óÜ   € ^ RI t ^ RIt^ RIt^RIHt ^RIHtHtH	t	 ^RI
HtHtHtHtHt ]! 4       '       d   ^ RIt^RIHtHt  ! R R]4      t]! ]! RR	7      4       ! R
 R]4      4       tR# )é    N)ÚGenerationConfig)Úadd_end_docstringsÚis_torch_availableÚrequires_backends)ÚArgumentHandlerÚDatasetÚPipelineÚPipelineExceptionÚbuild_pipeline_init_args)Ú,MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMESÚ0MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMESc                   ó.   a € ] tR t^t o RtRR ltRtV tR# )Ú%TableQuestionAnsweringArgumentHandlerz:
Handles arguments for the TableQuestionAnsweringPipeline
Nc                óì  € \        V R 4       ^ RIpVf   \        R4      hVEfj   \        V\        4      '       d,   VP                  R4      e   VP                  R4      e   V.pEM/\        V\        4      '       d»   \        V4      ^ 8”  d«   \        ;QJ d    R V 4       F  '       d   K   RM	  RM! R V 4       4      '       g   \        RR	 V 4        24      hV^ ,          P                  R4      e   V^ ,          P                  R4      e   TpMƒ\        R
V^ ,          P                  4        R24      h\        e   \        V\        4      '       g!   \        V\        P                  4      '       d   V# \        R\        V4       R24      hRVRV/.pV FY  p\        VR,          VP                  4      '       d   K(  VR,          f   \        R4      hVP                  VR,          4      VR&   K[  	  V# )ÚpandasNz(Keyword argument `table` cannot be None.ÚqueryÚtablec              3   óB   "  € T F  p\        V\        4      x € K  	  R # 5i©N)Ú
isinstanceÚdict©Ú.0Úds   & Úp/home/luca/screen-checking/.venv/lib/python3.14/site-packages/transformers/pipelines/table_question_answering.pyÚ	<genexpr>ÚATableQuestionAnsweringArgumentHandler.__call__.<locals>.<genexpr>-   s   é € Ð>¹°1œ: a¬×.Ð.»ùs   ‚FTz:Keyword argument `table` should be a list of dict, but is c              3   ó8   "  € T F  p\        V4      x € K  	  R # 5ir   )Útyper   s   & r   r   r   /   s   é € ÐUmÑglÐbcÔVZÐ[\×V]ÐV]Óglùs   ‚z‹If keyword argument `table` is a list of dictionaries, each dictionary should have a `table` and `query` key, but only dictionary has keys z `table` and `query` keys.zZInvalid input. Keyword argument `table` should be either of type `dict` or `list`, but is Ú)zTable cannot be None.)r   r   Ú
ValueErrorr   r   ÚgetÚlistÚlenÚallÚkeysr   ÚtypesÚGeneratorTyper   Ú	DataFrame)Úselfr   r   ÚkwargsÚpdÚtqa_pipeline_inputsÚtqa_pipeline_inputs   &&&,   r   Ú__call__Ú.TableQuestionAnsweringArgumentHandler.__call__   sÈ  € ô 	˜$ Ô)ÛàŠ=ÜÐGÓHÐHØ‹]Ü˜%¤×&Ò&¨5¯9©9°WÓ+=Ò+IÈeÏiÉiÐX_ÓN`ÒNlØ', gÒ#Ü˜E¤4×(Ò(¬S°«Z¸!¬^ß“sÑ>¹Ó>—s—s’sÑ>¹Ó>×>Ò>Ü$ØTÑUmÑglÓUmÐTnÐoóð ð ˜•8—<‘< Ó(Ò4¸¸q½¿¹ÀgÓ9NÒ9ZØ*/Ñ'ä$ðJØJOÐPQÍ(Ï-É-Ë/ÐIZÐZtðvóð ô Ò$¬°E¼7×)CÒ)CÄzÐRWÔY^×YlÑYl×GmÒGmØ�ä ðÜ˜u›+˜ að)óð ð
 %,¨U°G¸UÐ#CÐ"DÐã"5ÐÜÐ0°Õ9¸2¿<¹<×HÔHØ% gÕ.Ò6Ü$Ð%<Ó=Ð=à.0¯l©lÐ;MÈgÕ;VÓ.WÐ" 7Ó+ñ #6ð #Ð"ó    © )NN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r/   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r   r      s   ø‡ € ñ÷-#ò -#r1   r   T)Úhas_tokenizerc                   ó¬   a a€ ] tR t^Mt oRtRtRtRtRtRt	Rt
]! RR7      t]! 4       3V 3R lltR tR	 tV 3R
 ltRR ltRR ltRR ltR tRtVtV ;t# )ÚTableQuestionAnsweringPipelineah  
Table Question Answering pipeline using a `ModelForTableQuestionAnswering`. This pipeline is only available in
PyTorch.

Unless the model you're using explicitly sets these generation parameters in its configuration files
(`generation_config.json`), the following default values will be used:
- max_new_tokens: 256

Example:

```python
>>> from transformers import pipeline

>>> oracle = pipeline(model="google/tapas-base-finetuned-wtq")
>>> table = {
...     "Repository": ["Transformers", "Datasets", "Tokenizers"],
...     "Stars": ["36542", "4512", "3934"],
...     "Contributors": ["651", "77", "34"],
...     "Programming language": ["Python", "Python", "Rust, Python and NodeJS"],
... }
>>> oracle(query="How many stars does the transformers repository have?", table=table)
{'answer': 'AVERAGE > 36542', 'coordinates': [(0, 1)], 'cells': ['36542'], 'aggregator': 'AVERAGE'}
```

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

This tabular question answering pipeline can currently be loaded from [`pipeline`] using the following task
identifier: `"table-question-answering"`.

The models that this pipeline can use are models that have been fine-tuned on a tabular question answering task.
See the up-to-date list of available models on
[huggingface.co/models](https://huggingface.co/models?filter=table-question-answering).
ztable,queryTFé   )Úmax_new_tokensc                ó´  <€ \         SV `  ! R/ VB  Wn        \        P                  ! 4       pVP                  \        4       V P                  V4       \        V P                  P                  R R4      ;'       d"    \        V P                  P                  RR4      V n        \        V P                  P                  R 4      '       d
   RV n        R# RV n        R# )Úaggregation_labelsNÚnum_aggregation_labelsÚtapasr2   )ÚsuperÚ__init__Ú_args_parserr   ÚcopyÚupdater   Úcheck_model_typeÚgetattrÚmodelÚconfigÚ	aggregateÚhasattrr   )r*   Úargs_parserr+   ÚmappingÚ	__class__s   &&, €r   rE   Ú'TableQuestionAnsweringPipeline.__init__}   s©   ø€ Ü‰ÒÑ"˜6Ò"Ø'ÔäB×GÒGÓIˆØ�‰ÔCÔDØ×Ñ˜gÔ&ä  §¡×!2Ñ!2Ð4HÈ$ÓO÷ 
ð 
ÔT[Ø�J‰J×ÑÐ7¸óU
ˆŒô  ' t§z¡z×'8Ñ'8Ð:N×OÒO�GˆŽ	ÐUYˆŽ	r1   c                ó&   € V P                   ! R/ VB # )Nr2   )rK   )r*   Úinputss   &,r   Úbatch_inferenceÚ.TableQuestionAnsweringPipeline.batch_inferenceŠ   s   € Ø�zŠzÑ#˜FÑ#Ð#r1   c           	     ó	  € . p. pRpVR,          P                   ^ ,          pVR,          P                  V P                  4      pVR,          P                  V P                  4      pVR,          P                  V P                  4      pRp	\        V4       EF’  p
VEeN   V	R,          p\        P
                  ! VP                  4       P                  4       4      pWŠ,          p	\        VP                   ^ ,          4       F›  pV	R	,          P                  4       V,          pV	R
,          P                  4       V,          ^,
          pV	R,          P                  4       V,          ^,
          pV^ 8¼  g   Kt  V^ 8¼  g   K}  V^8X  g   K†  \        WOV3,          4      WÍ&   K�  	  \        P                  ! V4      P                  \        P                  4      P                  V P                  4      V	R&   Wj,          pWz,          pWŠ,          p	V P                  VP                  ^ 4      VP                  ^ 4      V	P                  ^ 4      R7      pVP                   pV P"                  '       d   VP%                  VP&                  4       VP%                  V4       \        P(                  P+                  VR7      pVP,                  VP                  \        P.                  4      P                  VP,                  P                  4      ,          p\0        P2                  ! \4        4      p\7        VP9                  4       P                  4       4       F£  w  ppV	R	,          P                  4       V,          pV	R
,          P                  4       V,          ^,
          pV	R,          P                  4       V,          ^,
          pV^ 8¼  g   Kw  V^ 8¼  g   K€  V^8X  g   K‰  VVV3,          P%                  V4       K¥  	  V Uu/ uF2  pV\        P:                  ! VV,          4      P=                  4       R8„  bK4  	  ppEK•  	  \        P>                  ! \A        V4      ^ 4      pV P"                  '       g   V3# V\        P>                  ! \A        V4      ^ 4      3# u upi )z�
Inference used for models that need to process sequences in a sequential fashion, like the SQA models which
handle conversational query related to a table.
NÚ	input_idsÚattention_maskÚtoken_type_ids)rX   rY   rZ   )Úlogitsg      à?)ºNNNé   )r\   r   )r\   é   )r\   é   )!ÚshapeÚtoÚdeviceÚrangeÚnpÚ
zeros_likeÚcpuÚnumpyÚtolistÚintÚtorchÚ
from_numpyr   ÚlongrK   Ú	unsqueezer[   rM   ÚappendÚlogits_aggregationÚdistributionsÚ	BernoulliÚprobsÚfloat32ÚcollectionsÚdefaultdictr#   Ú	enumerateÚsqueezeÚarrayÚmeanÚcatÚtuple)r*   rT   Ú
all_logitsÚall_aggregationsÚprev_answersÚ
batch_sizerX   rY   rZ   Útoken_type_ids_exampleÚindexÚprev_labels_exampleÚmodel_labelsÚiÚ
segment_idÚcol_idÚrow_idÚinput_ids_exampleÚattention_mask_exampleÚoutputsr[   Údist_per_tokenÚprobabilitiesÚcoords_to_probsÚpÚcolÚrowÚkeyÚlogits_batchs   &,                           r   Úsequential_inferenceÚ3TableQuestionAnsweringPipeline.sequential_inference�   s¸  € ð
 ˆ
ØÐØˆØ˜KÕ(×.Ñ.¨qÕ1ˆ
à˜;Õ'×*Ñ*¨4¯;©;Ó7ˆ	ØÐ 0Õ1×4Ñ4°T·[±[ÓAˆØÐ 0Õ1×4Ñ4°T·[±[ÓAˆØ!%Ðä˜:×&ˆEð Ó'Ø&<¸TÕ&BÐ#Ü!Ÿ}š}Ð-@×-DÑ-DÓ-F×-LÑ-LÓ-NÓO�à)7Õ)>Ð&Ü˜|×1Ñ1°!Õ4Ö5�AØ!7¸Õ!=×!DÑ!DÓ!FÀqÕ!I�JØ3°DÕ9×@Ñ@ÓBÀ1ÕEÈÕI�FØ3°DÕ9×@Ñ@ÓBÀ1ÕEÈÕI�Fà –{ v°¦{°zÀQ¶Ü*-¨lÀFÐ;KÕ.LÓ*M˜›ñ 6ô 05×/?Ò/?ÀÓ/M×/RÑ/RÔSX×S]ÑS]Ó/^×/aÑ/aÐbf×bmÑbmÓ/nÐ& tÑ,à )Õ 0ÐØ%3Õ%:Ð"Ø%3Õ%:Ð"Ø—j‘jØ+×5Ñ5°aÓ8Ø5×?Ñ?ÀÓBØ5×?Ñ?ÀÓBð !ó ˆGð
 —^‘^ˆFà�~�~ˆ~Ø ×'Ñ'¨×(BÑ(BÔCà×Ñ˜fÔ%ä"×0Ñ0×:Ñ:À&Ð:ÓIˆNØ*×0Ñ0Ð3I×3NÑ3NÌuÏ}É}Ó3]×3`Ñ3`Ø×$Ñ$×+Ñ+ó4õ ˆMô *×5Ò5´dÓ;ˆOÜ! -×"7Ñ"7Ó"9×"@Ñ"@Ó"BÖC‘��1Ø3°DÕ9×@Ñ@ÓBÀ1ÕE�
Ø,¨TÕ2×9Ñ9Ó;¸AÕ>ÀÕB�Ø,¨TÕ2×9Ñ9Ó;¸AÕ>ÀÕB�Ø˜!–8  q¦¨Z¸1®_Ø# S¨# JÕ/×6Ñ6°qÖ9ñ Dñ YhÓhÑXgÐQT˜C¤§¢¨/¸#Õ*>Ó!?×!DÑ!DÓ!FÈÑ!LÒLÑXgˆLÐhŠLñ] 'ô` —y’y¤ zÓ!2°AÓ6ˆà&*§n§n n�ˆÐo¸<ÌÏÊÔSXÐYiÓSjÐlmÓInÐ:oÐoùò	 is   Ï,8Rc                ó€   <€ V P                   ! V/ VB p\        SV `  ! V3/ VB p\        V4      ^8X  d
   V^ ,          # V# )a2  
Answers queries according to a table. The pipeline accepts several types of inputs which are detailed below:

- `pipeline(table, query)`
- `pipeline(table, [query])`
- `pipeline(table=table, query=query)`
- `pipeline(table=table, query=[query])`
- `pipeline({"table": table, "query": query})`
- `pipeline({"table": table, "query": [query]})`
- `pipeline([{"table": table, "query": query}, {"table": table, "query": query}])`

The `table` argument should be a dict or a DataFrame built from that dict, containing the whole table:

Example:

```python
data = {
    "actors": ["brad pitt", "leonardo di caprio", "george clooney"],
    "age": ["56", "45", "59"],
    "number of movies": ["87", "53", "69"],
    "date of birth": ["7 february 1967", "10 june 1996", "28 november 1967"],
}
```

This dictionary can be passed in as such, or can be converted to a pandas DataFrame:

Example:

```python
import pandas as pd

table = pd.DataFrame.from_dict(data)
```

Args:
    table (`pd.DataFrame` or `Dict`):
        Pandas DataFrame or dictionary that will be converted to a DataFrame containing all the table values.
        See above for an example of dictionary.
    query (`str` or `list[str]`):
        Query or list of queries that will be sent to the model alongside the table.
    sequential (`bool`, *optional*, defaults to `False`):
        Whether to do inference sequentially or as a batch. Batching is faster, but models like SQA require the
        inference to be done sequentially to extract relations within sequences, given their conversational
        nature.
    padding (`bool`, `str` or [`~utils.PaddingStrategy`], *optional*, defaults to `False`):
        Activates and controls padding. Accepts the following values:

        - `True` or `'longest'`: Pad to the longest sequence in the batch (or no padding if only a single
          sequence if provided).
        - `'max_length'`: Pad to a maximum length specified with the argument `max_length` or to the maximum
          acceptable input length for the model if that argument is not provided.
        - `False` or `'do_not_pad'` (default): No padding (i.e., can output a batch with sequences of different
          lengths).

    truncation (`bool`, `str` or [`TapasTruncationStrategy`], *optional*, defaults to `False`):
        Activates and controls truncation. Accepts the following values:

        - `True` or `'drop_rows_to_fit'`: Truncate to a maximum length specified with the argument `max_length`
          or to the maximum acceptable input length for the model if that argument is not provided. This will
          truncate row by row, removing rows from the table.
        - `False` or `'do_not_truncate'` (default): No truncation (i.e., can output batch with sequence lengths
          greater than the model maximum admissible input size).


Return:
    A dictionary or a list of dictionaries containing results: Each result is a dictionary with the following
    keys:

    - **answer** (`str`) -- The answer of the query given the table. If there is an aggregator, the answer will
      be preceded by `AGGREGATOR >`.
    - **coordinates** (`list[tuple[int, int]]`) -- Coordinates of the cells of the answers.
    - **cells** (`list[str]`) -- List of strings made up of the answer cell values.
    - **aggregator** (`str`) -- If the model has an aggregator, this returns the aggregator.
)rF   rD   r/   r$   )r*   Úargsr+   Úpipeline_inputsÚresultsrQ   s   &*,  €r   r/   Ú'TableQuestionAnsweringPipeline.__call__Ð   sJ   ø€ ðV ×+Ò+¨TÐ<°VÑ<ˆä‘'Ò" ?Ñ=°fÑ=ˆÜˆw‹<˜1ÔØ˜1•:ÐØˆr1   c                óØ   € / pVe   W%R&   Ve   W5R&   / pVe   WR&   \        V RR 4      e   V P                  VR&   \        V RR 4      e   V P                  VR&   V P                  VR&   WV/ 3# )NÚpaddingÚ
truncationÚ
sequentialÚassistant_modelÚassistant_tokenizerÚ	tokenizer)rJ   rž   r    rŸ   )r*   r�   r›   rœ   r+   Úpreprocess_paramsÚforward_paramss   &&&&,  r   Ú_sanitize_parametersÚ3TableQuestionAnsweringPipeline._sanitize_parameters"  s’   € ØÐØÒØ+2˜iÑ(ØÒ!Ø.8˜lÑ+àˆØÒ!Ø+5˜<Ñ(ä�4Ð*¨DÓ1Ò=Ø04×0DÑ0DˆNÐ,Ñ-Ü�4Ð.°Ó5ÒAØ*.¯.©.ˆN˜;Ñ'Ø48×4LÑ4LˆNÐ0Ñ1à °"Ð4Ð4r1   c                óò   € Vf   V P                   R8X  d   RpMRpVR,          VR,          rTVP                  '       d   \        R4      hVe   VR8X  d   \        R4      hV P                  WER	W2R
7      pWFR&   V# )NrC   Údrop_rows_to_fitÚdo_not_truncater   r   ztable is emptyÚ zquery is emptyÚpt)Úreturn_tensorsrœ   r›   )r   Úemptyr!   r    )r*   Úpipeline_inputr›   rœ   r   r   rT   s   &&&&   r   Ú
preprocessÚ)TableQuestionAnsweringPipeline.preprocess5  s{   € ØÒØ�y‰y˜GÔ#Ø/‘
à.�
à% gÕ.°¸wÕ0GˆuØ�;�;ˆ;ÜÐ-Ó.Ð.ØŠ=˜E RœKÜÐ-Ó.Ð.Ø—‘ ¸TÈj�ÓjˆØˆw‰Øˆr1   c                ó  € VP                  R 4      pV P                  R8X  d/   V'       d   V P                  ! R/ VB pMGV P                  ! R/ VB pM4RV9  d   V P                  VR&   V P
                  P                  ! R/ VBVB pRVR VRV/pV# )r   rC   Úgeneration_configÚmodel_inputsrŠ   r2   )Úpopr   r“   rU   r°   rK   Úgenerate)r*   r±   r�   Úgenerate_kwargsr   rŠ   Úmodel_outputss   &&&,   r   Ú_forwardÚ'TableQuestionAnsweringPipeline._forwardE  s—   € Ø× Ñ  Ó)ˆà�9‰9˜ÔßØ×3Ò3ÑC°lÑC‘à×.Ò.Ñ>°Ñ>‘ð #¨/Ô9Ø7;×7MÑ7M�Ð 3Ñ4à—j‘j×)Ò)ÑL¨LÐL¸OÑLˆGØ'¨°wÀÀyÐRYÐZˆØÐr1   c                ó  € VR ,          pVR,          pVR,          pV P                   R8X  Edó   V P                  '       dÄ   VR,          w  rVV P                  P                  W%V4      pVw  r‰\	        V	4       U
Uu/ uF,  w  r«W P
                  P                  P                  V,          bK.  	  pp
pV P
                  P                  P                  p\	        V	4       U
Uu/ uF  w  r«W½8w  g   K  W¬V
,          R,           bK  	  pp
pM1V^ ,          pV P                  P                  W%4      pV^ ,          p/ p/ p. p\	        V4       F©  w  ppV Uu. uF  pVP                  V,          NK  	  ppVP                  VR4      pVP                  VR4      pRVRP                  V4      ,           R	TR
V Uu. uF  pVP                  V,          NK  	  up/pV'       d   VVR&   VP                  V4       K«  	  \        X4      ^ 8X  d"   \        RV P
                  P                  R4      hM.V P                  P!                  VRR7       Uu. uF  pRV/NK	  	  pp\        V4      ^8”  d   V# V^ ,          # u upp
i u upp
i u upi u upi u upi )r±   r   rŠ   rC   :Nr_   Nz > r¨   Úanswerz, ÚcoordinatesÚcellsÚ
aggregatorzTable question answeringzEmpty answerT)Úskip_special_tokens)r   rM   r    Úconvert_logits_to_predictionsrv   rK   rL   rA   Úno_aggregation_label_indexÚiatr"   Újoinrn   r$   r
   Úname_or_pathÚbatch_decode)r*   rµ   rT   r   rŠ   r[   Ú
logits_aggÚpredictionsÚanswer_coordinates_batchÚagg_predictionsr„   ÚpredÚaggregatorsÚno_agg_label_indexÚaggregators_prefixÚanswersr�   rº   Ú
coordinater»   r¼   Úaggregator_prefixr¹   s   &&                     r   ÚpostprocessÚ*TableQuestionAnsweringPipeline.postprocessV  sp  € Ø˜~Õ.ˆØ˜gÕ&ˆØ 	Õ*ˆØ�9‰9˜ÕØ�~�~ˆ~Ø%,¨R¥[Ñ"�Ø"Ÿn™n×JÑJÈ6Ð[eÓf�Ø<GÑ9Ð(Ü\eÐfuÔ\vÔwÑ\vÑQXÐQR˜q§*¡*×"3Ñ"3×"FÑ"FÀtÕ"LÒLÑ\v�Ñwà%)§Z¡Z×%6Ñ%6×%QÑ%QÐ"ä=FÀÔ=Wô&Ù=W±'°!Ð[_Ñ[uÔ-�A 1•~¨Õ-Ò-Ñ=Wð #ñ &Ð"ð ! ��Ø"Ÿn™n×JÑJÈ6ÓZ�Ø+6°q­>Ð(Ø �Ø%'Ð"ØˆGÜ&/Ð0HÖ&IÑ"��{ÙALÓMÁ°:˜Ÿ™ :×.Ð.Á�ÐMØ(Ÿ_™_¨U°BÓ7�
Ø$6×$:Ñ$:¸5À"Ó$EÐ!àÐ/°$·)±)¸EÓ2BÕBØ! ;ØÁkÓRÁk¸
˜eŸi™i¨
×3Ð3ÁkÑRð�÷
 Ø+5�F˜<Ñ(à—‘˜vÖ&ñ 'Jô �6‹{˜aÔÜ'Ð(BÀDÇJÁJ×D[ÑD[Ð]kÓlÐlð  ð 9=¿¹×8SÑ8SÐT[ÐquÐ8SÔ8vÓwÑ8v¨f˜ &Ó)Ñ8vˆGÐwä˜g›,¨Ô*ˆwÐ:°¸µ
Ð:ùó? xùó&ùò Nùò Sùò xs$   Á92I)Ã
I/Ã+I/ÅI5Æ,I:È?I?)rF   rM   r   )NNN)TN)F)r3   r4   r5   r6   r7   Údefault_input_namesÚ_pipeline_calls_generateÚ_load_processorÚ_load_image_processorÚ_load_feature_extractorÚ_load_tokenizerr   Ú_default_generation_configr   rE   rU   r“   r/   r£   r­   r¶   rÏ   r8   r9   Ú__classcell__)rQ   r:   s   @@r   r=   r=   M   sy   ù‡ € ñ ðD (Ðà#ÐØ€OØ!ÐØ#ÐØ€Oá!1Øô"Ðñ $IÓ#J÷ Zò$òApõFPôd5ô&ô ÷"(;ò (;r1   r=   )rt   r'   rg   rd   Ú
generationr   Úutilsr   r   r   Úbaser   r   r	   r
   r   rj   Úmodels.auto.modeling_autor   r   r   r=   r2   r1   r   Ú<module>rÝ      sn   ðÛ Û ã å )÷ñ ÷
 bÕ añ ×ÒÛ÷ô2#¨Oô 2#ñj Ñ,¸4Ô@ÓAôp; Xó p;ó Bòp;r1   