




from ...configuration_utils import PretrainedConfig


_lowerCamelCase      :  Optional[Any]      						=						{
    "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        __snake_case  (_a		):
				lowerCAmelCase__				=     "tapas"



				def __init__(      self      :		Dict		,	_UpperCAmelCase      :		Dict=3_0522		,	_UpperCAmelCase      :		List[str]=768		,	_UpperCAmelCase      :		int=12		,	_UpperCAmelCase      :		Any=12		,	_UpperCAmelCase      :		Any=3072		,	_UpperCAmelCase      :		Optional[Any]="gelu"		,	_UpperCAmelCase      :		str=0.1		,	_UpperCAmelCase      :		List[Any]=0.1		,	_UpperCAmelCase      :		List[str]=1024		,	_UpperCAmelCase      :		Optional[int]=[3, 256, 256, 2, 256, 256, 10]		,	_UpperCAmelCase      :		Union[str, Any]=0.02		,	_UpperCAmelCase      :		List[str]=1E-12		,	_UpperCAmelCase      :		Optional[Any]=0		,	_UpperCAmelCase      :		List[Any]=10.0		,	_UpperCAmelCase      :		Any=0		,	_UpperCAmelCase      :		int=1.0		,	_UpperCAmelCase      :		Optional[Any]=None		,	_UpperCAmelCase      :		str=1.0		,	_UpperCAmelCase      :		Any=False		,	_UpperCAmelCase      :		Dict=None		,	_UpperCAmelCase      :		Any=1.0		,	_UpperCAmelCase      :		int=1.0		,	_UpperCAmelCase      :		Dict=False		,	_UpperCAmelCase      :		Optional[Any]=False		,	_UpperCAmelCase      :		Any="ratio"		,	_UpperCAmelCase      :		str=None		,	_UpperCAmelCase      :		Any=None		,	_UpperCAmelCase      :		List[str]=64		,	_UpperCAmelCase      :		str=32		,	_UpperCAmelCase      :		Tuple=False		,	_UpperCAmelCase      :		Any=True		,	_UpperCAmelCase      :		str=False		,	_UpperCAmelCase      :		int=False		,	_UpperCAmelCase      :		str=True		,	_UpperCAmelCase      :		int=False		,	_UpperCAmelCase      :		Tuple=None		,	_UpperCAmelCase      :		List[str]=None		,	**_UpperCAmelCase      :		List[str]		,	)  ->    List[str]:





								'''simple docstring'''




								super().__init__(pad_token_id=_UpperCAmelCase		,	**_UpperCAmelCase      )

								# BERT hyperparameters (with updated max_position_embeddings and type_vocab_sizes)
								_lowerCAmelCase    :    Any										=      vocab_size
								_lowerCAmelCase    :    List[str]										=      hidden_size
								_lowerCAmelCase    :    List[Any]										=      num_hidden_layers
								_lowerCAmelCase    :    Tuple										=      num_attention_heads
								_lowerCAmelCase    :    int										=      hidden_act
								_lowerCAmelCase    :    Dict										=      intermediate_size
								_lowerCAmelCase    :    Any										=      hidden_dropout_prob
								_lowerCAmelCase    :    Optional[Any]										=      attention_probs_dropout_prob
								_lowerCAmelCase    :    Dict										=      max_position_embeddings
								_lowerCAmelCase    :    List[Any]										=      type_vocab_sizes
								_lowerCAmelCase    :    Optional[int]										=      initializer_range
								_lowerCAmelCase    :    Optional[Any]										=      layer_norm_eps

								# Fine-tuning task hyperparameters
								_lowerCAmelCase    :    Optional[Any]										=      positive_label_weight
								_lowerCAmelCase    :    Optional[Any]										=      num_aggregation_labels
								_lowerCAmelCase    :    List[str]										=      aggregation_loss_weight
								_lowerCAmelCase    :    Union[str, Any]										=      use_answer_as_supervision
								_lowerCAmelCase    :    List[str]										=      answer_loss_importance
								_lowerCAmelCase    :    Optional[Any]										=      use_normalized_answer_loss
								_lowerCAmelCase    :    str										=      huber_loss_delta
								_lowerCAmelCase    :    int										=      temperature
								_lowerCAmelCase    :    str										=      aggregation_temperature
								_lowerCAmelCase    :    Tuple										=      use_gumbel_for_cells
								_lowerCAmelCase    :    Any										=      use_gumbel_for_aggregation
								_lowerCAmelCase    :    Dict										=      average_approximation_function
								_lowerCAmelCase    :    Dict										=      cell_selection_preference
								_lowerCAmelCase    :    Optional[int]										=      answer_loss_cutoff
								_lowerCAmelCase    :    List[str]										=      max_num_rows
								_lowerCAmelCase    :    str										=      max_num_columns
								_lowerCAmelCase    :    Optional[Any]										=      average_logits_per_cell
								_lowerCAmelCase    :    List[str]										=      select_one_column
								_lowerCAmelCase    :    str										=      allow_empty_column_selection
								_lowerCAmelCase    :    Dict										=      init_cell_selection_weights_to_zero
								_lowerCAmelCase    :    Dict										=      reset_position_index_per_cell
								_lowerCAmelCase    :    Optional[Any]										=      disable_per_token_loss

								# Aggregation hyperparameters
								_lowerCAmelCase    :    List[str]										=      aggregation_labels
								_lowerCAmelCase    :    int										=      no_aggregation_label_index

								if isinstance(self.aggregation_labels		,	_UpperCAmelCase      ):
												_lowerCAmelCase    :    Any										=      {int(_UpperCAmelCase      ): v for k, v in aggregation_labels.items()}







from __future__ import annotations

from decimal import Decimal

from numpy import array




def 							_UpperCAmelCase  (UpperCamelCase_ : list[list[float]]       ):
				'''simple docstring'''
				_lowerCAmelCase    :    int										=      Decimal

				# Check if the provided matrix has 2 rows and 2 columns
				# since this implementation only works for 2x2 matrices
				if len(UpperCamelCase_       ) == 2 and len(matrix[0]       ) == 2 and len(matrix[1]       ) == 2:
								# Calculate the determinant of the matrix
								_lowerCAmelCase    :    Optional[Any]										=      float(
								    d(matrix[0][0]       ) * d(matrix[1][1]       ) - d(matrix[1][0]       ) * d(matrix[0][1]       )       )
								if determinant == 0:
												raise ValueError("""This matrix has no inverse."""       )

								# Creates a copy of the matrix with swapped positions of the elements
								_lowerCAmelCase    :    Union[str, Any]										=      [[0.0, 0.0], [0.0, 0.0]]
								_lowerCAmelCase					,    _lowerCAmelCase    :    Any										=      matrix[1][1], matrix[0][0]
								_lowerCAmelCase					,    _lowerCAmelCase    :    Optional[Any]										=      -matrix[1][0], -matrix[0][1]

								# Calculate the inverse of the matrix
								return [
								    [(float(d(UpperCamelCase_       )       ) / determinant) or 0.0 for n in row] for row in swapped_matrix
								]
				elif (
				    len(UpperCamelCase_       ) == 3
				    and len(matrix[0]       ) == 3
				    and len(matrix[1]       ) == 3
				    and len(matrix[2]       ) == 3
				):
								# Calculate the determinant of the matrix using Sarrus rule
								_lowerCAmelCase    :    List[str]										=      float(
								    (
								        (d(matrix[0][0]       ) * d(matrix[1][1]       ) * d(matrix[2][2]       ))
								        + (d(matrix[0][1]       ) * d(matrix[1][2]       ) * d(matrix[2][0]       ))
								        + (d(matrix[0][2]       ) * d(matrix[1][0]       ) * d(matrix[2][1]       ))
								    )
								    - (
								        (d(matrix[0][2]       ) * d(matrix[1][1]       ) * d(matrix[2][0]       ))
								        + (d(matrix[0][1]       ) * d(matrix[1][0]       ) * d(matrix[2][2]       ))
								        + (d(matrix[0][0]       ) * d(matrix[1][2]       ) * d(matrix[2][1]       ))
								    )       )
								if determinant == 0:
												raise ValueError("""This matrix has no inverse."""       )

								# Creating cofactor matrix
								_lowerCAmelCase    :    Optional[Any]										=      [
								    [d(0.0       ), d(0.0       ), d(0.0       )],
								    [d(0.0       ), d(0.0       ), d(0.0       )],
								    [d(0.0       ), d(0.0       ), d(0.0       )],
								]
								_lowerCAmelCase    :    Optional[Any]										=      (d(matrix[1][1]       ) * d(matrix[2][2]       )) - (
								    d(matrix[1][2]       ) * d(matrix[2][1]       )
								)
								_lowerCAmelCase    :    str										=      -(
								    (d(matrix[1][0]       ) * d(matrix[2][2]       )) - (d(matrix[1][2]       ) * d(matrix[2][0]       ))
								)
								_lowerCAmelCase    :    Any										=      (d(matrix[1][0]       ) * d(matrix[2][1]       )) - (
								    d(matrix[1][1]       ) * d(matrix[2][0]       )
								)
								_lowerCAmelCase    :    List[str]										=      -(
								    (d(matrix[0][1]       ) * d(matrix[2][2]       )) - (d(matrix[0][2]       ) * d(matrix[2][1]       ))
								)
								_lowerCAmelCase    :    Tuple										=      (d(matrix[0][0]       ) * d(matrix[2][2]       )) - (
								    d(matrix[0][2]       ) * d(matrix[2][0]       )
								)
								_lowerCAmelCase    :    Any										=      -(
								    (d(matrix[0][0]       ) * d(matrix[2][1]       )) - (d(matrix[0][1]       ) * d(matrix[2][0]       ))
								)
								_lowerCAmelCase    :    int										=      (d(matrix[0][1]       ) * d(matrix[1][2]       )) - (
								    d(matrix[0][2]       ) * d(matrix[1][1]       )
								)
								_lowerCAmelCase    :    Optional[Any]										=      -(
								    (d(matrix[0][0]       ) * d(matrix[1][2]       )) - (d(matrix[0][2]       ) * d(matrix[1][0]       ))
								)
								_lowerCAmelCase    :    Tuple										=      (d(matrix[0][0]       ) * d(matrix[1][1]       )) - (
								    d(matrix[0][1]       ) * d(matrix[1][0]       )
								)

								# Transpose the cofactor matrix (Adjoint matrix)
								_lowerCAmelCase    :    List[str]										=      array(UpperCamelCase_       )
								for i in range(3       ):
												for j in range(3       ):
																_lowerCAmelCase    :    List[Any]										=      cofactor_matrix[j][i]

        # Inverse of the matrix using the formula (1/determinant) * adjoint matrix
								_lowerCAmelCase    :    Tuple										=      array(UpperCamelCase_       )
								for i in range(3       ):
												for j in range(3       ):
																inverse_matrix[i][j] /= d(UpperCamelCase_       )

        # Calculate the inverse of the matrix
								return [[float(d(UpperCamelCase_       )       ) or 0.0 for n in row] for row in inverse_matrix]
				raise ValueError("""Please provide a matrix of size 2x2 or 3x3."""       )

