"""simple docstring"""






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

from tokenizers import pre_tokenizers, processors

from ...tokenization_utils_base import AddedToken, BatchEncoding
from ...tokenization_utils_fast import PreTrainedTokenizerFast
from ...utils import logging
from .tokenization_blenderbot import BlenderbotTokenizer


if TYPE_CHECKING:
       from transformers.pipelines.conversational import Conversation

__lowerCAmelCase    :       List[str]					     =logging.get_logger(__name__)


__lowerCAmelCase    :       Dict					     ={
    """vocab_file""": """vocab.json""",
    """merges_file""": """merges.txt""",
    """tokenizer_config_file""": """tokenizer_config.json""",
}

__lowerCAmelCase    :       Optional[Any]					     ={
    """vocab_file""": {"""facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/vocab.json"""},
    """merges_file""": {"""facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/merges.txt"""},
    """tokenizer_config_file""": {
        """facebook/blenderbot-3B""": """https://huggingface.co/facebook/blenderbot-3B/resolve/main/tokenizer_config.json"""
    },
}

__lowerCAmelCase    :       Dict					     ={"""facebook/blenderbot-3B""": 1_2_8}





class  _A						(       lowerCAmelCase	):
      snake_case__			:   int							  =	VOCAB_FILES_NAMES
      snake_case__			:   List[Any]							  =	PRETRAINED_VOCAB_FILES_MAP
      snake_case__			:   Optional[Any]							  =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
      snake_case__			:   int							  =	['input_ids', 'attention_mask']
      snake_case__			:   Optional[int]							  =	BlenderbotTokenizer

      def __init__(						self		,       __lowerCAmelCase=None		,       __lowerCAmelCase=None		,       __lowerCAmelCase=None		,       __lowerCAmelCase="replace"		,       __lowerCAmelCase="<s>"		,       __lowerCAmelCase="</s>"		,       __lowerCAmelCase="</s>"		,       __lowerCAmelCase="<s>"		,       __lowerCAmelCase="<unk>"		,       __lowerCAmelCase="<pad>"		,       __lowerCAmelCase="<mask>"		,       __lowerCAmelCase=False		,       __lowerCAmelCase=True		,       **__lowerCAmelCase		,       ):







            """simple docstring"""



            super().__init__(
                __lowerCAmelCase		,       __lowerCAmelCase		,       tokenizer_file=__lowerCAmelCase		,       errors=__lowerCAmelCase		,       bos_token=__lowerCAmelCase		,       eos_token=__lowerCAmelCase		,       sep_token=__lowerCAmelCase		,       cls_token=__lowerCAmelCase		,       unk_token=__lowerCAmelCase		,       pad_token=__lowerCAmelCase		,       mask_token=__lowerCAmelCase		,       add_prefix_space=__lowerCAmelCase		,       trim_offsets=__lowerCAmelCase		,       **__lowerCAmelCase		,       )

            lowercase														=	json.loads(self.backend_tokenizer.pre_tokenizer.__getstate__()						)
            if pre_tok_state.get("""add_prefix_space"""		,       __lowerCAmelCase						) != add_prefix_space:
                  lowercase														=	getattr(__lowerCAmelCase		,       pre_tok_state.pop("""type"""						)						)
                  lowercase														=	add_prefix_space
                  lowercase														=	pre_tok_class(**__lowerCAmelCase						)

            lowercase														=	add_prefix_space

            lowercase														=	"""post_processor"""
            lowercase														=	getattr(self.backend_tokenizer		,       __lowerCAmelCase		,       __lowerCAmelCase						)
            if tokenizer_component_instance:
                  lowercase														=	json.loads(tokenizer_component_instance.__getstate__()						)

                  # The lists 'sep' and 'cls' must be cased in tuples for the object `post_processor_class`
                  if "sep" in state:
                        lowercase														=	tuple(state["""sep"""]						)
                  if "cls" in state:
                        lowercase														=	tuple(state["""cls"""]						)

                  lowercase														=	False

                  if state.get("""add_prefix_space"""		,       __lowerCAmelCase						) != add_prefix_space:
                        lowercase														=	add_prefix_space
                        lowercase														=	True

                  if state.get("""trim_offsets"""		,       __lowerCAmelCase						) != trim_offsets:
                        lowercase														=	trim_offsets
                        lowercase														=	True

                  if changes_to_apply:
                        lowercase														=	getattr(__lowerCAmelCase		,       state.pop("""type"""						)						)
                        lowercase														=	component_class(**__lowerCAmelCase						)
                        setattr(self.backend_tokenizer		,       __lowerCAmelCase		,       __lowerCAmelCase						)

      @property
      # Copied from transformers.models.roberta.tokenization_roberta_fast.RobertaTokenizerFast.mask_token with Roberta->Blenderbot, RoBERTa->Blenderbot
      def 				A__       (						self						):







            """simple docstring"""



            if self._mask_token is None:
                  if self.verbose:
                        logger.error("""Using mask_token, but it is not set yet."""						)
                  return None
            return str(self._mask_token						)

      @mask_token.setter
      def 				A__       (						self		,       __lowerCAmelCase						):







            """simple docstring"""



            lowercase														=	AddedToken(__lowerCAmelCase		,       lstrip=__lowerCAmelCase		,       rstrip=__lowerCAmelCase						) if isinstance(__lowerCAmelCase		,       __lowerCAmelCase						) else value
            lowercase														=	value

      def 				A__       (						self		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            lowercase														=	kwargs.get("""is_split_into_words"""		,       __lowerCAmelCase						)
            assert self.add_prefix_space or not is_split_into_words, (
                f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                "to use it with pretokenized inputs."
            )

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

      def 				A__       (						self		,       *__lowerCAmelCase		,       **__lowerCAmelCase						):







            """simple docstring"""



            lowercase														=	kwargs.get("""is_split_into_words"""		,       __lowerCAmelCase						)

            assert self.add_prefix_space or not is_split_into_words, (
                f'You need to instantiate {self.__class__.__name__} with add_prefix_space=True '
                "to use it with pretokenized inputs."
            )

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

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase = None						):







            """simple docstring"""



            lowercase														=	self._tokenizer.model.save(__lowerCAmelCase		,       name=__lowerCAmelCase						)
            return tuple(__lowerCAmelCase						)

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase = None						):







            """simple docstring"""



            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 + sep + token_ids_a + sep						) * [0]

      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase = None						):







            """simple docstring"""



            return token_ids_a + [self.eos_token_id]







      def 				A__       (						self		,       __lowerCAmelCase						):







            """simple docstring"""



            lowercase														=	[]
            for is_user, text in conversation.iter_texts():
                  if is_user:
                        # We need to space prefix as it's being done within blenderbot
                        inputs.append(""" """ + text						)
                  else:
                        # Generated responses should contain them already.
                        inputs.append(__lowerCAmelCase						)

            lowercase														=	"""  """.join(__lowerCAmelCase						)
            lowercase														=	self.encode(__lowerCAmelCase						)
            if len(__lowerCAmelCase						) > self.model_max_length:
                  lowercase														=	input_ids[-self.model_max_length :]
                  logger.warning(f'Trimmed input from conversation as it was longer than {self.model_max_length} tokens.'						)
            return input_ids




