"""simple docstring"""


import unicodedata
from dataclasses import dataclass
from typing import Optional, Union

import numpy as np

from transformers.data.data_collator import DataCollatorMixin
from transformers.file_utils import PaddingStrategy
from transformers.tokenization_utils_base import PreTrainedTokenizerBase






def     __UpperCAmelCase					(			lowercase   ,lowercase   ,lowercase   ,lowercase		):







  """simple docstring"""
  if isinstance(lowercase   ,lowercase		):
    _UpperCAmelCase						 =      np.full((len(lowercase		), sequence_length, 2)   ,lowercase		)
  else:
    _UpperCAmelCase						 =      np.full((len(lowercase		), sequence_length)   ,lowercase		)

  for i, tensor in enumerate(lowercase		):
    if padding_side == "right":
      if isinstance(lowercase   ,lowercase		):
        _UpperCAmelCase						 =      tensor[:sequence_length]
      else:
        _UpperCAmelCase						 =      tensor[:sequence_length]
    else:
      if isinstance(lowercase   ,lowercase		):
        _UpperCAmelCase						 =      tensor[:sequence_length]
      else:
        _UpperCAmelCase						 =      tensor[:sequence_length]

  return out_tensor.tolist()






def     __UpperCAmelCase					(			lowercase		):







  """simple docstring"""
  _UpperCAmelCase						 =      ord(lowercase		)
  if (cp >= 33 and cp <= 47) or (cp >= 58 and cp <= 64) or (cp >= 91 and cp <= 96) or (cp >= 1_23 and cp <= 1_26):
    return True
  _UpperCAmelCase						 =      unicodedata.category(lowercase		)
  if cat.startswith("""P"""		):
    return True
  return False


@dataclass
class        a				(		lowerCAmelCase_   ):
    _snake_case     :  PreTrainedTokenizerBase
    _snake_case     :  Union[bool, str, PaddingStrategy]     							=							True
    _snake_case     :  Optional[int]     							=							None
    _snake_case     :  Optional[int]     							=							None
    _snake_case     :  int     							=							-1_00
    _snake_case     :  str     							=							"pt"


    def      lowerCAmelCase_  (					self	:  Dict   ,				__lowerCAmelCase	:  int					):
      import torch

      _UpperCAmelCase						 =      """label""" if """label""" in features[0].keys() else """labels"""
      _UpperCAmelCase						 =      [feature[label_name] for feature in features] if label_name in features[0].keys() else None
      _UpperCAmelCase						 =      self.tokenizer.pad(
          __lowerCAmelCase   ,				padding=self.padding   ,				max_length=self.max_length   ,				pad_to_multiple_of=self.pad_to_multiple_of   ,				return_tensors="""pt""" if labels is None else None   ,				)

      if labels is None:
        return batch

      _UpperCAmelCase						 =      torch.tensor(batch["""entity_ids"""]					).shape[1]
      _UpperCAmelCase						 =      self.tokenizer.padding_side
      if padding_side == "right":
        _UpperCAmelCase						 =      [
            list(__lowerCAmelCase					) + [self.label_pad_token_id] * (sequence_length - len(__lowerCAmelCase					)) for label in labels
        ]
      else:
        _UpperCAmelCase						 =      [
            [self.label_pad_token_id] * (sequence_length - len(__lowerCAmelCase					)) + list(__lowerCAmelCase					) for label in labels
        ]

      _UpperCAmelCase						 =      [feature["""ner_tags"""] for feature in features]
      _UpperCAmelCase						 =      padding_tensor(__lowerCAmelCase   ,				-1   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)
      _UpperCAmelCase						 =      [feature["""original_entity_spans"""] for feature in features]
      _UpperCAmelCase						 =      padding_tensor(__lowerCAmelCase   ,				(-1, -1)   ,				__lowerCAmelCase   ,				__lowerCAmelCase					)
      _UpperCAmelCase						 =      {k: torch.tensor(__lowerCAmelCase   ,				dtype=torch.intaa					) for k, v in batch.items()}

      return batch

"""simple docstring"""


import datasets


UpperCAmelCase__  		=						"""\
@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\",
}
"""

UpperCAmelCase__  		=						"""\
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).
"""

UpperCAmelCase__  		=						"""
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        a				(		datasets.Metric   ):


    def      lowerCAmelCase_  (					self	:  Union[str, Any]					):
      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      lowerCAmelCase_  (					self	:  List[str]   ,				__lowerCAmelCase	:  int   ,				__lowerCAmelCase	:  Any					):
      return {"accuracy": simple_accuracy(__lowerCAmelCase   ,				__lowerCAmelCase					)}
