

'''simple docstring'''






import os
from shutil import copyfile
from typing import List, Optional, Tuple

from ...tokenization_utils import AddedToken
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import is_sentencepiece_available, logging


if is_sentencepiece_available():
 from .tokenization_big_bird import BigBirdTokenizer
else:
 lowerCAmelCase__      		=			None

lowerCAmelCase__      		=			logging.get_logger(__name__)
lowerCAmelCase__      		=			{'''vocab_file''': '''spiece.model''', '''tokenizer_file''': '''tokenizer.json'''}

lowerCAmelCase__      		=			{
    '''vocab_file''': {
        '''google/bigbird-roberta-base''': '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/spiece.model''',
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/spiece.model'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/spiece.model'''
        ),
    },
    '''tokenizer_file''': {
        '''google/bigbird-roberta-base''': (
            '''https://huggingface.co/google/bigbird-roberta-base/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-roberta-large''': (
            '''https://huggingface.co/google/bigbird-roberta-large/resolve/main/tokenizer.json'''
        ),
        '''google/bigbird-base-trivia-itc''': (
            '''https://huggingface.co/google/bigbird-base-trivia-itc/resolve/main/tokenizer.json'''
        ),
    },
}

lowerCAmelCase__      		=			{
    '''google/bigbird-roberta-base''': 4096,
    '''google/bigbird-roberta-large''': 4096,
    '''google/bigbird-base-trivia-itc''': 4096,
}


lowerCAmelCase__      		=			'''▁'''






