Ë
    T^(h†O  ã                   óì   — d dl Z d dlZd dlZddlmZmZmZmZ ddl	m
Z
mZmZmZmZ  e«       rd dlZddlmZmZ  e«       rd dlZddlmZmZ  G d„ d	e
«      Z e ed
¬«      «       G d„ de«      «       Zy)é    Né   )Úadd_end_docstringsÚis_tf_availableÚ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_NAMES)Ú/TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING_NAMESÚ3TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING_NAMESc                   ó   — e Zd ZdZdd„Zy)Ú%TableQuestionAnsweringArgumentHandlerzB
    Handles arguments for the TableQuestionAnsweringPipeline
    Nc                 ó  — t        | d«       dd l}|€t        d«      ‚|�€t        |t        «      r&|j                  d«      �|j                  d«      �|g}nàt        |t        «      r€t        |«      dkD  rrt        d„ |D «       «      st        dd„ |D «       › �«      ‚|d   j                  d«      �|d   j                  d«      �|}npt        d	|d   j                  «       › d
�«      ‚t        �t        |t        «      st        |t        j                  «      r|S t        dt        |«      › d�«      ‚||dœg}|D ]C  }t        |d   |j                  «      rŒ|d   €t        d«      ‚|j                  |d   «      |d<   ŒE |S )NÚpandasr   z(Keyword argument `table` cannot be None.ÚqueryÚtablec              3   ó<   K  — | ]  }t        |t        «      –— Œ y ­w©N)Ú
isinstanceÚdict©Ú.0Úds     úm/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/transformers/pipelines/table_question_answering.pyú	<genexpr>zATableQuestionAnsweringArgumentHandler.__call__.<locals>.<genexpr>5   s   è ø€ Ò>°1œ: a¬×.Ñ>ùs   ‚z:Keyword argument `table` should be a list of dict, but is c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr   )Útyper   s     r   r    zATableQuestionAnsweringArgumentHandler.__call__.<locals>.<genexpr>7   s   è ø€ ÒUmÐbcÔVZÐ[\×V]ÑUmù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 ú))r   r   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__z.TableQuestionAnsweringArgumentHandler.__call__%   s©  € ô 	˜$ Ô)Ûàˆ=ÜÐGÓHÐHØ‰]Ü˜%¤Ô&¨5¯9©9°WÓ+=Ð+IÈeÏiÉiÐX_ÓN`ÐNlØ', gÑ#Ü˜E¤4Ô(¬S°«Z¸!ª^ÜÑ>¸Ô>Ô>Ü$ØTÑUmÐglÔUmÐTnÐoóð ð ˜‘8—<‘< Ó(Ð4¸¸q¹¿¹ÀgÓ9NÐ9ZØ*/Ñ'ä$ðJØJOÐPQÉ(Ï-É-Ë/ÐIZÐZtðvóð ô Ð$¬°E¼7Ô)CÄzÐRWÔY^×YlÑYlÔGmØ�ä ðÜ˜u›+˜ að)óð ð
 .3¸UÑ#CÐ"DÐà"5ò 	XÐÜÐ0°Ñ9¸2¿<¹<ÕHØ% gÑ.Ð6Ü$Ð%<Ó=Ð=à.0¯l©lÐ;MÈgÑ;VÓ.WÐ" 7Ò+ð	Xð #Ð"ó    )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   © r3   r   r   r       s   „ ñô-#r3   r   T)Úhas_tokenizerc                   óh   ‡ — e Zd ZdZdZ e«       fˆ fd„	Zd„ Zd„ Zˆ fd„Z	dd„Z
dd„Zdd	„Zd
„ Zˆ xZS )ÚTableQuestionAnsweringPipelineaý  
    Table Question Answering pipeline using a `ModelForTableQuestionAnswering`. This pipeline is only available in
    PyTorch.

    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,queryc                 ó,  •— t        ‰| �  |i |¤Ž || _        | j                  dk(  r*t	        j
                  «       }|j                  t        «       n)t        j
                  «       }|j                  t        «       | j                  |«       t        t        | j                  j                  dd «      «      xr* t        t        | j                  j                  dd «      «      | _        t!        | j                  j                  d«      rd| _        y d | _        y )NÚtfÚaggregation_labelsÚnum_aggregation_labelsÚtapas)ÚsuperÚ__init__Ú_args_parserÚ	frameworkr   ÚcopyÚupdater   r   r   Úcheck_model_typeÚboolÚgetattrÚmodelÚconfigÚ	aggregateÚhasattrr"   )r-   Úargs_parserÚargsr.   ÚmappingÚ	__class__s        €r   rB   z'TableQuestionAnsweringPipeline.__init__w   sÖ   ø€ Ü‰Ñ˜$Ð) &Ò)Ø'ˆÔà�>‰>˜TÒ!ÜI×NÑNÓPˆGØ�N‰NÔJÕKäF×KÑKÓMˆGØ�N‰NÔGÔHØ×Ñ˜gÔ&äœg d§j¡j×&7Ñ&7Ð9MÈtÓTÓUò 
ÔZ^Ü�D—J‘J×%Ñ%Ð'?ÀÓFó[
ˆŒô  ' t§z¡z×'8Ñ'8Ð:NÔO�Gˆ�	ÐUYˆ�	r3   c                 ó&   —  | j                   di |¤ŽS )Nr8   )rJ   )r-   Úinputss     r   Úbatch_inferencez.TableQuestionAnsweringPipeline.batch_inferenceˆ   s   € Øˆt�z‰zÑ#˜FÑ#Ð#r3   c           	      ó@  — | j                   dk(  �rýg }g }d}|d   j                  d   }|d   j                  | j                  «      }|d   j                  | j                  «      }|d   j                  | j                  «      }d}	t	        |«      D �]+  }
|��'|	dd…df   }t        j                  |j                  «       j                  «       «      }||
   }	t	        |j                  d   «      D ]{  }|	dd…df   j                  «       |   }|	dd…df   j                  «       |   dz
  }|	dd…d	f   j                  «       |   dz
  }|dk\  sŒ]|dk\  sŒc|dk(  sŒit        |||f   «      ||<   Œ} t        j                  |«      j                  t        j                  «      j                  | j                  «      |	dd…df<   ||
   }||
   }||
   }	| j                  |j!                  d«      |j!                  d«      |	j!                  d«      ¬
«      }|j"                  }| j$                  r|j'                  |j(                  «       |j'                  |«       t        j*                  j-                  |¬«      }|j.                  |j                  t        j0                  «      j                  |j.                  j                  «      z  }t3        j4                  t6        «      }t9        |j;                  «       j                  «       «      D ]�  \  }}|	dd…df   j                  «       |   }|	dd…df   j                  «       |   dz
  }|	dd…d	f   j                  «       |   dz
  }|dk\  sŒ`|dk\  sŒf|dk(  sŒl|||f   j'                  |«       Œƒ |D �ci c],  }|t        j<                  ||   «      j?                  «       dkD  “Œ. }}�Œ. t        j@                  tC        |«      d«      }| j$                  s|fS |t        j@                  tC        |«      d«      fS g }g }d}|d   j                  d   }|d   }|d   }|d   j                  «       }d}	t	        |«      D �]ó  }
|�Ò|	dd…df   }t        j                  |t
        jD                  ¬«      }||
   }	t	        |j                  d   «      D ]{  }|	dd…df   j                  «       |   }|	dd…df   j                  «       |   dz
  }|	dd…d	f   j                  «       |   dz
  }|dk\  sŒ]|dk\  sŒc|dk(  sŒit        |||f   «      ||<   Œ} ||	dd…df<   ||
   }||
   }||
   }	| j                  t        jF                  |d¬«      t        jF                  |d¬«      t        jF                  |	d¬«      ¬
