
'''simple docstring'''



import copy
import os
from typing import TYPE_CHECKING, List, Union


if TYPE_CHECKING:
						pass

from ...configuration_utils import PretrainedConfig
from ...utils import logging


_lowercase          =						logging.get_logger(__name__)

_lowercase          =						{
    """kakaobrain/align-base""": """https://huggingface.co/kakaobrain/align-base/resolve/main/config.json""",
}




class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: Any										=  '''align_text_model'''




						def __init__(   self       ,  _lowercase=30_522       ,  _lowercase=768       ,  _lowercase=12       ,  _lowercase=12       ,  _lowercase=3_072       ,  _lowercase="gelu"       ,  _lowercase=0.1       ,  _lowercase=0.1       ,  _lowercase=512       ,  _lowercase=2       ,  _lowercase=0.02       ,  _lowercase=1e-12       ,  _lowercase=0       ,  _lowercase="absolute"       ,  _lowercase=True       ,  **_lowercase       ,  ):

												"""simple docstring"""



												super().__init__(**_lowercase )

												_lowerCAmelCase    		=					vocab_size
												_lowerCAmelCase    		=					hidden_size
												_lowerCAmelCase    		=					num_hidden_layers
												_lowerCAmelCase    		=					num_attention_heads
												_lowerCAmelCase    		=					hidden_act
												_lowerCAmelCase    		=					intermediate_size
												_lowerCAmelCase    		=					hidden_dropout_prob
												_lowerCAmelCase    		=					attention_probs_dropout_prob
												_lowerCAmelCase    		=					max_position_embeddings
												_lowerCAmelCase    		=					type_vocab_size
												_lowerCAmelCase    		=					initializer_range
												_lowerCAmelCase    		=					layer_norm_eps
												_lowerCAmelCase    		=					position_embedding_type
												_lowerCAmelCase    		=					use_cache
												_lowerCAmelCase    		=					pad_token_id




						@classmethod
						def    _lowercase      (   cls       ,  _lowercase       ,  **_lowercase ):

												"""simple docstring"""



												cls._set_token_in_kwargs(_lowercase )

												_lowerCAmelCase		,       _lowerCAmelCase    		=					cls.get_config_dict(_lowercase       ,  **_lowercase )

												# get the text config dict if we are loading from AlignConfig
												if config_dict.get("""model_type""" ) == "align":
																		_lowerCAmelCase    		=					config_dict["""text_config"""]

												if "model_type" in config_dict and hasattr(cls       ,  """model_type""" ) and config_dict["model_type"] != cls.model_type:
																		logger.warning(
																		    F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
																		    F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.' )

												return cls.from_dict(_lowercase       ,  **_lowercase )






class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: Optional[Any]										=  '''align_vision_model'''




						def __init__(   self       ,  _lowercase = 3       ,  _lowercase = 600       ,  _lowercase = 2.0       ,  _lowercase = 3.1       ,  _lowercase = 8       ,  _lowercase = [3, 3, 5, 3, 5, 5, 3]       ,  _lowercase = [32, 16, 24, 40, 80, 112, 192]       ,  _lowercase = [16, 24, 40, 80, 112, 192, 320]       ,  _lowercase = []       ,  _lowercase = [1, 2, 2, 2, 1, 2, 1]       ,  _lowercase = [1, 2, 2, 3, 3, 4, 1]       ,  _lowercase = [1, 6, 6, 6, 6, 6, 6]       ,  _lowercase = 0.25       ,  _lowercase = "swish"       ,  _lowercase = 2_560       ,  _lowercase = "mean"       ,  _lowercase = 0.02       ,  _lowercase = 0.001       ,  _lowercase = 0.99       ,  _lowercase = 0.2       ,  **_lowercase       ,  ):

												"""simple docstring"""



												super().__init__(**_lowercase )

												_lowerCAmelCase    		=					num_channels
												_lowerCAmelCase    		=					image_size
												_lowerCAmelCase    		=					width_coefficient
												_lowerCAmelCase    		=					depth_coefficient
												_lowerCAmelCase    		=					depth_divisor
												_lowerCAmelCase    		=					kernel_sizes
												_lowerCAmelCase    		=					in_channels
												_lowerCAmelCase    		=					out_channels
												_lowerCAmelCase    		=					depthwise_padding
												_lowerCAmelCase    		=					strides
												_lowerCAmelCase    		=					num_block_repeats
												_lowerCAmelCase    		=					expand_ratios
												_lowerCAmelCase    		=					squeeze_expansion_ratio
												_lowerCAmelCase    		=					hidden_act
												_lowerCAmelCase    		=					hidden_dim
												_lowerCAmelCase    		=					pooling_type
												_lowerCAmelCase    		=					initializer_range
												_lowerCAmelCase    		=					batch_norm_eps
												_lowerCAmelCase    		=					batch_norm_momentum
												_lowerCAmelCase    		=					drop_connect_rate
												_lowerCAmelCase    		=					sum(_lowercase ) * 4




						@classmethod
						def    _lowercase      (   cls       ,  _lowercase       ,  **_lowercase ):

												"""simple docstring"""



												cls._set_token_in_kwargs(_lowercase )

												_lowerCAmelCase		,       _lowerCAmelCase    		=					cls.get_config_dict(_lowercase       ,  **_lowercase )

												# get the vision config dict if we are loading from AlignConfig
												if config_dict.get("""model_type""" ) == "align":
																		_lowerCAmelCase    		=					config_dict["""vision_config"""]

												if "model_type" in config_dict and hasattr(cls       ,  """model_type""" ) and config_dict["model_type"] != cls.model_type:
																		logger.warning(
																		    F'You are using a model of type {config_dict["model_type"]} to instantiate a model of type '
																		    F'{cls.model_type}. This is not supported for all configurations of models and can yield errors.' )

												return cls.from_dict(_lowercase       ,  **_lowercase )






class     UpperCAmelCase_	(						_SCREAMING_SNAKE_CASE					):






						'''simple docstring'''






						_lowercase						: Tuple										=  '''align'''
						_lowercase						: Optional[int]										=  True




						def __init__(   self       ,  _lowercase=None       ,  _lowercase=None       ,  _lowercase=640       ,  _lowercase=1.0       ,  _lowercase=0.02       ,  **_lowercase       ,  ):

												"""simple docstring"""



												super().__init__(**_lowercase )

												if text_config is None:
																		_lowerCAmelCase    		=					{}
																		logger.info("""text_config is None. Initializing the AlignTextConfig with default values.""" )

												if vision_config is None:
																		_lowerCAmelCase    		=					{}
																		logger.info("""vision_config is None. Initializing the AlignVisionConfig with default values.""" )

												_lowerCAmelCase    		=					AlignTextConfig(**_lowercase )
												_lowerCAmelCase    		=					AlignVisionConfig(**_lowercase )

												_lowerCAmelCase    		=					projection_dim
												_lowerCAmelCase    		=					temperature_init_value
												_lowerCAmelCase    		=					initializer_range




						@classmethod
						def    _lowercase      (   cls       ,  _lowercase       ,  _lowercase       ,  **_lowercase ):

												"""simple docstring"""



												return cls(text_config=text_config.to_dict()       ,  vision_config=vision_config.to_dict()       ,  **_lowercase )




						def    _lowercase      (   self ):

												"""simple docstring"""



												_lowerCAmelCase    		=					copy.deepcopy(self.__dict__ )
												_lowerCAmelCase    		=					self.text_config.to_dict()
												_lowerCAmelCase    		=					self.vision_config.to_dict()
												_lowerCAmelCase    		=					self.__class__.model_type
												return output

import datasets


__a    :	Optional[Any]         =    """\
@InProceedings{conneau2018xnli,
  author = \"Conneau, Alexis
                 and Rinott, Ruty
                 and Lample, Guillaume
                 and Williams, Adina
                 and Bowman, Samuel R.
                 and Schwenk, Holger
                 and Stoyanov, Veselin\",
  title = \"XNLI: Evaluating Cross-lingual Sentence Representations\",
  booktitle = \"Proceedings of the 2018 Conference on Empirical Methods
               in Natural Language Processing\",
  year = \"2018\",
  publisher = \"Association for Computational Linguistics\",
  location = \"Brussels, Belgium\",
}
"""

__a    :	Optional[Any]         =    """\
XNLI is a subset of a few thousand examples from MNLI which has been translated
into a 14 different languages (some low-ish resource). As with MNLI, the goal is
to predict textual entailment (does sentence A imply/contradict/neither sentence
B) and is a classification task (given two sentences, predict one of three
labels).
"""

__a    :	str         =    """
Computes XNLI score which is just simple accuracy.
Args:
    predictions: Predicted labels.
    references: Ground truth labels.
Returns:
    'accuracy': accuracy
Examples:

    >>> predictions = [0, 1]
    >>> references = [0, 1]
    >>> xnli_metric = datasets.load_metric(\"xnli\")
    >>> results = xnli_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {'accuracy': 1.0}
"""





def 							UpperCAmelCase		(       lowercase				,     lowercase				):







				"""simple docstring"""



				return (preds == labels).mean()




@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION		,_KWARGS_DESCRIPTION					)
class   _UpperCamelCase (		datasets.Metric					):


			"""simple docstring"""






			def 			_SCREAMING_SNAKE_CASE     (  self		)	->   str:

							'''simple docstring'''


							return datasets.MetricInfo(
							    description=_DESCRIPTION ,  citation=_CITATION ,  inputs_description=_KWARGS_DESCRIPTION ,  features=datasets.Features(
							        {
							            '''predictions''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''		),
							            '''references''': datasets.Value('''int64''' if self.config_name != '''sts-b''' else '''float32'''		),
							        }		) ,  codebase_urls=[] ,  reference_urls=[] ,  format='''numpy''' ,  )





			def 			_SCREAMING_SNAKE_CASE     (  self ,  lowerCAmelCase__ ,  lowerCAmelCase__		)	->   Dict:

							'''simple docstring'''


							return {"accuracy": simple_accuracy(lowerCAmelCase__ ,  lowerCAmelCase__		)}