
"""simple docstring"""





from scipy.stats import pearsonr

import datasets


UpperCamelCase_       :    str						      =			'''
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.
'''


UpperCamelCase_       :    Dict						      =			'''
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
'''


UpperCamelCase_       :    List[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 __lowerCAmelCase					(       datasets.Metric   ):




			"""simple docstring"""







			def   lowerCamelCase__  (					self    :       str						)   ->			Tuple:







								"""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   lowerCamelCase__  (					self    :       Optional[Any]							, _snake_case    :       str							, _snake_case    :       Dict							, _snake_case    :       Optional[int]=False						)   ->			Union[str, Any]:







								"""simple docstring"""
								if return_pvalue:
													A_								=    pearsonr(_snake_case							, _snake_case						)
													return {"pearsonr": results[0], "p-value": results[1]}
								else:
													return {"pearsonr": float(pearsonr(_snake_case							, _snake_case						)[0]						)}






"""simple docstring"""





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

from tokenizers import processors

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


if is_sentencepiece_available():
		from .tokenization_mbart import MBartTokenizer
else:
		UpperCamelCase_       :    Dict						      =			None


UpperCamelCase_       :    int						      =			logging.get_logger(__name__)


UpperCamelCase_       :    str						      =			{'''vocab_file''': '''sentencepiece.bpe.model''', '''tokenizer_file''': '''tokenizer.json'''}

UpperCamelCase_       :    List[Any]						      =			{
    '''vocab_file''': {
        '''facebook/mbart-large-en-ro''': (
            '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/sentencepiece.bpe.model'''
        ),
        '''facebook/mbart-large-cc25''': (
            '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/sentencepiece.bpe.model'''
        ),
    },
    '''tokenizer_file''': {
        '''facebook/mbart-large-en-ro''': '''https://huggingface.co/facebook/mbart-large-en-ro/resolve/main/tokenizer.json''',
        '''facebook/mbart-large-cc25''': '''https://huggingface.co/facebook/mbart-large-cc25/resolve/main/tokenizer.json''',
    },
}

UpperCamelCase_       :    Optional[Any]						      =			{
    '''facebook/mbart-large-en-ro''': 1024,
    '''facebook/mbart-large-cc25''': 1024,
}

# fmt: off
UpperCamelCase_       :    str						      =			['''ar_AR''', '''cs_CZ''', '''de_DE''', '''en_XX''', '''es_XX''', '''et_EE''', '''fi_FI''', '''fr_XX''', '''gu_IN''', '''hi_IN''', '''it_IT''', '''ja_XX''', '''kk_KZ''', '''ko_KR''', '''lt_LT''', '''lv_LV''', '''my_MM''', '''ne_NP''', '''nl_XX''', '''ro_RO''', '''ru_RU''', '''si_LK''', '''tr_TR''', '''vi_VN''', '''zh_CN''']



class __lowerCAmelCase					(       _lowercase   ):




			"""simple docstring"""







			snake_case						   =					VOCAB_FILES_NAMES
			snake_case						   =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
			snake_case						   =					PRETRAINED_VOCAB_FILES_MAP
			snake_case						   =					["input_ids", "attention_mask"]
			snake_case						   =					MBartTokenizer

			snake_case						   =					[]
			snake_case						   =					[]




			def __init__(					self    :       List[str]							, _snake_case    :       Tuple=None							, _snake_case    :       int=None							, _snake_case    :       List[Any]="<s>"							, _snake_case    :       Tuple="</s>"							, _snake_case    :       str="</s>"							, _snake_case    :       List[Any]="<s>"							, _snake_case    :       Dict="<unk>"							, _snake_case    :       str="<pad>"							, _snake_case    :       Any="<mask>"							, _snake_case    :       int=None							, _snake_case    :       Optional[int]=None							, _snake_case    :       Any=None							, **_snake_case    :       Union[str, Any]							, )   ->			List[str]:







								"""simple docstring"""
								# Mask token behave like a normal word, i.e. include the space before it
								A_								=    AddedToken(_snake_case							, lstrip=_snake_case							, rstrip=_snake_case						) if isinstance(_snake_case							, _snake_case						) else mask_token

								super().__init__(
								    vocab_file=_snake_case							, tokenizer_file=_snake_case							, bos_token=_snake_case							, eos_token=_snake_case							, sep_token=_snake_case							, cls_token=_snake_case							, unk_token=_snake_case							, pad_token=_snake_case							, mask_token=_snake_case							, src_lang=_snake_case							, tgt_lang=_snake_case							, additional_special_tokens=_snake_case							, **_snake_case							, )

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

								A_								=    FAIRSEQ_LANGUAGE_CODES.copy()

								if additional_special_tokens is not None:
													# Only add those special tokens if they are not already there.
													_additional_special_tokens.extend(
													    [t for t in additional_special_tokens if t not in _additional_special_tokens]						)

								self.add_special_tokens({"additional_special_tokens": _additional_special_tokens}						)
								A_								=    {
								    lang_code: self.convert_tokens_to_ids(_snake_case						) for lang_code in FAIRSEQ_LANGUAGE_CODES
								}

								A_								=    src_lang if src_lang is not None else "en_XX"
								A_								=    self.convert_tokens_to_ids(self._src_lang						)
								A_								=    tgt_lang
								self.set_src_lang_special_tokens(self._src_lang						)




			@property
			def   lowerCamelCase__  (					self    :       Dict						)   ->			str:







								"""simple docstring"""
								return self._src_lang




			@src_lang.setter
			def   lowerCamelCase__  (					self    :       Tuple							, _snake_case    :       str						)   ->			None:







								"""simple docstring"""
								A_								=    new_src_lang
								self.set_src_lang_special_tokens(self._src_lang						)




			def   lowerCamelCase__  (					self    :       Optional[Any]							, _snake_case    :       List[int]							, _snake_case    :       Optional[List[int]] = None						)   ->			List[int]:







								"""simple docstring"""
								if token_ids_a is None:
													return self.prefix_tokens + token_ids_a + self.suffix_tokens
								# We don't expect to process pairs, but leave the pair logic for API consistency
								return self.prefix_tokens + token_ids_a + token_ids_a + self.suffix_tokens




			def   lowerCamelCase__  (					self    :       Dict							, _snake_case    :       List[int]							, _snake_case    :       Optional[List[int]] = None						)   ->			List[int]:







								"""simple docstring"""
								A_								=    [self.sep_token_id]
								A_								=    [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   lowerCamelCase__  (					self    :       List[Any]							, _snake_case    :       str							, _snake_case    :       str							, _snake_case    :       Optional[str]							, _snake_case    :       Optional[str]							, **_snake_case    :       Optional[int]						)   ->			str:







								"""simple docstring"""
								if src_lang is None or tgt_lang is None:
													raise ValueError("Translation requires a `src_lang` and a `tgt_lang` for this model"						)
								A_								=    src_lang
								A_								=    self(_snake_case							, add_special_tokens=_snake_case							, return_tensors=_snake_case							, **_snake_case						)
								A_								=    self.convert_tokens_to_ids(_snake_case						)
								A_								=    tgt_lang_id
								return inputs




			def   lowerCamelCase__  (					self    :       Dict							, _snake_case    :       List[str]							, _snake_case    :       str = "en_XX"							, _snake_case    :       Optional[List[str]] = None							, _snake_case    :       str = "ro_RO"							, **_snake_case    :       str							, )   ->			BatchEncoding:







								"""simple docstring"""
								A_								=    src_lang
								A_								=    tgt_lang
								return super().prepare_seqaseq_batch(_snake_case							, _snake_case							, **_snake_case						)




			def   lowerCamelCase__  (					self    :       Any						)   ->			Optional[Any]:







								"""simple docstring"""
								return self.set_src_lang_special_tokens(self.src_lang						)




			def   lowerCamelCase__  (					self    :       Dict						)   ->			List[Any]:







								"""simple docstring"""
								return self.set_tgt_lang_special_tokens(self.tgt_lang						)




			def   lowerCamelCase__  (					self    :       Tuple							, _snake_case    :       List[str]						)   ->			None:







								"""simple docstring"""
								A_								=    self.convert_tokens_to_ids(_snake_case						)
								A_								=    []
								A_								=    [self.eos_token_id, self.cur_lang_code]

								A_								=    self.convert_ids_to_tokens(self.prefix_tokens						)
								A_								=    self.convert_ids_to_tokens(self.suffix_tokens						)

								A_								=    processors.TemplateProcessing(
								    single=prefix_tokens_str + ["$A"] + suffix_tokens_str							, pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str							, special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str							, self.prefix_tokens + self.suffix_tokens						)						)							, )




			def   lowerCamelCase__  (					self    :       List[str]							, _snake_case    :       str						)   ->			None:







								"""simple docstring"""
								A_								=    self.convert_tokens_to_ids(_snake_case						)
								A_								=    []
								A_								=    [self.eos_token_id, self.cur_lang_code]

								A_								=    self.convert_ids_to_tokens(self.prefix_tokens						)
								A_								=    self.convert_ids_to_tokens(self.suffix_tokens						)

								A_								=    processors.TemplateProcessing(
								    single=prefix_tokens_str + ["$A"] + suffix_tokens_str							, pair=prefix_tokens_str + ["$A", "$B"] + suffix_tokens_str							, special_tokens=list(zip(prefix_tokens_str + suffix_tokens_str							, self.prefix_tokens + self.suffix_tokens						)						)							, )






			def   lowerCamelCase__  (					self    :       Union[str, Any]							, _snake_case    :       str							, _snake_case    :       Optional[str] = None						)   ->			Tuple[str]:







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

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

								return (out_vocab_file,)




