

"""simple docstring"""



import concurrent.futures
import json
import os
import shutil
import tempfile
import unittest

from transformers import AutoTokenizer, PreTrainedTokenizerFast
from transformers.testing_utils import require_tokenizers

from ..test_tokenization_common import TokenizerTesterMixin



@require_tokenizers
class        a    (							_lowercase,						unittest.TestCase					):



    """simple docstring"""



    UpperCAmelCase    			=       PreTrainedTokenizerFast
    UpperCAmelCase    			=       False
    UpperCAmelCase    			=       True
    UpperCAmelCase    			=       "tokenizer_file"

    def 					UpperCamelCase						(  self:			int							):






         """simple docstring"""


         A__				      =	False  # because we don't have pretrained_vocab_files_map
         super().setUp()
         A__				      =	True

         A__				      =	["""robot-test/dummy-tokenizer-fast""", """robot-test/dummy-tokenizer-wordlevel"""]
         A__				      =	"""SaulLu/dummy-tokenizer-bytelevel-bpe"""

         # Inclusion of 2 tokenizers to test different types of models (Unigram and WordLevel for the moment)
         A__				      =	[(PreTrainedTokenizerFast, model_path, {}) for model_path in model_paths]

         A__				      =	PreTrainedTokenizerFast.from_pretrained(model_paths[0]							)
         tokenizer.save_pretrained(self.tmpdirname							)

    def 					UpperCamelCase						(  self:			Union[str, Any]							):






         """simple docstring"""


         pass

    def 					UpperCamelCase						(  self:			int							):






         """simple docstring"""


         pass

    def 					UpperCamelCase						(  self:			str							):






         """simple docstring"""


         pass

    def 					UpperCamelCase						(  self:			Union[str, Any]							):






         """simple docstring"""


         pass

    def 					UpperCamelCase						(  self:			Union[str, Any]							):






         """simple docstring"""


         A__				      =	self.tmpdirname
         # Here we want to test the 2 available tokenizers that use 2 different types of models: Unigram and WordLevel.
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""							):
                   try:
                        A__				      =	tempfile.mkdtemp()
                        A__				      =	self.rust_tokenizer_class.from_pretrained(__SCREAMING_SNAKE_CASE     ,    **__SCREAMING_SNAKE_CASE							)

                        tokenizer.save_pretrained(self.tmpdirname							)
                        super().test_training_new_tokenizer()
                   finally:
                        # Even if the test fails, we must be sure that the folder is deleted and that the default tokenizer
                        # is restored
                        shutil.rmtree(self.tmpdirname							)
                        A__				      =	tmpdirname_orig

    def 					UpperCamelCase						(  self:			Tuple							):






         """simple docstring"""


         A__				      =	self.tmpdirname
         # Here we want to test the 2 available tokenizers that use 2 different types of models: Unigram and WordLevel.
         for tokenizer, pretrained_name, kwargs in self.tokenizers_list:
              with self.subTest(f"""{tokenizer.__class__.__name__} ({pretrained_name})"""							):
                   try:
                        A__				      =	tempfile.mkdtemp()
                        A__				      =	self.rust_tokenizer_class.from_pretrained(__SCREAMING_SNAKE_CASE     ,    **__SCREAMING_SNAKE_CASE							)

                        tokenizer.save_pretrained(self.tmpdirname							)
                        super().test_training_new_tokenizer_with_special_tokens_change()
                   finally:
                        # Even if the test fails, we must be sure that the folder is deleted and that the default tokenizer
                        # is restored
                        shutil.rmtree(self.tmpdirname							)
                        A__				      =	tmpdirname_orig





    def 					UpperCamelCase						(  self:			List[Any]							):






         """simple docstring"""


         A__				      =	self.rust_tokenizer_class.from_pretrained(self.bytelevel_bpe_model_name							)

         A__				      =	("""a""" for _ in range(10_00							))
         A__				      =	tokenizer.train_new_from_iterator(text_iterator=__SCREAMING_SNAKE_CASE     ,    length=10_00     ,    vocab_size=50							)

         A__				      =	new_tokenizer.encode("""a🤗"""							)
         self.assertEqual(__SCREAMING_SNAKE_CASE     ,    [64, 1_72, 2_53, 97, 2_45]							)



