


'''simple docstring'''

import datasets


a_						:       Union[str, 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_						:       Union[str, 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_						:       Tuple      			=				"""
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 __snake_case      (   UpperCAmelCase_		:		List[Any]      ,       UpperCAmelCase_		:		Union[str, Any]	):
 return (preds == labels).mean()







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





  """simple docstring"""




  def 						snake_case	(					self  ):







   """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 						snake_case	(					self    ,						UpperCamelCase    ,						UpperCamelCase  ):







   """simple docstring"""
   return {"accuracy": simple_accuracy(UpperCamelCase    ,						UpperCamelCase  )}







'''simple docstring'''

from dataclasses import dataclass
from typing import Optional, Tuple

import torch
from torch import nn
from transformers import RobertaPreTrainedModel, XLMRobertaConfig, XLMRobertaModel
from transformers.utils import ModelOutput





@dataclass
class   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						None
  _lowerCamelCase						=						None
  _lowerCamelCase						=						None
  _lowerCamelCase						=						None





class   snake_case					(					lowercase    ):





  """simple docstring"""




  def __init__(					self    ,						UpperCamelCase=1    ,						UpperCamelCase=0    ,						UpperCamelCase=2    ,						UpperCamelCase=512    ,						UpperCamelCase="cls"    ,						UpperCamelCase=False    ,						UpperCamelCase=True    ,						**UpperCamelCase    ,						):







   """simple docstring"""
   super().__init__(pad_token_id=UpperCamelCase    ,						bos_token_id=UpperCamelCase    ,						eos_token_id=UpperCamelCase    ,						**UpperCamelCase  )
   lowerCamelCase_  				=						project_dim
   lowerCamelCase_  				=						pooler_fn
   lowerCamelCase_  				=						learn_encoder
   lowerCamelCase_  				=						use_attention_mask





class   snake_case					(					lowercase    ):





  """simple docstring"""




  _lowerCamelCase						=						[r"pooler", r"logit_scale"]
  _lowerCamelCase						=						[r"position_ids", r"predictions.decoder.bias"]
  _lowerCamelCase						=						"roberta"
  _lowerCamelCase						=						RobertaSeriesConfig






  def __init__(					self    ,						UpperCamelCase  ):







   """simple docstring"""
   super().__init__(UpperCamelCase  )
   lowerCamelCase_  				=						XLMRobertaModel(UpperCamelCase  )
   lowerCamelCase_  				=						nn.Linear(config.hidden_size    ,						config.project_dim  )
   lowerCamelCase_  				=						getattr(UpperCamelCase    ,						"has_pre_transformation"    ,						UpperCamelCase  )
   if self.has_pre_transformation:
    lowerCamelCase_  				=						nn.Linear(config.hidden_size    ,						config.project_dim  )
    lowerCamelCase_  				=						nn.LayerNorm(config.hidden_size    ,						eps=config.layer_norm_eps  )
   self.post_init()







  def 						snake_case	(					self    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						UpperCamelCase = None    ,						):







   """simple docstring"""
   lowerCamelCase_  				=						return_dict if return_dict is not None else self.config.use_return_dict

   lowerCamelCase_  				=						self.base_model(
       input_ids=UpperCamelCase    ,						attention_mask=UpperCamelCase    ,						token_type_ids=UpperCamelCase    ,						position_ids=UpperCamelCase    ,						head_mask=UpperCamelCase    ,						inputs_embeds=UpperCamelCase    ,						encoder_hidden_states=UpperCamelCase    ,						encoder_attention_mask=UpperCamelCase    ,						output_attentions=UpperCamelCase    ,						output_hidden_states=True if self.has_pre_transformation else output_hidden_states    ,						return_dict=UpperCamelCase    ,						)

   if self.has_pre_transformation:
    lowerCamelCase_  				=						outputs["hidden_states"][-2]
    lowerCamelCase_  				=						self.pre_LN(UpperCamelCase  )
    lowerCamelCase_  				=						self.transformation_pre(UpperCamelCase  )

    return TransformationModelOutput(
        projection_state=UpperCamelCase    ,						last_hidden_state=outputs.last_hidden_state    ,						hidden_states=outputs.hidden_states    ,						attentions=outputs.attentions    ,						)
   else:
    lowerCamelCase_  				=						self.transformation(outputs.last_hidden_state  )
    return TransformationModelOutput(
        projection_state=UpperCamelCase    ,						last_hidden_state=outputs.last_hidden_state    ,						hidden_states=outputs.hidden_states    ,						attentions=outputs.attentions    ,						)



