





from scipy.stats import spearmanr

import datasets


_lowerCAmelCase							:					Optional[int]		    =		"""
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							:					Union[str, Any]		    =		"""
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							:					Tuple		    =		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     __magic_name__     (							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("float"     ),
                    "references": datasets.Value("float"     ),
                }     )	,					reference_urls=["https://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.spearmanr.html"]	,					)





     def   SCREAMING_SNAKE_CASE						(							self				:Union[str, Any]	,					snake_case				:Dict	,					snake_case				:Tuple	,					snake_case				:int=False     ):





        '''simple docstring'''




        A_    : List[Any]								=	spearmanr(SCREAMING_SNAKE_CASE_	,					SCREAMING_SNAKE_CASE_     )
        if return_pvalue:
           return {"spearmanr": results[0], "spearmanr_pvalue": results[1]}
        else:
           return {"spearmanr": results[0]}





"""simple docstring"""







import json
from typing import TYPE_CHECKING, List, Optional, Tuple

from tokenizers import pre_tokenizers

from ...tokenization_utils_base import BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging


if TYPE_CHECKING:
     from transformers.pipelines.conversational import Conversation


lowercase__		:				Optional[Any]          =	logging.get_logger(__name__)

lowercase__		:				List[str]          =	{"""tokenizer_file""": """tokenizer.json"""}

lowercase__		:				List[str]          =	{
    """tokenizer_file""": {
        """bigscience/tokenizer""": """https://huggingface.co/bigscience/tokenizer/blob/main/tokenizer.json""",
        """bigscience/bloom-560m""": """https://huggingface.co/bigscience/bloom-560m/blob/main/tokenizer.json""",
        """bigscience/bloom-1b1""": """https://huggingface.co/bigscience/bloom-1b1/blob/main/tokenizer.json""",
        """bigscience/bloom-1b7""": """https://huggingface.co/bigscience/bloom-1b7/blob/main/tokenizer.json""",
        """bigscience/bloom-3b""": """https://huggingface.co/bigscience/bloom-3b/blob/main/tokenizer.json""",
        """bigscience/bloom-7b1""": """https://huggingface.co/bigscience/bloom-7b1/blob/main/tokenizer.json""",
        """bigscience/bloom""": """https://huggingface.co/bigscience/bloom/blob/main/tokenizer.json""",
    },
}







class       UpperCamelCase__   (	lowercase_  ):




      """simple docstring"""




      _SCREAMING_SNAKE_CASE  				=     VOCAB_FILES_NAMES
      _SCREAMING_SNAKE_CASE  				=     PRETRAINED_VOCAB_FILES_MAP
      _SCREAMING_SNAKE_CASE  				=     ["""input_ids""", """attention_mask"""]
      _SCREAMING_SNAKE_CASE  				=     None



      def __init__(      self				:      Union[str, Any]    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]=None    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]=None    ,			SCREAMING_SNAKE_CASE_				:      Tuple=None    ,			SCREAMING_SNAKE_CASE_				:      Optional[Any]="<unk>"    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]="<s>"    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]="</s>"    ,			SCREAMING_SNAKE_CASE_				:      Optional[int]="<pad>"    ,			SCREAMING_SNAKE_CASE_				:      List[str]=False    ,			SCREAMING_SNAKE_CASE_				:      Any=False    ,			**SCREAMING_SNAKE_CASE_				:      Any    ,			):
        super().__init__(
            SCREAMING_SNAKE_CASE_    ,			SCREAMING_SNAKE_CASE_    ,			tokenizer_file=SCREAMING_SNAKE_CASE_    ,			unk_token=SCREAMING_SNAKE_CASE_    ,			bos_token=SCREAMING_SNAKE_CASE_    ,			eos_token=SCREAMING_SNAKE_CASE_    ,			pad_token=SCREAMING_SNAKE_CASE_    ,			add_prefix_space=SCREAMING_SNAKE_CASE_    ,			clean_up_tokenization_spaces=SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_    ,			)
        lowerCAmelCase_   :				Optional[Any]								= json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()       )
        if pre_tok_state.get('add_prefix_space'    ,			SCREAMING_SNAKE_CASE_       ) != add_prefix_space:
          lowerCAmelCase_   :				str								= getattr(SCREAMING_SNAKE_CASE_    ,			pre_tok_state.pop('type'       )       )
          lowerCAmelCase_   :				str								= add_prefix_space
          lowerCAmelCase_   :				str								= pre_tok_class(**SCREAMING_SNAKE_CASE_       )

        lowerCAmelCase_   :				str								= add_prefix_space



      def      SCREAMING_SNAKE_CASE__ (      self				:      Any    ,			*SCREAMING_SNAKE_CASE_				:      List[Any]    ,			**SCREAMING_SNAKE_CASE_				:      Tuple       ):
        lowerCAmelCase_   :				List[Any]								= kwargs.get('is_split_into_words'    ,			SCREAMING_SNAKE_CASE_       )
        if not (self.add_prefix_space or not is_split_into_words):
          raise Exception(
              F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
              ' pretokenized inputs.'       )

        return super()._batch_encode_plus(*SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Any    ,			*SCREAMING_SNAKE_CASE_				:      Optional[int]    ,			**SCREAMING_SNAKE_CASE_				:      int       ):
        lowerCAmelCase_   :				List[Any]								= kwargs.get('is_split_into_words'    ,			SCREAMING_SNAKE_CASE_       )

        if not (self.add_prefix_space or not is_split_into_words):
          raise Exception(
              F"You need to instantiate {self.__class__.__name__} with add_prefix_space=True to use it with"
              ' pretokenized inputs.'       )

        return super()._encode_plus(*SCREAMING_SNAKE_CASE_    ,			**SCREAMING_SNAKE_CASE_       )



      def      SCREAMING_SNAKE_CASE__ (      self				:      Optional[Any]    ,			SCREAMING_SNAKE_CASE_				:      str    ,			SCREAMING_SNAKE_CASE_				:      Optional[str] = None       ):
        lowerCAmelCase_   :				Optional[int]								= self._tokenizer.model.save(SCREAMING_SNAKE_CASE_    ,			name=SCREAMING_SNAKE_CASE_       )
        return tuple(SCREAMING_SNAKE_CASE_       )





      def      SCREAMING_SNAKE_CASE__ (      self				:      int    ,			SCREAMING_SNAKE_CASE_				:      "Conversation"       ):
        lowerCAmelCase_   :				int								= []
        for is_user, text in conversation.iter_texts():
          input_ids.extend(self.encode(SCREAMING_SNAKE_CASE_    ,			add_special_tokens=SCREAMING_SNAKE_CASE_       ) + [self.eos_token_id]       )

        if len(SCREAMING_SNAKE_CASE_       ) > self.model_max_length:
          lowerCAmelCase_   :				Any								= input_ids[-self.model_max_length :]
        return input_ids