class     lowercase_			(lowerCamelCase__   ):




  """simple docstring"""




  SCREAMING_SNAKE_CASE					:						Dict           =    VOCAB_FILES_NAMES
  SCREAMING_SNAKE_CASE					:						Any           =    PRETRAINED_VOCAB_FILES_MAP
  SCREAMING_SNAKE_CASE					:						Tuple           =    PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
  SCREAMING_SNAKE_CASE					:						Dict           =    BigBirdTokenizer
  SCREAMING_SNAKE_CASE					:						Tuple           =    ['input_ids', 'attention_mask']
  SCREAMING_SNAKE_CASE					:						List[int]           =    []






  def __init__(   self     :  List[str]      ,lowercase__     :  Optional[int]=None      ,lowercase__     :  Any=None      ,lowercase__     :  Optional[Any]="<unk>"      ,lowercase__     :  List[Any]="<s>"      ,lowercase__     :  Any="</s>"      ,lowercase__     :  str="<pad>"      ,lowercase__     :  Optional[int]="[SEP]"      ,lowercase__     :  Optional[Any]="[MASK]"      ,lowercase__     :  List[str]="[CLS]"      ,**lowercase__     :  List[Any]      ,):
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else bos_token
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else eos_token
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else unk_token
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else pad_token
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else cls_token
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else sep_token

   # Mask token behave like a normal word, i.e. include the space before it
   __lowercase													=				AddedToken(lowercase__      ,lstrip=lowercase__      ,rstrip=lowercase__    ) if isinstance(lowercase__      ,lowercase__    ) else mask_token

   super().__init__(
       lowercase__      ,tokenizer_file=lowercase__      ,bos_token=lowercase__      ,eos_token=lowercase__      ,unk_token=lowercase__      ,sep_token=lowercase__      ,pad_token=lowercase__      ,cls_token=lowercase__      ,mask_token=lowercase__      ,**lowercase__      ,)

   __lowercase													=				vocab_file
   __lowercase													=				False if not self.vocab_file else True






  def       SCREAMING_SNAKE_CASE   (   self     :  Dict      ,lowercase__     :  List[int]      ,lowercase__     :  Optional[List[int]] = None    ):
   __lowercase													=				[self.sep_token_id]
   __lowercase													=				[self.cls_token_id]
   if token_ids_a is None:
    return cls + token_ids_a + sep
   return cls + token_ids_a + sep + token_ids_a + sep






  def       SCREAMING_SNAKE_CASE   (   self     :  Tuple      ,lowercase__     :  List[int]      ,lowercase__     :  Optional[List[int]] = None      ,lowercase__     :  bool = False    ):

   if already_has_special_tokens:
    if token_ids_a is not None:
     raise ValueError(
         '''You should not supply a second sequence if the provided sequence of '''
         '''ids is already formatted with special tokens for the model.'''    )
    return [1 if x in [self.sep_token_id, self.cls_token_id] else 0 for x in token_ids_a]

   if token_ids_a is None:
    return [1] + ([0] * len(lowercase__    )) + [1]
   return [1] + ([0] * len(lowercase__    )) + [1] + ([0] * len(lowercase__    )) + [1]






  def       SCREAMING_SNAKE_CASE   (   self     :  int      ,lowercase__     :  List[int]      ,lowercase__     :  Optional[List[int]] = None    ):
   __lowercase													=				[self.sep_token_id]
   __lowercase													=				[self.cls_token_id]

   if token_ids_a is None:
    return len(cls + token_ids_a + sep    ) * [0]
   return len(cls + token_ids_a + sep    ) * [0] + len(token_ids_a + sep    ) * [1]






  def       SCREAMING_SNAKE_CASE   (   self     :  str      ,lowercase__     :  str      ,lowercase__     :  Optional[str] = None    ):
   if not self.can_save_slow_tokenizer:
    raise ValueError(
        '''Your fast tokenizer does not have the necessary information to save the vocabulary for a slow '''
        '''tokenizer.'''    )

   if not os.path.isdir(lowercase__    ):
    logger.error(F"Vocabulary path ({save_directory}) should be a directory"    )
    return
   __lowercase													=				os.path.join(
       lowercase__      ,(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']    )

   if os.path.abspath(self.vocab_file    ) != os.path.abspath(lowercase__    ):
    copyfile(self.vocab_file      ,lowercase__    )

   return (out_vocab_file,)




'''simple docstring'''






from scipy.stats import spearmanr

import datasets


lowerCAmelCase__      		=			'''
The Spearman rank-order correlation coefficient is a measure of the
relationship between two datasets. Like other correlation coefficients,
this one varies between -1 and +1 with 0 implying no correlation.
Positive correlations imply that as data in dataset x increases, so
does data in dataset y. Negative correlations imply that as x increases,
y decreases. Correlations of -1 or +1 imply an exact monotonic relationship.

Unlike the Pearson correlation, the Spearman correlation does not
assume that both datasets are normally distributed.

The p-value roughly indicates the probability of an uncorrelated system
producing datasets that have a Spearman correlation at least as extreme
as the one computed from these datasets. The p-values are not entirely
reliable but are probably reasonable for datasets larger than 500 or so.
'''

lowerCAmelCase__      		=			'''
Args:
    predictions (`List[float]`): Predicted labels, as returned by a model.
    references (`List[float]`): Ground truth labels.
    return_pvalue (`bool`): If `True`, returns the p-value. If `False`, returns
            only the spearmanr score. Defaults to `False`.
Returns:
    spearmanr (`float`): Spearman correlation coefficient.
    p-value (`float`): p-value. **Note**: is only returned if `return_pvalue=True` is input.
Examples:
    Example 1:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5], predictions=[10, 9, 2.5, 6, 4])
        >>> print(results)
        {\'spearmanr\': -0.7}

    Example 2:
        >>> spearmanr_metric = datasets.load_metric("spearmanr")
        >>> results = spearmanr_metric.compute(references=[1, 2, 3, 4, 5],
        ...                                     predictions=[10, 9, 2.5, 6, 4],
        ...                                     return_pvalue=True)
        >>> print(results[\'spearmanr\'])
        -0.7
        >>> print(round(results[\'spearmanr_pvalue\'], 2))
        0.19
'''

lowerCAmelCase__      		=			R'''\
@book{kokoska2000crc,
  title={CRC standard probability and statistics tables and formulae},
  author={Kokoska, Stephen and Zwillinger, Daniel},
  year={2000},
  publisher={Crc Press}
}
@article{2020SciPy-NMeth,
  author  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and
            Haberland, Matt and Reddy, Tyler and Cournapeau, David and
            Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and
            Bright, Jonathan and {van der Walt}, St{\'e}fan J. and
            Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and
            Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and
            Kern, Robert and Larson, Eric and Carey, C J and
            Polat, {\.I}lhan and Feng, Yu and Moore, Eric W. and
            {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and
            Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and
            Harris, Charles R. and Archibald, Anne M. and
            Ribeiro, Ant{\^o}nio H. and Pedregosa, Fabian and
            {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},
  title   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific
            Computing in Python}},
  journal = {Nature Methods},
  year    = {2020},
  volume  = {17},
  pages   = {261--272},
  adsurl  = {https://rdcu.be/b08Wh},
  doi     = {10.1038/s41592-019-0686-2},
}
'''






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




  """simple docstring"""




  def       SCREAMING_SNAKE_CASE   (   self     :  Optional[int]    ):
   return datasets.MetricInfo(
       description=_DESCRIPTION      ,citation=_CITATION      ,inputs_description=_KWARGS_DESCRIPTION      ,features=datasets.Features(
           {
               '''predictions''': datasets.Value('''float'''    ),
               '''references''': datasets.Value('''float'''    ),
           }    )      ,reference_urls=['''https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html''']      ,)






  def       SCREAMING_SNAKE_CASE   (   self     :  Tuple      ,lowercase__     :  List[Any]      ,lowercase__     :  List[Any]      ,lowercase__     :  Union[str, Any]=False    ):
   __lowercase													=				spearmanr(lowercase__      ,lowercase__    )
   if return_pvalue:
    return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
   else:
    return {"spearmanr": results[0]}