"""simple docstring"""






from scipy.stats import pearsonr

import datasets


__lowerCAmelCase    :       List[Any]					     ="""
Pearson correlation coefficient and p-value for testing non-correlation.
The Pearson correlation coefficient measures the linear relationship between two datasets. The calculation of the p-value relies on the assumption that each dataset is normally distributed. Like other correlation coefficients, this one varies between -1 and +1 with 0 implying no correlation. Correlations of -1 or +1 imply an exact linear relationship. Positive correlations imply that as x increases, so does y. Negative correlations imply that as x increases, y decreases.
The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets.
"""


__lowerCAmelCase    :       Optional[int]					     ="""
Args:
    predictions (`list` of `int`): Predicted class labels, as returned by a model.
    references (`list` of `int`): Ground truth labels.
    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.

Returns:
    pearsonr (`float`): Pearson correlation coefficient. Minimum possible value is -1. Maximum possible value is 1. Values of 1 and -1 indicate exact linear positive and negative relationships, respectively. A value of 0 implies no correlation.
    p-value (`float`): P-value, which roughly indicates the probability of an The p-value roughly indicates the probability of an uncorrelated system producing datasets that have a Pearson correlation at least as extreme as the one computed from these datasets. Minimum possible value is 0. Maximum possible value is 1. Higher values indicate higher probabilities.

Examples:

    Example 1-A simple example using only predictions and references.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])
        >>> print(round(results['pearsonr'], 2))
        -0.74

    Example 2-The same as Example 1, but that also returns the `p-value`.
        >>> pearsonr_metric = datasets.load_metric(\"pearsonr\")
        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)
        >>> print(sorted(list(results.keys())))
        ['p-value', 'pearsonr']
        >>> print(round(results['pearsonr'], 2))
        -0.74
        >>> print(round(results['p-value'], 2))
        0.15
"""


__lowerCAmelCase    :       str					     ="""
@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, Ilhan 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, Antonio 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  _A						(       datasets.Metric	):

      def 				A__       (						self						):







            """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.pearsonr.html"""]		,       )







      def 				A__       (						self		,       __lowerCAmelCase		,       __lowerCAmelCase		,       __lowerCAmelCase=False						):







            """simple docstring"""



            if return_pvalue:
                  lowercase														=	pearsonr(__lowerCAmelCase		,       __lowerCAmelCase						)
                  return {"pearsonr": results[0], "p-value": results[1]}
            else:
                  return {"pearsonr": float(pearsonr(__lowerCAmelCase		,       __lowerCAmelCase						)[0]						)}