«      }|j"                  }| j$                  r|j'                  |j(                  «       |j'                  |«       tH        jJ                  jM                  tI        jN                  |tH        j0                  «      «      tI        jN                  |tH        j0                  «      z  }t3        j4                  t6        «      }|	}	t9        tI        j:                  |«      j                  «       j                  «       «      D ]�  \  }}|	dd…df   j                  «       |   }|	dd…df   j                  «       |   dz
  }|	dd…d	f   j                  «       |   dz
  }|dk\  sŒ`|dk\  sŒf|dk(  sŒl|||f   j'                  |«       Œƒ |D �ci c],  }|t        j<                  ||   «      j?                  «       dkD  “Œ. }}�Œö tI        jP                  tC        |«      d«      }| j$                  s|fS |tI        jP                  tC        |«      d«      fS c c}w c c}w )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.
        ÚptNÚ	input_idsr   Úattention_maskÚtoken_type_idsé   r   r   )rW   rX   rY   )Úlogitsg      à?)Údtype)Úaxis))rD   ÚshapeÚtoÚdeviceÚrangeÚnpÚ
zeros_likeÚcpuÚnumpyÚtolistÚintÚtorchÚ
from_numpyr"   ÚlongrJ   Ú	unsqueezer[   rL   ÚappendÚlogits_aggregationÚdistributionsÚ	BernoulliÚprobsÚfloat32ÚcollectionsÚdefaultdictr&   Ú	enumerateÚsqueezeÚarrayÚmeanÚcatÚtupleÚint32Úexpand_dimsr=   ÚmathÚsigmoidÚcastÚconcat)r-   rS   Ú
all_logitsÚall_aggregationsÚprev_answersÚ
batch_sizerW   rX   rY   Ú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_inferencez3TableQuestionAnsweringPipeline.sequential_inference‹   s�  € ð
 �>‰>˜TÓ!ØˆJØ!ÐØˆLØ Ñ,×2Ñ2°1Ñ5ˆJà˜{Ñ+×.Ñ.¨t¯{©{Ó;ˆIØ#Ð$4Ñ5×8Ñ8¸¿¹ÓEˆNØ#Ð$4Ñ5×8Ñ8¸¿¹ÓEˆNØ%)Ð"ä˜zÓ*ó .m�ð  Ñ+Ø*@ÂÀAÀÑ*FÐ'Ü#%§=¡=Ð1D×1HÑ1HÓ1J×1PÑ1PÓ1RÓ#S�Là-;¸EÑ-BÐ*Ü" <×#5Ñ#5°aÑ#8Ó9ò R˜Ø%;ºA¸q¸DÑ%A×%HÑ%HÓ%JÈ1Ñ%M˜
Ø!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!IÈAÑ!M˜Ø!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!IÈAÑ!M˜à! Q›;¨6°Q«;¸:È»?Ü.1°,ÀÈÐ?OÑ2PÓ.Q˜L¨šOðRô 49×3CÑ3CÀLÓ3Q×3VÑ3VÔW\×WaÑWaÓ3b×3eÑ3eÐfj×fqÑfqÓ3rÐ*ª1¨a¨4Ñ0à$-¨eÑ$4Ð!Ø)7¸Ñ)>Ð&Ø)7¸Ñ)>Ð&ØŸ*™*Ø/×9Ñ9¸!Ó<Ø#9×#CÑ#CÀAÓ#FØ#9×#CÑ#CÀAÓ#Fð %ó �ð
 !Ÿ™�à—>’>Ø$×+Ñ+¨G×,FÑ,FÔGà×!Ñ! &Ô)ä!&×!4Ñ!4×!>Ñ!>ÀfÐ!>Ó!M�Ø .× 4Ñ 4Ð7M×7RÑ7RÔSX×S`ÑS`Ó7a×7dÑ7dØ"×(Ñ(×/Ñ/ó8ñ !�ô #.×"9Ñ"9¼$Ó"?�Ü% m×&;Ñ&;Ó&=×&DÑ&DÓ&FÓGò >‘D�A�qØ!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!I�JØ0²°A°Ñ6×=Ñ=Ó?ÀÑBÀQÑF�CØ0²°A°Ñ6×=Ñ=Ó?ÀÑBÀQÑF�CØ˜a“x C¨1£H°¸q³Ø'¨¨c¨
Ñ3×:Ñ:¸1Õ=ð>ð ]lÖlÐUX ¤R§X¡X¨o¸cÑ.BÓ%C×%HÑ%HÓ%JÈSÑ%PÑ PÐl�Òlð].mô` !Ÿ9™9¤U¨:Ó%6¸Ó:ˆLà*.¯.ª.�L�?Ðs¸|ÌUÏYÉYÔW\Ð]mÓWnÐpqÓMrÐ>sÐsàˆJØ!ÐØˆLØ Ñ,×2Ñ2°1Ñ5ˆJà˜{Ñ+ˆIØ#Ð$4Ñ5ˆNØ#Ð$4Ñ5×;Ñ;Ó=ˆNØ%)Ð"ä˜zÓ*ó .m�ð  Ð+Ø*@ÂÀAÀÑ*FÐ'Ü#%§=¡=Ð1DÌBÏHÉHÔ#U�Là-;¸EÑ-BÐ*Ü" <×#5Ñ#5°aÑ#8Ó9ò R˜Ø%;ºA¸q¸DÑ%A×%HÑ%HÓ%JÈ1Ñ%M˜
Ø!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!IÈAÑ!M˜Ø!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!IÈAÑ!M˜à! Q›;¨6°Q«;¸:È»?Ü.1°,ÀÈÐ?OÑ2PÓ.Q˜L¨šOðRð 4@Ð*ª1¨a¨4Ñ0à$-¨eÑ$4Ð!Ø)7¸Ñ)>Ð&Ø)7¸Ñ)>Ð&ØŸ*™*Ü Ÿn™nÐ->ÀQÔGÜ#%§>¡>Ð2HÈqÔ#QÜ#%§>¡>Ð2HÈqÔ#Qð %ó �ð
 !Ÿ™�à—>’>Ø$×+Ñ+¨G×,FÑ,FÔGà×!Ñ! &Ô)ä "§¡§¡´·±¸ÄÇ