@require_tokenizers
class        a    (							unittest.TestCase					):



    """simple docstring"""



    def 					UpperCamelCase						(  self:			Union[str, Any]							):






         """simple docstring"""


         A__				      =	AutoTokenizer.from_pretrained("""bert-base-cased"""							)
         A__				      =	json.loads(tokenizer._tokenizer.to_str()							)
         A__				      =	len(__SCREAMING_SNAKE_CASE							)

         with tempfile.TemporaryDirectory() as tmp_dir:
              # Hack to save this in the tokenizer_config.json
              A__				      =	["""tokenizer.4.0.0.json"""]
              tokenizer.save_pretrained(__SCREAMING_SNAKE_CASE							)
              json.dump(__SCREAMING_SNAKE_CASE     ,    open(os.path.join(__SCREAMING_SNAKE_CASE     ,    """tokenizer.4.0.0.json"""							)     ,    """w"""							)							)

              # This should pick the new tokenizer file as the version of Transformers is > 4.0.0
              A__				      =	AutoTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE							)
              self.assertEqual(len(__SCREAMING_SNAKE_CASE							)     ,    len(__SCREAMING_SNAKE_CASE							) + 1							)
              A__				      =	json.loads(new_tokenizer._tokenizer.to_str()							)
              self.assertIn("""huggingface"""     ,    json_tokenizer["""model"""]["""vocab"""]							)

              # Will need to be adjusted if we reach v42 and this test is still here.
              # Should pick the old tokenizer file as the version of Transformers is < 4.0.0
              shutil.move(os.path.join(__SCREAMING_SNAKE_CASE     ,    """tokenizer.4.0.0.json"""							)     ,    os.path.join(__SCREAMING_SNAKE_CASE     ,    """tokenizer.42.0.0.json"""							)							)
              A__				      =	["""tokenizer.42.0.0.json"""]
              tokenizer.save_pretrained(__SCREAMING_SNAKE_CASE							)
              A__				      =	AutoTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE							)
              self.assertEqual(len(__SCREAMING_SNAKE_CASE							)     ,    len(__SCREAMING_SNAKE_CASE							)							)
              A__				      =	json.loads(new_tokenizer._tokenizer.to_str()							)
              self.assertNotIn("""huggingface"""     ,    json_tokenizer["""model"""]["""vocab"""]							)





    def 					UpperCamelCase						(  self:			int							):






         """simple docstring"""


         A__				      =	"""hf-internal-testing/test-two-tokenizers"""

         # This should pick the new tokenizer file as the version of Transformers is > 4.0.0
         A__				      =	AutoTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE							)
         self.assertEqual(len(__SCREAMING_SNAKE_CASE							)     ,    2_89_97							)
         A__				      =	json.loads(tokenizer._tokenizer.to_str()							)
         self.assertIn("""huggingface"""     ,    json_tokenizer["""model"""]["""vocab"""]							)

         # Testing an older version by monkey-patching the version in the module it's used.
         import transformers as old_transformers

         A__				      =	"""3.0.0"""
         A__				      =	old_transformers.models.auto.AutoTokenizer.from_pretrained(__SCREAMING_SNAKE_CASE							)
         self.assertEqual(len(__SCREAMING_SNAKE_CASE							)     ,    2_89_96							)
         A__				      =	json.loads(old_tokenizer._tokenizer.to_str()							)
         self.assertNotIn("""huggingface"""     ,    json_tokenizer["""model"""]["""vocab"""]							)



