from scipy.stats import pearsonr

import datasets


__UpperCamelCase	: Tuple    		=  '\nPearson correlation coefficient and p-value for testing non-correlation.\nThe 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.\nThe 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.\n'


__UpperCamelCase	: Any    		=  '\nArgs:\n    predictions (`list` of `int`): Predicted class labels, as returned by a model.\n    references (`list` of `int`): Ground truth labels.\n    return_pvalue (`boolean`): If `True`, returns the p-value, along with the correlation coefficient. If `False`, returns only the correlation coefficient. Defaults to `False`.\n\nReturns:\n    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.\n    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.\n\nExamples:\n\n    Example 1-A simple example using only predictions and references.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5])\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n\n    Example 2-The same as Example 1, but that also returns the `p-value`.\n        >>> pearsonr_metric = datasets.load_metric("pearsonr")\n        >>> results = pearsonr_metric.compute(predictions=[10, 9, 2.5, 6, 4], references=[1, 2, 3, 4, 5], return_pvalue=True)\n        >>> print(sorted(list(results.keys())))\n        [\'p-value\', \'pearsonr\']\n        >>> print(round(results[\'pearsonr\'], 2))\n        -0.74\n        >>> print(round(results[\'p-value\'], 2))\n        0.15\n'


__UpperCamelCase	: Tuple    		=  '\n@article{2020SciPy-NMeth,\nauthor  = {Virtanen, Pauli and Gommers, Ralf and Oliphant, Travis E. and\n      Haberland, Matt and Reddy, Tyler and Cournapeau, David and\n      Burovski, Evgeni and Peterson, Pearu and Weckesser, Warren and\n      Bright, Jonathan and {van der Walt}, St{\'e}fan J. and\n      Brett, Matthew and Wilson, Joshua and Millman, K. Jarrod and\n      Mayorov, Nikolay and Nelson, Andrew R. J. and Jones, Eric and\n      Kern, Robert and Larson, Eric and Carey, C J and\n      Polat, Ilhan and Feng, Yu and Moore, Eric W. and\n      {VanderPlas}, Jake and Laxalde, Denis and Perktold, Josef and\n      Cimrman, Robert and Henriksen, Ian and Quintero, E. A. and\n      Harris, Charles R. and Archibald, Anne M. and\n      Ribeiro, Antonio H. and Pedregosa, Fabian and\n      {van Mulbregt}, Paul and {SciPy 1.0 Contributors}},\ntitle   = {{{SciPy} 1.0: Fundamental Algorithms for Scientific\n      Computing in Python}},\njournal = {Nature Methods},\nyear    = {2020},\nvolume  = {17},\npages   = {261--272},\nadsurl  = {https://rdcu.be/b08Wh},\ndoi = {10.1038/s41592-019-0686-2},\n}\n'





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


						def  __A ( self			:       List[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.pearsonr.html''']					,	)



						def  __A ( self			:       Union[str, Any]					,	UpperCamelCase__			:       Union[str, Any]					,	UpperCamelCase__			:       Any					,	UpperCamelCase__			:       Dict=False		):





												'''simple docstring'''





												if return_pvalue:
																		SCREAMING_SNAKE_CASE							:					List[Any]           =							pearsonr(UpperCamelCase__					,	UpperCamelCase__		)
																		return {"pearsonr": results[0], "p-value": results[1]}
												else:
																		return {"pearsonr": float(pearsonr(UpperCamelCase__					,	UpperCamelCase__		)[0]		)}






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

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


if is_sentencepiece_available():
					from .tokenization_ta import TaTokenizer
else:
					__UpperCamelCase	: Dict    		=  None


__UpperCamelCase	: Tuple    		=  logging.get_logger(__name__)

__UpperCamelCase	: Optional[int]    		=  {'vocab_file': 'spiece.model', 'tokenizer_file': 'tokenizer.json'}

__UpperCamelCase	: Optional[int]    		=  {
    'vocab_file': {
        't5-small': 'https://huggingface.co/t5-small/resolve/main/spiece.model',
        't5-base': 'https://huggingface.co/t5-base/resolve/main/spiece.model',
        't5-large': 'https://huggingface.co/t5-large/resolve/main/spiece.model',
        't5-3b': 'https://huggingface.co/t5-3b/resolve/main/spiece.model',
        't5-11b': 'https://huggingface.co/t5-11b/resolve/main/spiece.model',
    },
    'tokenizer_file': {
        't5-small': 'https://huggingface.co/t5-small/resolve/main/tokenizer.json',
        't5-base': 'https://huggingface.co/t5-base/resolve/main/tokenizer.json',
        't5-large': 'https://huggingface.co/t5-large/resolve/main/tokenizer.json',
        't5-3b': 'https://huggingface.co/t5-3b/resolve/main/tokenizer.json',
        't5-11b': 'https://huggingface.co/t5-11b/resolve/main/tokenizer.json',
    },
}


# TODO(PVP) - this should be removed in Transformers v5
__UpperCamelCase	: Union[str, Any]    		=  {
    't5-small': 512,
    't5-base': 512,
    't5-large': 512,
    't5-3b': 512,
    't5-11b': 512,
}





class       lowercase__		(     UpperCamelCase_):
						UpperCamelCase_  =	VOCAB_FILES_NAMES
						UpperCamelCase_  =	PRETRAINED_VOCAB_FILES_MAP
						UpperCamelCase_  =	PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
						UpperCamelCase_  =	["""input_ids""", """attention_mask"""]
						UpperCamelCase_  =	TaTokenizer

						UpperCamelCase_  =	[]


						def __init__( self			:       str					,	UpperCamelCase__			:       Optional[int]=None					,	UpperCamelCase__			:       Dict=None					,	UpperCamelCase__			:       str="</s>"					,	UpperCamelCase__			:       str="<unk>"					,	UpperCamelCase__			:       Optional[int]="<pad>"					,	UpperCamelCase__			:       Optional[Any]=100					,	UpperCamelCase__			:       List[Any]=None					,	**UpperCamelCase__			:       str					,	):





												'''simple docstring'''





												if extra_ids > 0 and additional_special_tokens is None:
																		SCREAMING_SNAKE_CASE							:					List[str]           =							[f"""<extra_id_{i}>""" for i in range(UpperCamelCase__		)]
												elif extra_ids > 0 and additional_special_tokens is not None:
																		# Check that we have the right number of extra special tokens
																		SCREAMING_SNAKE_CASE							:					int           =							len(set(filter(lambda UpperCamelCase__		: bool('''extra_id_''' in str(UpperCamelCase__		)		)					,	UpperCamelCase__		)		)		)
																		if extra_tokens != extra_ids:
																								raise ValueError(
																								    f"""Both extra_ids ({extra_ids}) and additional_special_tokens ({additional_special_tokens}) are"""
																								    ''' provided to T5Tokenizer. In this case the additional_special_tokens must include the extra_ids'''
																								    ''' tokens'''		)

												super().__init__(
												    UpperCamelCase__					,	tokenizer_file=UpperCamelCase__					,	eos_token=UpperCamelCase__					,	unk_token=UpperCamelCase__					,	pad_token=UpperCamelCase__					,	extra_ids=UpperCamelCase__					,	additional_special_tokens=UpperCamelCase__					,	**UpperCamelCase__					,	)

												SCREAMING_SNAKE_CASE							:					str           =							vocab_file
												SCREAMING_SNAKE_CASE							:					int           =							False if not self.vocab_file else True
												SCREAMING_SNAKE_CASE							:					str           =							extra_ids


						@staticmethod
						def  __A ( UpperCamelCase__			:       Optional[int]					,	UpperCamelCase__			:       Optional[int]					,	UpperCamelCase__			:       Optional[Any]		):





												'''simple docstring'''





												if pretrained_model_name_or_path in TaTokenizerFast.max_model_input_sizes:
																		SCREAMING_SNAKE_CASE							:					List[str]           =							TaTokenizerFast.max_model_input_sizes[pretrained_model_name_or_path]
																		if init_max_model_length is not None and init_max_model_length != max_model_length:
																								return init_max_model_length
																		elif init_max_model_length is None:
																								warnings.warn(
																								    '''This tokenizer was incorrectly instantiated with a model max length of'''
																								    f""" {deprecated_max_model_length} which will be corrected in Transformers v5.\nFor now, this"""
																								    ''' behavior is kept to avoid breaking backwards compatibility when padding/encoding with'''
																								    ''' `truncation is True`.\n- Be aware that you SHOULD NOT rely on'''
																								    f""" {pretrained_model_name_or_path} automatically truncating your input to"""
																								    f""" {deprecated_max_model_length} when padding/encoding.\n- If you want to encode/pad to sequences"""
																								    f""" longer than {deprecated_max_model_length} you can either instantiate this tokenizer with"""
																								    ''' `model_max_length` or pass `max_length` when encoding/padding.\n- To avoid this warning, please'''
																								    ''' instantiate this tokenizer with `model_max_length` set to your preferred value.'''					,	UpperCamelCase__					,	)

												return max_model_length


						def  __A ( self			:       Tuple					,	UpperCamelCase__			:       str					,	UpperCamelCase__			:       Optional[str] = None		):





												'''simple docstring'''





												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(UpperCamelCase__		):
																		logger.error(f"""Vocabulary path ({save_directory}) should be a directory"""		)
																		return
												SCREAMING_SNAKE_CASE							:					Any           =							os.path.join(
												    UpperCamelCase__					,	(filename_prefix + '''-''' if filename_prefix else '''''') + VOCAB_FILES_NAMES['''vocab_file''']		)

												if os.path.abspath(self.vocab_file		) != os.path.abspath(UpperCamelCase__		):
																		copyfile(self.vocab_file					,	UpperCamelCase__		)
																		logger.info(f"""Copy vocab file to {out_vocab_file}"""		)

												return (out_vocab_file,)


						def  __A ( self			:       Optional[Any]					,	UpperCamelCase__			:       List[int]					,	UpperCamelCase__			:       Optional[List[int]] = None		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Optional[int]           =							token_ids_a + [self.eos_token_id]
												if token_ids_a is None:
																		return self.prefix_tokens + token_ids_a
												else:
																		SCREAMING_SNAKE_CASE							:					Tuple           =							token_ids_a + [self.eos_token_id]
																		return self.prefix_tokens + token_ids_a + token_ids_a


						def  __A ( self			:       Any					,	UpperCamelCase__			:       List[int]					,	UpperCamelCase__			:       Optional[List[int]] = None		):





												'''simple docstring'''





												SCREAMING_SNAKE_CASE							:					Union[str, Any]           =							[self.eos_token_id]

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


						def  __A ( self			:       Dict		):





												'''simple docstring'''





												return list(
												    set(filter(lambda UpperCamelCase__		: bool(re.search(r'''<extra_id_\d+>'''					,	UpperCamelCase__		)		) is not None					,	self.additional_special_tokens		)		)		)



						def  __A ( self			:       List[Any]		):





												'''simple docstring'''





												return [self.convert_tokens_to_ids(UpperCamelCase__		) for token in self.get_sentinel_tokens()]