Á
Ó0KÓ LÌrÏwÉwØ*¬B¯J©JóPñ !�ô #.×"9Ñ"9¼$Ó"?�Ø)?Ð&Ü%¤b§j¡j°Ó&?×&EÑ&EÓ&G×&NÑ&NÓ&PÓQò >‘D�A�qØ!7º¸1¸Ñ!=×!DÑ!DÓ!FÀqÑ!I�JØ0²°A°Ñ6×=Ñ=Ó?ÀÑBÀQÑF�CØ0²°A°Ñ6×=Ñ=Ó?ÀÑBÀQÑF�CØ˜a“x C¨1£H°¸q³Ø'¨¨c¨
Ñ3×:Ñ:¸1Õ=ð>ð ]lÖlÐUX ¤R§X¡X¨o¸cÑ.BÓ%C×%HÑ%HÓ%JÈSÑ%PÑ PÐl�Òlð].mô` Ÿ9™9¤U¨:Ó%6¸Ó:ˆLà*.¯.ª.�L�?Ðs¸|ÌRÏYÉYÔW\Ð]mÓWnÐpqÓMrÐ>sÐsùòE  mùò|  ms   Î	1^Ü1^c                 ór   •—  | j                   |i |¤Ž}t        ‰| �  |fi |¤Ž}t        |«      dk(  r|d   S |S )a  
        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.
        r   r   )rC   rA   r2   r'   )r-   rO   r.   Úpipeline_inputsÚresultsrQ   s        €r   r2   z'TableQuestionAnsweringPipeline.__call__  sL   ø€ ðV ,˜$×+Ñ+¨TÐ<°VÑ<ˆä‘'Ñ" ?Ñ=°fÑ=ˆÜˆw‹<˜1ÒØ˜1‘:ÐØˆr3   c                 óÈ   — i }|�||d<   |�||d<   i }|�||d<   | j                   �| j                   |d<   | j                  �| j                  |d<   | j                  |d<   ||i fS )NÚpaddingÚ
truncationÚ
sequentialÚassistant_modelÚ	tokenizerÚassistant_tokenizer)rŸ   r¡   r    )r-   rž   rœ   r�   r.   Úpreprocess_paramsÚforward_paramss          r   Ú_sanitize_parametersz3TableQuestionAnsweringPipeline._sanitize_parameters_  s”   € ØÐØÐØ+2Ð˜iÑ(ØÐ!Ø.8Ð˜lÑ+àˆØÐ!Ø+5ˆN˜<Ñ(à×ÑÐ+Ø04×0DÑ0DˆNÐ,Ñ-Ø×#Ñ#Ð/Ø*.¯.©.ˆN˜;Ñ'Ø48×4LÑ4LˆNÐ0Ñ1à  .°"Ð4Ð4r3   c                 óâ   — |€| j                   dk(  rd}nd}|d   |d   }}|j                  rt        d«      ‚|�|dk(  rt        d«      ‚| j                  ||| j                  ||¬	«      }||d<   |S )
Nr@   Údrop_rows_to_fitÚdo_not_truncater   r   ztable is emptyÚ zquery is empty)Úreturn_tensorsr�   rœ   )r"   Úemptyr$   r    rD   )r-   Úpipeline_inputrž   rœ   r�   r   r   rS   s           r   Ú
preprocessz)TableQuestionAnsweringPipeline.preprocessr  s‡   € ØÐØ�y‰y˜GÒ#Ø/‘
à.�
à% gÑ.°¸wÑ0GˆuˆØ�;Š;ÜÐ-Ó.Ð.Øˆ=˜E RšKÜÐ-Ó.Ð.Ø—‘  u¸T¿^¹^ÐXbÐls�ÓtˆØˆˆw‰Øˆr3   c                 ó  — |j                  d«      }| j                  dk(  r(|r | j                  di |¤Ž}nD | j                  di |¤Ž}n1d|vr| j                  |d<    | j
                  j                  di |¤|¤Ž}|||dœ}|S )Nr   r@   Úgeneration_config)Úmodel_inputsr   rŽ   r8   )Úpopr"   r—   rT   r®   rJ   Úgenerate)r-   r¯   rž   Úgenerate_kwargsr   rŽ   Úmodel_outputss          r   Ú_forwardz'TableQuestionAnsweringPipeline._forward‚  s—   € Ø× Ñ  Ó)ˆà�9‰9˜ÒÙØ3˜$×3Ñ3ÑC°lÑC‘à.˜$×.Ñ.Ñ>°Ñ>‘ð #¨/Ñ9Ø7;×7MÑ7M�Ð 3Ñ4à)�d—j‘j×)Ñ)ÑL¨LÐL¸OÑLˆGØ)5ÀÐRYÑZˆØÐr3   c                 ó>  — |d   }|d   }|d   }| j                   dk(  �r£| j                  r´|d d \  }}| j                  j                  |||«      }|\  }}	t	        |	«      D �
�ci c])  \  }
}|
| j
                  j                  j                  |   “Œ+ }}
}| j
                  j                  j                  }t	        |	«      D �
�ci c]  \  }
}||k7  sŒ|
||
   dz   “Œ }}
}n*|d   }| j                  j                  ||«      }|d   }i }i }g }t	        |«      D ]�  \  }}|D �cg c]  }|j                  |   ‘Œ }}|j                  |d«      }|j                  |d«      }|d	j                  |«      z   ||D �cg c]  }|j                  |   ‘Œ c}d
œ}|r||d<   |j                  |«       Œ’ t        «      dk(  r7t        d«      ‚| j                  j                  |d¬«      D �cg c]  }d|i‘Œ }}t        |«      dkD  r|S |d   S c c}}
w c c}}
w c c}w c c}w c c}w )Nr¯   r   rŽ   r@   r   z > r   r¨   z, )ÚanswerÚcoordinatesÚcellsÚ
aggregatorzEmpty answerT)Úskip_special_tokensr¶   r   )r"   rL   r    Úconvert_logits_to_predictionsrt   rJ   rK   r>   Úno_aggregation_label_indexÚiatr%   Újoinrl   r'   r   Úbatch_decode)r-   r³   rS   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   Úpostprocessz*TableQuestionAnsweringPipeline.postprocess“  sS  € Ø˜~Ñ.ˆØ˜gÑ&ˆØ 	Ñ*ˆØ�9‰9˜ÓØ�~Š~Ø%,¨R¨a [Ñ"�˜
Ø"Ÿn™n×JÑJÈ6ÐSYÐ[eÓf�Ø<GÑ9Ð(¨/Ü\eÐfuÓ\v×wÑQXÐQRÐTX˜q $§*¡*×"3Ñ"3×"FÑ"FÀtÑ"LÑLÐw�Ñwà%)§Z¡Z×%6Ñ%6×%QÑ%QÐ"ä=FÀÓ=W÷&Ù29°!°TÐ[_ÐcuÓ[u�A�{ 1‘~¨Ñ-Ñ-ð&Ð"ò &ð ! ™�Ø"Ÿn™n×JÑJÈ6ÐSYÓZ�Ø+6°q©>Ð(Ø �Ø%'Ð"ØˆGÜ&/Ð0HÓ&Iò 'Ñ"��{ØALÖM°:˜Ÿ™ :Ó.ÐM�ÐMØ(Ÿ_™_¨U°BÓ7�
Ø$6×$:Ñ$:¸5À"Ó$EÐ!à/°$·)±)¸EÓ2BÑBØ#.ØFQÖR¸
˜eŸi™i¨
Ó3ÒRñ�ñ
 Ø+5�F˜<Ñ(à—‘˜vÕ&ð'ô �6‹{˜aÒÜ'¨Ó7Ð7à8<¿¹×8SÑ8SÐT[ÐquÐ8SÓ8vÖw¨f˜ &Ò)ÐwˆGÐwä˜g›,¨Ò*ˆwÐ:°¸±
Ð:ùó? xùó&ùò Nùò Sùò xs$   Á$.HÃH
ÃH
Ä!HÅ5H
Ç"H)NNN)NTN)F)r4   r5   r6   r7   Údefault_input_namesr   rB   rT   r—   r2   r¤   r¬   r´   rË   Ú__classcell__)rQ   s   @r   r;   r;   U   sD   ø„ ñð< (Ðá#HÓ#Jõ Zò"$ò@tôDPód5ó&ó ö"(;r3   r;   )rr   r*   re   rb   Úutilsr   r   r   r   Úbaser	   r
   r   r   r   rh   Úmodels.auto.modeling_autor   r   Ú
tensorflowr=   Úmodels.auto.modeling_tf_autor   r   r   r;   r8   r3   r   ú<module>rÓ      sx   ðÛ Û ã ÷ó ÷ bÕ añ ÔÛ÷ñ
 ÔÛ÷ô2#¨Oô 2#ñj Ñ,¸4Ô@ÓAôe; Xó e;ó Bñe;r3   