@require_tokenizers
class        a    (							unittest.TestCase					):



    """simple docstring"""



    def 					UpperCamelCase						(  self:			Optional[Any]							):






         """simple docstring"""


         A__				      =	PreTrainedTokenizerFast.from_pretrained("""robot-test/dummy-tokenizer-wordlevel"""							)
         A__				      =	"""The Matrix is a 1999 science fiction action film."""

         with concurrent.futures.ThreadPoolExecutor() as executor:
              A__				      =	[executor.submit(self.fetch     ,    __SCREAMING_SNAKE_CASE     ,    __SCREAMING_SNAKE_CASE							) for i in range(10							)]
              A__				      =	[future.result() for future in futures]
              self.assertEqual(__SCREAMING_SNAKE_CASE     ,    [[1, 10, 0, 8, 0, 18, 0, 0, 0, 2] for i in range(10							)]							)





    def 					UpperCamelCase						(  self:			Optional[Any]     ,    UpperCamelCase:			Optional[Any]     ,    UpperCamelCase:			Union[str, Any]							):






         """simple docstring"""


         return tokenizer.encode(__SCREAMING_SNAKE_CASE     ,    truncation="""longest_first"""     ,    padding="""longest"""							)







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 						_SCREAMING_SNAKE_CASE				(  _lowercase				):






		"""simple docstring"""







		def __call__(      self     :					Union[str, Any]	,       __SCREAMING_SNAKE_CASE     :					int=None	,       __SCREAMING_SNAKE_CASE     :					str=None	,       **__SCREAMING_SNAKE_CASE     :					Union[str, Any] ):






					"""simple docstring"""
					# Returns tqa_pipeline_inputs of shape:
					# [
					#   {"table": pd.DataFrame, "query": List[str]},
					#   ...,
					#   {"table": pd.DataFrame, "query" : List[str]}
					# ]
					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(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE ) and table.get("query" ) is not None and table.get("table" ) is not None:
											_snake_case														=   [table]
								elif isinstance(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE ) and len(__SCREAMING_SNAKE_CASE ) > 0:
											if not all(isinstance(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE ) for d in table ):
														raise ValueError(
														    F'Keyword argument `table` should be a list of dict, but is {(type(__SCREAMING_SNAKE_CASE ) for d in table)}' )

											if table[0].get("query" ) is not None and table[0].get("table" ) is not None:
														_snake_case														=   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(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE ) or isinstance(__SCREAMING_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(__SCREAMING_SNAKE_CASE )})' )
					else:
								_snake_case														=   [{"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														=   pd.DataFrame(tqa_pipeline_input["table"] )

					return tqa_pipeline_inputs

@add_end_docstrings(_lowercase				)
class 						_SCREAMING_SNAKE_CASE				(  _lowercase				):






		"""simple docstring"""







		A_    			=   '''table,query'''



		def __init__(      self     :					Optional[Any]	,       __SCREAMING_SNAKE_CASE     :					Tuple=TableQuestionAnsweringArgumentHandler()	,       *__SCREAMING_SNAKE_CASE     :					Optional[int]	,       **__SCREAMING_SNAKE_CASE     :					List[Any] ):






					"""simple docstring"""
					super().__init__(*__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )
					_snake_case														=   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														=   bool(getattr(self.model.config	,       "aggregation_labels"	,       __SCREAMING_SNAKE_CASE ) ) and bool(
					    getattr(self.model.config	,       "num_aggregation_labels"	,       __SCREAMING_SNAKE_CASE ) )
					_snake_case														=   "tapas" if hasattr(self.model.config	,       "aggregation_labels" ) else None



		def 					_a					(      self     :					List[Any]	,       **__SCREAMING_SNAKE_CASE     :					str ):






					"""simple docstring"""
					return self.model(**__SCREAMING_SNAKE_CASE )



		def 					_a					(      self     :					Tuple	,       **__SCREAMING_SNAKE_CASE     :					List[Any] ):






					"""simple docstring"""
					if self.framework == "pt":
								_snake_case														=   []
								_snake_case														=   []
								_snake_case														=   None
								_snake_case														=   inputs["input_ids"].shape[0]

								_snake_case														=   inputs["input_ids"].to(self.device )
								_snake_case														=   inputs["attention_mask"].to(self.device )
								_snake_case														=   inputs["token_type_ids"].to(self.device )
								_snake_case														=   None

								for index in range(__SCREAMING_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														=   token_type_ids_example[:, 3]  # shape (seq_len,)
														_snake_case														=   np.zeros_like(prev_labels_example.cpu().numpy() )  # shape (seq_len,)

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

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

														_snake_case														=   torch.from_numpy(__SCREAMING_SNAKE_CASE ).type(torch.long ).to(self.device )

											_snake_case														=   input_ids[index]
											_snake_case														=   attention_mask[index]  # shape (seq_len,)
											_snake_case														=   token_type_ids[index]  # shape (seq_len, 7)
											_snake_case														=   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														=   outputs.logits

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

											all_logits.append(__SCREAMING_SNAKE_CASE )

											_snake_case														=   torch.distributions.Bernoulli(logits=__SCREAMING_SNAKE_CASE )
											_snake_case														=   dist_per_token.probs * attention_mask_example.type(torch.floataa ).to(
											    dist_per_token.probs.device )

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

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

								_snake_case														=   torch.cat(tuple(__SCREAMING_SNAKE_CASE )	,       0 )

								return (logits_batch,) if not self.aggregate else (logits_batch, torch.cat(tuple(__SCREAMING_SNAKE_CASE )	,       0 ))
					else:
								_snake_case														=   []
								_snake_case														=   []
								_snake_case														=   None
								_snake_case														=   inputs["input_ids"].shape[0]

								_snake_case														=   inputs["input_ids"]
								_snake_case														=   inputs["attention_mask"]
								_snake_case														=   inputs["token_type_ids"].numpy()
								_snake_case														=   None

								for index in range(__SCREAMING_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														=   token_type_ids_example[:, 3]  # shape (seq_len,)
														_snake_case														=   np.zeros_like(__SCREAMING_SNAKE_CASE	,       dtype=np.intaa )  # shape (seq_len,)

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

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

														_snake_case														=   model_labels

											_snake_case														=   input_ids[index]
											_snake_case														=   attention_mask[index]  # shape (seq_len,)
											_snake_case														=   token_type_ids[index]  # shape (seq_len, 7)
											_snake_case														=   self.model(
											    input_ids=np.expand_dims(__SCREAMING_SNAKE_CASE	,       axis=0 )	,       attention_mask=np.expand_dims(__SCREAMING_SNAKE_CASE	,       axis=0 )	,       token_type_ids=np.expand_dims(__SCREAMING_SNAKE_CASE	,       axis=0 )	,       )
											_snake_case														=   outputs.logits

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

											all_logits.append(__SCREAMING_SNAKE_CASE )

											_snake_case														=   tfp.distributions.Bernoulli(logits=__SCREAMING_SNAKE_CASE )
											_snake_case														=   dist_per_token.probs_parameter() * tf.cast(__SCREAMING_SNAKE_CASE	,       tf.floataa )

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

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

								_snake_case														=   tf.concat(tuple(__SCREAMING_SNAKE_CASE )	,       0 )

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



		def __call__(      self     :					str	,       *__SCREAMING_SNAKE_CASE     :					Optional[int]	,       **__SCREAMING_SNAKE_CASE     :					List[Any] ):






					"""simple docstring"""
					_snake_case														=   self._args_parser(*__SCREAMING_SNAKE_CASE	,       **__SCREAMING_SNAKE_CASE )

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



		def 					_a					(      self     :					Optional[int]	,       __SCREAMING_SNAKE_CASE     :					Optional[int]=None	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]=None	,       __SCREAMING_SNAKE_CASE     :					str=None	,       **__SCREAMING_SNAKE_CASE     :					Optional[int] ):






					"""simple docstring"""
					_snake_case														=   {}
					if padding is not None:
								_snake_case														=   padding
					if truncation is not None:
								_snake_case														=   truncation

					_snake_case														=   {}
					if sequential is not None:
								_snake_case														=   sequential
					return preprocess_params, forward_params, {}



		def 					_a					(      self     :					Any	,       __SCREAMING_SNAKE_CASE     :					Tuple	,       __SCREAMING_SNAKE_CASE     :					Optional[Any]=None	,       __SCREAMING_SNAKE_CASE     :					Union[str, Any]=True	,       __SCREAMING_SNAKE_CASE     :					str=None ):






					"""simple docstring"""
					if truncation is None:
								if self.type == "tapas":
											_snake_case														=   "drop_rows_to_fit"
								else:
											_snake_case														=   "do_not_truncate"

					_snake_case							,			_snake_case														=   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														=   self.tokenizer(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       return_tensors=self.framework	,       truncation=__SCREAMING_SNAKE_CASE	,       padding=__SCREAMING_SNAKE_CASE )
					_snake_case														=   table
					return inputs



		def 					_a					(      self     :					Optional[int]	,       __SCREAMING_SNAKE_CASE     :					str	,       __SCREAMING_SNAKE_CASE     :					List[Any]=False ):






					"""simple docstring"""
					_snake_case														=   model_inputs.pop("table" )

					if self.type == "tapas":
								if sequential:
											_snake_case														=   self.sequential_inference(**__SCREAMING_SNAKE_CASE )
								else:
											_snake_case														=   self.batch_inference(**__SCREAMING_SNAKE_CASE )
					else:
								_snake_case														=   self.model.generate(**__SCREAMING_SNAKE_CASE )
					_snake_case														=   {"model_inputs": model_inputs, "table": table, "outputs": outputs}
					return model_outputs







		def 					_a					(      self     :					Dict	,       __SCREAMING_SNAKE_CASE     :					Optional[int] ):






					"""simple docstring"""
					_snake_case														=   model_outputs["model_inputs"]
					_snake_case														=   model_outputs["table"]
					_snake_case														=   model_outputs["outputs"]
					if self.type == "tapas":
								if self.aggregate:
											_snake_case							,			_snake_case														=   outputs[:2]
											_snake_case														=   self.tokenizer.convert_logits_to_predictions(__SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE	,       __SCREAMING_SNAKE_CASE )
											_snake_case							,			_snake_case														=   predictions
											_snake_case														=   {i: self.model.config.aggregation_labels[pred] for i, pred in enumerate(__SCREAMING_SNAKE_CASE )}

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

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

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

