



'''simple docstring'''





import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
      from transformers import WhisperFeatureExtractor, WhisperProcessor


A			:   Optional[Any]			=      50_358
A			:   Union[str, Any]			=      50_362





@require_torch
@require_torchaudio
@require_sentencepiece
class 							lowerCAmelCase_		(	unittest.TestCase						):





    def 					__snake_case       (    self    :    List[str]     ):



       '''simple docstring'''







       snake_case   :							Tuple						  ='''openai/whisper-small.en'''
       snake_case   :							Optional[Any]						  =tempfile.mkdtemp()





    def 					__snake_case       (    self    :    Any,    **_snake_case    :    str     ):



       '''simple docstring'''







       return WhisperTokenizer.from_pretrained(self.checkpoint,    **_snake_case     )





    def 					__snake_case       (    self    :    Tuple,    **_snake_case    :    Any     ):



       '''simple docstring'''







       return WhisperFeatureExtractor.from_pretrained(self.checkpoint,    **_snake_case     )





    def 					__snake_case       (    self    :    str     ):



       '''simple docstring'''







       shutil.rmtree(self.tmpdirname     )





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							str						  =self.get_tokenizer()
       snake_case   :							str						  =self.get_feature_extractor()

       snake_case   :							Dict						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )

       processor.save_pretrained(self.tmpdirname     )
       snake_case   :							Any						  =WhisperProcessor.from_pretrained(self.tmpdirname     )

       self.assertEqual(processor.tokenizer.get_vocab(),    tokenizer.get_vocab()     )
       self.assertIsInstance(processor.tokenizer,    _snake_case     )

       self.assertEqual(processor.feature_extractor.to_json_string(),    feature_extractor.to_json_string()     )
       self.assertIsInstance(processor.feature_extractor,    _snake_case     )





    def 					__snake_case       (    self    :    int     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =WhisperProcessor(tokenizer=self.get_tokenizer(),    feature_extractor=self.get_feature_extractor()     )
       processor.save_pretrained(self.tmpdirname     )

       snake_case   :							int						  =self.get_tokenizer(bos_token='''(BOS)''',    eos_token='''(EOS)'''     )
       snake_case   :							int						  =self.get_feature_extractor(do_normalize=_snake_case,    padding_value=1.0     )

       snake_case   :							str						  =WhisperProcessor.from_pretrained(
           self.tmpdirname,    bos_token='''(BOS)''',    eos_token='''(EOS)''',    do_normalize=_snake_case,    padding_value=1.0     )

       self.assertEqual(processor.tokenizer.get_vocab(),    tokenizer_add_kwargs.get_vocab()     )
       self.assertIsInstance(processor.tokenizer,    _snake_case     )

       self.assertEqual(processor.feature_extractor.to_json_string(),    feature_extractor_add_kwargs.to_json_string()     )
       self.assertIsInstance(processor.feature_extractor,    _snake_case     )





    def 					__snake_case       (    self    :    Dict     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =self.get_feature_extractor()
       snake_case   :							Optional[Any]						  =self.get_tokenizer()

       snake_case   :							List[Any]						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )

       snake_case   :							List[Any]						  =floats_list((3, 1_000)     )

       snake_case   :							str						  =feature_extractor(_snake_case,    return_tensors='''np'''     )
       snake_case   :							Union[str, Any]						  =processor(_snake_case,    return_tensors='''np'''     )

       for key in input_feat_extract.keys():
          self.assertAlmostEqual(input_feat_extract[key].sum(),    input_processor[key].sum(),    delta=1E-2     )





    def 					__snake_case       (    self    :    Optional[Any]     ):



       '''simple docstring'''







       snake_case   :							Dict						  =self.get_feature_extractor()
       snake_case   :							List[Any]						  =self.get_tokenizer()

       snake_case   :							Dict						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )

       snake_case   :							Tuple						  ='''This is a test string'''

       snake_case   :							str						  =processor(text=_snake_case     )

       snake_case   :							Any						  =tokenizer(_snake_case     )

       for key in encoded_tok.keys():
          self.assertListEqual(encoded_tok[key],    encoded_processor[key]     )





    def 					__snake_case       (    self    :    Any     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =self.get_feature_extractor()
       snake_case   :							Optional[Any]						  =self.get_tokenizer()

       snake_case   :							int						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )

       snake_case   :							List[Any]						  =[[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

       snake_case   :							Optional[Any]						  =processor.batch_decode(_snake_case     )
       snake_case   :							Any						  =tokenizer.batch_decode(_snake_case     )

       self.assertListEqual(_snake_case,    _snake_case     )





    def 					__snake_case       (    self    :    Dict     ):



       '''simple docstring'''







       snake_case   :							Optional[int]						  =self.get_feature_extractor()
       snake_case   :							int						  =self.get_tokenizer()

       snake_case   :							List[str]						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )

       self.assertListEqual(
           processor.model_input_names,    feature_extractor.model_input_names,    msg='''`processor` and `feature_extractor` model input names do not match''',    )





    def 					__snake_case       (    self    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							Optional[Any]						  =self.get_feature_extractor()
       snake_case   :							List[str]						  =self.get_tokenizer()

       snake_case   :							Dict						  =WhisperProcessor(tokenizer=_snake_case,    feature_extractor=_snake_case     )
       snake_case   :							Dict						  =processor.get_decoder_prompt_ids(task='''transcribe''',    no_timestamps=_snake_case     )

       self.assertIsInstance(_snake_case,    _snake_case     )
       for ids in forced_decoder_ids:
          self.assertIsInstance(_snake_case,    (list, tuple)     )

       snake_case   :							int						  =[TRANSCRIBE, NOTIMESTAMPS]
       self.assertListEqual([ids[-1] for ids in forced_decoder_ids],    _snake_case     )





    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =WhisperProcessor(tokenizer=self.get_tokenizer(),    feature_extractor=self.get_feature_extractor()     )
       snake_case   :							Optional[int]						  =processor.get_prompt_ids('''Mr. Quilter'''     )
       snake_case   :							List[str]						  =processor.tokenizer.decode(_snake_case     )

       self.assertListEqual(prompt_ids.tolist(),    [50_360, 1_770, 13, 2_264, 346, 353]     )
       self.assertEqual(_snake_case,    '''<|startofprev|> Mr. Quilter'''     )





    def 					__snake_case       (    self    :    Optional[int]     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =WhisperProcessor(tokenizer=self.get_tokenizer(),    feature_extractor=self.get_feature_extractor()     )
       snake_case   :							str						  =processor.get_prompt_ids(''''''     )
       snake_case   :							Optional[int]						  =processor.tokenizer.decode(_snake_case     )

       self.assertListEqual(prompt_ids.tolist(),    [50_360, 220]     )
       self.assertEqual(_snake_case,    '''<|startofprev|> '''     )






    def 					__snake_case       (    self    :    Any     ):



       '''simple docstring'''







       snake_case   :							Any						  =WhisperProcessor(tokenizer=self.get_tokenizer(),    feature_extractor=self.get_feature_extractor()     )

       def _test_prompt_error_raised_helper(_snake_case    :    Dict,    _snake_case    :    List[Any]     ):
          with pytest.raises(_snake_case     ) as excinfo:
             processor.get_prompt_ids(_snake_case     )
          snake_case   :							List[str]						  =f'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
          self.assertEqual(_snake_case,    str(excinfo.value     )     )

       _test_prompt_error_raised_helper('''<|startofprev|> test''',    '''<|startofprev|>'''     )
       _test_prompt_error_raised_helper('''test <|notimestamps|>''',    '''<|notimestamps|>'''     )
       _test_prompt_error_raised_helper('''test <|zh|> test <|transcribe|>''',    '''<|zh|>'''     )










'''simple docstring'''





import collections
import types

import numpy as np

from ..utils import (
    add_end_docstrings,
    is_tensorflow_probability_available,
    is_tf_available,
    is_torch_available,
    requires_backends,
)
from .base import PIPELINE_INIT_ARGS, ArgumentHandler, Dataset, Pipeline, PipelineException


if is_torch_available():
      import torch

      from ..models.auto.modeling_auto import (
          MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
          MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
      )

if is_tf_available() and is_tensorflow_probability_available():
      import tensorflow as tf
      import tensorflow_probability as tfp

      from ..models.auto.modeling_tf_auto import (
          TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING,
          TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING,
      )





class 							lowerCAmelCase_		(	a_						):





    def __call__(    self    :    str,    _snake_case    :    Dict=None,    _snake_case    :    str=None,    **_snake_case    :    Any     ):



       '''simple docstring'''







       requires_backends(self,    '''pandas'''     )
       import pandas as pd

       if table is None:
          raise ValueError('''Keyword argument `table` cannot be None.'''     )
       elif query is None:
          if isinstance(_snake_case,    _snake_case     ) and table.get('''query'''     ) is not None and table.get('''table'''     ) is not None:
             snake_case   :							Union[str, Any]						  =[table]
          elif isinstance(_snake_case,    _snake_case     ) and len(_snake_case     ) > 0:
             if not all(isinstance(_snake_case,    _snake_case     ) for d in table     ):
                raise ValueError(
                    f'''Keyword argument `table` should be a list of dict, but is {(type(_snake_case     ) for d in table)}'''     )

             if table[0].get('''query'''     ) is not None and table[0].get('''table'''     ) is not None:
                snake_case   :							Dict						  =table
             else:
                raise ValueError(
                    '''If keyword argument `table` is a list of dictionaries, each dictionary should have a `table`'''
                    f''' and `query` key, but only dictionary has keys {table[0].keys()} `table` and `query` keys.'''     )
          elif Dataset is not None and isinstance(_snake_case,    _snake_case     ) or isinstance(_snake_case,    types.GeneratorType     ):
             return table
          else:
             raise ValueError(
                 '''Invalid input. Keyword argument `table` should be either of type `dict` or `list`, but '''
                 f'''is {type(_snake_case     )})'''     )
       else:
          snake_case   :							Union[str, Any]						  =[{'''table''': table, '''query''': query}]

       for tqa_pipeline_input in tqa_pipeline_inputs:
          if not isinstance(tqa_pipeline_input['''table'''],    pd.DataFrame     ):
             if tqa_pipeline_input["table"] is None:
                raise ValueError('''Table cannot be None.'''     )

             snake_case   :							Any						  =pd.DataFrame(tqa_pipeline_input['''table''']     )

       return tqa_pipeline_inputs





@add_end_docstrings(a_						)
class 							lowerCAmelCase_		(	a_						):
    __UpperCAmelCase							=	'table,query'





    def __init__(    self    :    Any,    _snake_case    :    Any=TableQuestionAnsweringArgumentHandler(),    *_snake_case    :    List[Any],    **_snake_case    :    Dict     ):



       '''simple docstring'''







       super().__init__(*_snake_case,    **_snake_case     )
       snake_case   :							str						  =args_parser

       self.check_model_type(
           dict(
               TF_MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items()
               + TF_MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()     )
           if self.framework == '''tf'''
           else dict(
               MODEL_FOR_TABLE_QUESTION_ANSWERING_MAPPING.items() + MODEL_FOR_SEQ_TO_SEQ_CAUSAL_LM_MAPPING.items()     )     )

       snake_case   :							Dict						  =bool(getattr(self.model.config,    '''aggregation_labels''',    _snake_case     )     ) and bool(
           getattr(self.model.config,    '''num_aggregation_labels''',    _snake_case     )     )
       snake_case   :							List[str]						  ='''tapas''' if hasattr(self.model.config,    '''aggregation_labels'''     ) else None





    def 					__snake_case       (    self    :    Dict,    **_snake_case    :    Tuple     ):



       '''simple docstring'''







       return self.model(**_snake_case     )





    def 					__snake_case       (    self    :    List[Any],    **_snake_case    :    List[str]     ):



       '''simple docstring'''







       if self.framework == "pt":
          snake_case   :							str						  =[]
          snake_case   :							str						  =[]
          snake_case   :							Optional[int]						  =None
          snake_case   :							List[str]						  =inputs['''input_ids'''].shape[0]

          snake_case   :							Union[str, Any]						  =inputs['''input_ids'''].to(self.device     )
          snake_case   :							List[str]						  =inputs['''attention_mask'''].to(self.device     )
          snake_case   :							Optional[int]						  =inputs['''token_type_ids'''].to(self.device     )
          snake_case   :							Any						  =None

          for index in range(_snake_case     ):
             # If sequences have already been processed, the token type IDs will be created according to the previous
             # answer.
             if prev_answers is not None:
                snake_case   :							Union[str, Any]						  =token_type_ids_example[:, 3]  # shape (seq_len,)
                snake_case   :							Any						  =np.zeros_like(prev_labels_example.cpu().numpy()     )  # shape (seq_len,)

                snake_case   :							Any						  =token_type_ids[index]  # shape (seq_len, 7)
                for i in range(model_labels.shape[0]     ):
                   snake_case   :							Tuple						  =token_type_ids_example[:, 0].tolist()[i]
                   snake_case   :							Tuple						  =token_type_ids_example[:, 1].tolist()[i] - 1
                   snake_case   :							Optional[int]						  =token_type_ids_example[:, 2].tolist()[i] - 1

                   if row_id >= 0 and col_id >= 0 and segment_id == 1:
                      snake_case   :							List[Any]						  =int(prev_answers[(col_id, row_id)]     )

                snake_case   :							List[Any]						  =torch.from_numpy(_snake_case     ).type(torch.long     ).to(self.device     )

             snake_case   :							Tuple						  =input_ids[index]
             snake_case   :							Optional[int]						  =attention_mask[index]  # shape (seq_len,)
             snake_case   :							List[Any]						  =token_type_ids[index]  # shape (seq_len, 7)
             snake_case   :							Union[str, Any]						  =self.model(
                 input_ids=input_ids_example.unsqueeze(0     ),    attention_mask=attention_mask_example.unsqueeze(0     ),    token_type_ids=token_type_ids_example.unsqueeze(0     ),    )
             snake_case   :							int						  =outputs.logits

             if self.aggregate:
                all_aggregations.append(outputs.logits_aggregation     )

             all_logits.append(_snake_case     )

             snake_case   :							List[Any]						  =torch.distributions.Bernoulli(logits=_snake_case     )
             snake_case   :							Optional[Any]						  =dist_per_token.probs * attention_mask_example.type(torch.floataa     ).to(
                 dist_per_token.probs.device     )

             snake_case   :							Dict						  =collections.defaultdict(_snake_case     )
             for i, p in enumerate(probabilities.squeeze().tolist()     ):
                snake_case   :							int						  =token_type_ids_example[:, 0].tolist()[i]
                snake_case   :							Optional[int]						  =token_type_ids_example[:, 1].tolist()[i] - 1
                snake_case   :							Dict						  =token_type_ids_example[:, 2].tolist()[i] - 1
                if col >= 0 and row >= 0 and segment_id == 1:
                   coords_to_probs[(col, row)].append(_snake_case     )

             snake_case   :							Union[str, Any]						  ={key: np.array(coords_to_probs[key]     ).mean() > 0.5 for key in coords_to_probs}

          snake_case   :							Tuple						  =torch.cat(tuple(_snake_case     ),    0     )

          return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(_snake_case     ),    0     ))
       else:
          snake_case   :							Tuple						  =[]
          snake_case   :							Optional[int]						  =[]
          snake_case   :							str						  =None
          snake_case   :							Dict						  =inputs['''input_ids'''].shape[0]

          snake_case   :							Optional[Any]						  =inputs['''input_ids''']
          snake_case   :							Optional[int]						  =inputs['''attention_mask''']
          snake_case   :							Union[str, Any]						  =inputs['''token_type_ids'''].numpy()
          snake_case   :							Tuple						  =None

          for index in range(_snake_case     ):
             # If sequences have already been processed, the token type IDs will be created according to the previous
             # answer.
             if prev_answers is not None:
                snake_case   :							Any						  =token_type_ids_example[:, 3]  # shape (seq_len,)
                snake_case   :							str						  =np.zeros_like(_snake_case,    dtype=np.intaa     )  # shape (seq_len,)

                snake_case   :							Any						  =token_type_ids[index]  # shape (seq_len, 7)
                for i in range(model_labels.shape[0]     ):
                   snake_case   :							Union[str, Any]						  =token_type_ids_example[:, 0].tolist()[i]
                   snake_case   :							Dict						  =token_type_ids_example[:, 1].tolist()[i] - 1
                   snake_case   :							Any						  =token_type_ids_example[:, 2].tolist()[i] - 1

                   if row_id >= 0 and col_id >= 0 and segment_id == 1:
                      snake_case   :							Any						  =int(prev_answers[(col_id, row_id)]     )

                snake_case   :							Union[str, Any]						  =model_labels

             snake_case   :							List[Any]						  =input_ids[index]
             snake_case   :							Tuple						  =attention_mask[index]  # shape (seq_len,)
             snake_case   :							Optional[Any]						  =token_type_ids[index]  # shape (seq_len, 7)
             snake_case   :							Optional[Any]						  =self.model(
                 input_ids=np.expand_dims(_snake_case,    axis=0     ),    attention_mask=np.expand_dims(_snake_case,    axis=0     ),    token_type_ids=np.expand_dims(_snake_case,    axis=0     ),    )
             snake_case   :							List[str]						  =outputs.logits

             if self.aggregate:
                all_aggregations.append(outputs.logits_aggregation     )

             all_logits.append(_snake_case     )

             snake_case   :							int						  =tfp.distributions.Bernoulli(logits=_snake_case     )
             snake_case   :							Union[str, Any]						  =dist_per_token.probs_parameter() * tf.cast(_snake_case,    tf.floataa     )

             snake_case   :							List[Any]						  =collections.defaultdict(_snake_case     )
             snake_case   :							Dict						  =token_type_ids_example
             for i, p in enumerate(tf.squeeze(_snake_case     ).numpy().tolist()     ):
                snake_case   :							Optional[Any]						  =token_type_ids_example[:, 0].tolist()[i]
                snake_case   :							Optional[Any]						  =token_type_ids_example[:, 1].tolist()[i] - 1
                snake_case   :							str						  =token_type_ids_example[:, 2].tolist()[i] - 1
                if col >= 0 and row >= 0 and segment_id == 1:
                   coords_to_probs[(col, row)].append(_snake_case     )

             snake_case   :							Optional[int]						  ={key: np.array(coords_to_probs[key]     ).mean() > 0.5 for key in coords_to_probs}

          snake_case   :							Dict						  =tf.concat(tuple(_snake_case     ),    0     )

          return (logits_batch,) if not self.aggregate else (logits_batch, tf.concat(tuple(_snake_case     ),    0     ))





    def __call__(    self    :    List[str],    *_snake_case    :    Any,    **_snake_case    :    List[Any]     ):



       '''simple docstring'''







       snake_case   :							Tuple						  =self._args_parser(*_snake_case,    **_snake_case     )

       snake_case   :							Dict						  =super().__call__(_snake_case,    **_snake_case     )
       if len(_snake_case     ) == 1:
          return results[0]
       return results





    def 					__snake_case       (    self    :    Dict,    _snake_case    :    Union[str, Any]=None,    _snake_case    :    Union[str, Any]=None,    _snake_case    :    List[Any]=None,    **_snake_case    :    List[str]     ):



       '''simple docstring'''







       snake_case   :							Optional[Any]						  ={}
       if padding is not None:
          snake_case   :							List[Any]						  =padding
       if truncation is not None:
          snake_case   :							int						  =truncation

       snake_case   :							Any						  ={}
       if sequential is not None:
          snake_case   :							int						  =sequential
       return preprocess_params, forward_params, {}





    def 					__snake_case       (    self    :    Dict,    _snake_case    :    Dict,    _snake_case    :    List[Any]=None,    _snake_case    :    Optional[int]=True,    _snake_case    :    Dict=None     ):



       '''simple docstring'''







       if truncation is None:
          if self.type == "tapas":
             snake_case   :							Union[str, Any]						  ='''drop_rows_to_fit'''
          else:
             snake_case   :							Dict						  ='''do_not_truncate'''

       snake_case  ,    snake_case   :							Optional[int]						  =pipeline_input['''table'''], pipeline_input['''query''']
       if table.empty:
          raise ValueError('''table is empty'''     )
       if query is None or query == "":
          raise ValueError('''query is empty'''     )
       snake_case   :							Dict						  =self.tokenizer(_snake_case,    _snake_case,    return_tensors=self.framework,    truncation=_snake_case,    padding=_snake_case     )
       snake_case   :							List[Any]						  =table
       return inputs





    def 					__snake_case       (    self    :    List[str],    _snake_case    :    List[Any],    _snake_case    :    Any=False     ):



       '''simple docstring'''







       snake_case   :							Union[str, Any]						  =model_inputs.pop('''table'''     )

       if self.type == "tapas":
          if sequential:
             snake_case   :							Dict						  =self.sequential_inference(**_snake_case     )
          else:
             snake_case   :							Optional[int]						  =self.batch_inference(**_snake_case     )
       else:
          snake_case   :							str						  =self.model.generate(**_snake_case     )
       snake_case   :							int						  ={'''model_inputs''': model_inputs, '''table''': table, '''outputs''': outputs}
       return model_outputs






    def 					__snake_case       (    self    :    Optional[int],    _snake_case    :    Optional[Any]     ):



       '''simple docstring'''







       snake_case   :							str						  =model_outputs['''model_inputs''']
       snake_case   :							Tuple						  =model_outputs['''table''']
       snake_case   :							Union[str, Any]						  =model_outputs['''outputs''']
       if self.type == "tapas":
          if self.aggregate:
             snake_case  ,    snake_case   :							Union[str, Any]						  =outputs[:2]
             snake_case   :							Tuple						  =self.tokenizer.convert_logits_to_predictions(_snake_case,    _snake_case,    _snake_case     )
             snake_case  ,    snake_case   :							Any						  =predictions
             snake_case   :							int						  ={i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(_snake_case     )}

             snake_case   :							List[str]						  =self.model.config.no_aggregation_label_index
             snake_case   :							Dict						  ={
                 i: aggregators[i] + ''' > ''' for i, pred in enumerate(_snake_case     ) if pred != no_agg_label_index
             }
          else:
             snake_case   :							List[str]						  =outputs[0]
             snake_case   :							List[Any]						  =self.tokenizer.convert_logits_to_predictions(_snake_case,    _snake_case     )
             snake_case   :							str						  =predictions[0]
             snake_case   :							str						  ={}
             snake_case   :							str						  ={}
          snake_case   :							Optional[int]						  =[]
          for index, coordinates in enumerate(_snake_case     ):
             snake_case   :							int						  =[table.iat[coordinate] for coordinate in coordinates]
             snake_case   :							Dict						  =aggregators.get(_snake_case,    ''''''     )
             snake_case   :							Any						  =aggregators_prefix.get(_snake_case,    ''''''     )
             snake_case   :							int						  ={
                 '''answer''': aggregator_prefix + ''', '''.join(_snake_case     ),
                 '''coordinates''': coordinates,
                 '''cells''': [table.iat[coordinate] for coordinate in coordinates],
             }
             if aggregator:
                snake_case   :							Tuple						  =aggregator

             answers.append(_snake_case     )
          if len(_snake_case     ) == 0:
             raise PipelineException('''Empty answer'''     )
       else:
          snake_case   :							Optional[int]						  =[{'''answer''': answer} for answer in self.tokenizer.batch_decode(_snake_case,    skip_special_tokens=_snake_case     )]

       return answers if len(_snake_case     ) > 1 else answers[0]





