


"""simple docstring"""







from ...configuration_utils import PretrainedConfig


a__				:							Optional[int]						=     {
    '''google/tapas-base-finetuned-sqa''': (
        '''https://huggingface.co/google/tapas-base-finetuned-sqa/resolve/main/config.json'''
    ),
    '''google/tapas-base-finetuned-wtq''': (
        '''https://huggingface.co/google/tapas-base-finetuned-wtq/resolve/main/config.json'''
    ),
    '''google/tapas-base-finetuned-wikisql-supervised''': (
        '''https://huggingface.co/google/tapas-base-finetuned-wikisql-supervised/resolve/main/config.json'''
    ),
    '''google/tapas-base-finetuned-tabfact''': (
        '''https://huggingface.co/google/tapas-base-finetuned-tabfact/resolve/main/config.json'''
    ),
}




class  UpperCamelCase_	( UpperCamelCase):

	"""simple docstring"""





	snake_case__				:  List[str]    					=			"tapas"




	def __init__( self			:				int			,			UpperCAmelCase__			:				Any=3_0_5_2_2			,			UpperCAmelCase__			:				Dict=7_6_8			,			UpperCAmelCase__			:				Optional[Any]=1_2			,			UpperCAmelCase__			:				Optional[int]=1_2			,			UpperCAmelCase__			:				Any=3_0_7_2			,			UpperCAmelCase__			:				List[Any]="gelu"			,			UpperCAmelCase__			:				List[Any]=0.1			,			UpperCAmelCase__			:				List[str]=0.1			,			UpperCAmelCase__			:				str=1_0_2_4			,			UpperCAmelCase__			:				Dict=[3, 2_5_6, 2_5_6, 2, 2_5_6, 2_5_6, 1_0]			,			UpperCAmelCase__			:				Union[str, Any]=0.02			,			UpperCAmelCase__			:				Tuple=1E-12			,			UpperCAmelCase__			:				Any=0			,			UpperCAmelCase__			:				Any=10.0			,			UpperCAmelCase__			:				Dict=0			,			UpperCAmelCase__			:				str=1.0			,			UpperCAmelCase__			:				Union[str, Any]=None			,			UpperCAmelCase__			:				str=1.0			,			UpperCAmelCase__			:				Union[str, Any]=False			,			UpperCAmelCase__			:				Optional[int]=None			,			UpperCAmelCase__			:				Tuple=1.0			,			UpperCAmelCase__			:				Any=1.0			,			UpperCAmelCase__			:				Optional[int]=False			,			UpperCAmelCase__			:				str=False			,			UpperCAmelCase__			:				List[str]="ratio"			,			UpperCAmelCase__			:				Union[str, Any]=None			,			UpperCAmelCase__			:				List[Any]=None			,			UpperCAmelCase__			:				Optional[int]=6_4			,			UpperCAmelCase__			:				Any=3_2			,			UpperCAmelCase__			:				Optional[Any]=False			,			UpperCAmelCase__			:				List[Any]=True			,			UpperCAmelCase__			:				List[str]=False			,			UpperCAmelCase__			:				int=False			,			UpperCAmelCase__			:				Any=True			,			UpperCAmelCase__			:				List[Any]=False			,			UpperCAmelCase__			:				Optional[int]=None			,			UpperCAmelCase__			:				Any=None			,			**UpperCAmelCase__			:				Optional[int]			,			)       ->	List[str]:
						super().__init__(pad_token_id=UpperCAmelCase__			,			**UpperCAmelCase__   )

						# BERT hyperparameters (with updated max_position_embeddings and type_vocab_sizes)
						__SCREAMING_SNAKE_CASE						   =				vocab_size
						__SCREAMING_SNAKE_CASE						   =				hidden_size
						__SCREAMING_SNAKE_CASE						   =				num_hidden_layers
						__SCREAMING_SNAKE_CASE						   =				num_attention_heads
						__SCREAMING_SNAKE_CASE						   =				hidden_act
						__SCREAMING_SNAKE_CASE						   =				intermediate_size
						__SCREAMING_SNAKE_CASE						   =				hidden_dropout_prob
						__SCREAMING_SNAKE_CASE						   =				attention_probs_dropout_prob
						__SCREAMING_SNAKE_CASE						   =				max_position_embeddings
						__SCREAMING_SNAKE_CASE						   =				type_vocab_sizes
						__SCREAMING_SNAKE_CASE						   =				initializer_range
						__SCREAMING_SNAKE_CASE						   =				layer_norm_eps

						# Fine-tuning task hyperparameters
						__SCREAMING_SNAKE_CASE						   =				positive_label_weight
						__SCREAMING_SNAKE_CASE						   =				num_aggregation_labels
						__SCREAMING_SNAKE_CASE						   =				aggregation_loss_weight
						__SCREAMING_SNAKE_CASE						   =				use_answer_as_supervision
						__SCREAMING_SNAKE_CASE						   =				answer_loss_importance
						__SCREAMING_SNAKE_CASE						   =				use_normalized_answer_loss
						__SCREAMING_SNAKE_CASE						   =				huber_loss_delta
						__SCREAMING_SNAKE_CASE						   =				temperature
						__SCREAMING_SNAKE_CASE						   =				aggregation_temperature
						__SCREAMING_SNAKE_CASE						   =				use_gumbel_for_cells
						__SCREAMING_SNAKE_CASE						   =				use_gumbel_for_aggregation
						__SCREAMING_SNAKE_CASE						   =				average_approximation_function
						__SCREAMING_SNAKE_CASE						   =				cell_selection_preference
						__SCREAMING_SNAKE_CASE						   =				answer_loss_cutoff
						__SCREAMING_SNAKE_CASE						   =				max_num_rows
						__SCREAMING_SNAKE_CASE						   =				max_num_columns
						__SCREAMING_SNAKE_CASE						   =				average_logits_per_cell
						__SCREAMING_SNAKE_CASE						   =				select_one_column
						__SCREAMING_SNAKE_CASE						   =				allow_empty_column_selection
						__SCREAMING_SNAKE_CASE						   =				init_cell_selection_weights_to_zero
						__SCREAMING_SNAKE_CASE						   =				reset_position_index_per_cell
						__SCREAMING_SNAKE_CASE						   =				disable_per_token_loss

						# Aggregation hyperparameters
						__SCREAMING_SNAKE_CASE						   =				aggregation_labels
						__SCREAMING_SNAKE_CASE						   =				no_aggregation_label_index

						if isinstance(self.aggregation_labels			,			UpperCAmelCase__   ):
											__SCREAMING_SNAKE_CASE						   =				{int(UpperCAmelCase__   ): v for k, v in aggregation_labels.items()}




"""simple docstring"""







import unittest

from transformers.testing_utils import CaptureStdout
from transformers.tools.python_interpreter import evaluate




def    UpperCAmelCase__       (lowerCAmelCase_   ):




					'''simple docstring'''


					return x + 2




class  UpperCamelCase_	( unittest.TestCase):

	"""simple docstring"""





	def   UpperCAmelCase_      ( self			:				Any   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"x = 3"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3}   )

						__SCREAMING_SNAKE_CASE						   =				"x = y"
						__SCREAMING_SNAKE_CASE						   =				{"y": 5}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 5, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Dict   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"y = add_two(x)"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )

						# Won't work without the tool
						with CaptureStdout() as out:
											__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result is None
						assert "tried to execute add_two" in out.out




	def   UpperCAmelCase_      ( self			:				List[Any]   )       ->	List[Any]:
						__SCREAMING_SNAKE_CASE						   =				"x = 3"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3}   )




	def   UpperCAmelCase_      ( self			:				str   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"test_dict = {'x': x, 'y': add_two(x)}"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_dict": {"x": 3, "y": 5}}   )




	def   UpperCAmelCase_      ( self			:				int   )       ->	Optional[Any]:
						__SCREAMING_SNAKE_CASE						   =				"x = 3\ny = 5"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	Any:
						__SCREAMING_SNAKE_CASE						   =				"text = f'This is x: {x}.'"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == "This is x: 3."
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "text": "This is x: 3."}   )




	def   UpperCAmelCase_      ( self			:				Union[str, Any]   )       ->	Optional[int]:
						__SCREAMING_SNAKE_CASE						   =				"if x <= 3:\n    y = 2\nelse:\n    y = 5"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 2
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 2}   )

						__SCREAMING_SNAKE_CASE						   =				{"x": 8}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						# evaluate returns the value of the last assignment.
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 8, "y": 5}   )




	def   UpperCAmelCase_      ( self			:				Tuple   )       ->	str:
						__SCREAMING_SNAKE_CASE						   =				"test_list = [x, add_two(x)]"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						self.assertListEqual(UpperCAmelCase__			,			[3, 5]   )
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_list": [3, 5]}   )




	def   UpperCAmelCase_      ( self			:				Any   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				"y = x"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{}			,			state=UpperCAmelCase__   )
						assert result == 3
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "y": 3}   )




	def   UpperCAmelCase_      ( self			:				Tuple   )       ->	int:
						__SCREAMING_SNAKE_CASE						   =				"test_list = [x, add_two(x)]\ntest_list[1]"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_list": [3, 5]}   )

						__SCREAMING_SNAKE_CASE						   =				"test_dict = {'x': x, 'y': add_two(x)}\ntest_dict['y']"
						__SCREAMING_SNAKE_CASE						   =				{"x": 3}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"add_two": add_two}			,			state=UpperCAmelCase__   )
						assert result == 5
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 3, "test_dict": {"x": 3, "y": 5}}   )




	def   UpperCAmelCase_      ( self			:				List[str]   )       ->	List[str]:
						__SCREAMING_SNAKE_CASE						   =				"x = 0\nfor i in range(3):\n    x = i"
						__SCREAMING_SNAKE_CASE						   =				{}
						__SCREAMING_SNAKE_CASE						   =				evaluate(UpperCAmelCase__			,			{"range": range}			,			state=UpperCAmelCase__   )
						assert result == 2
						self.assertDictEqual(UpperCAmelCase__			,			{"x": 2, "i": 2}   )
