



'''simple docstring'''




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

from ...tokenization_utils import PreTrainedTokenizer
from ...utils import logging


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

a     :    Optional[Any]      						=					{
    """vocab_file""": """vocab.txt""",
    """merges_file""": """bpe.codes""",
}

a     :    str      						=					{
    """vocab_file""": {
        """vinai/phobert-base""": """https://huggingface.co/vinai/phobert-base/resolve/main/vocab.txt""",
        """vinai/phobert-large""": """https://huggingface.co/vinai/phobert-large/resolve/main/vocab.txt""",
    },
    """merges_file""": {
        """vinai/phobert-base""": """https://huggingface.co/vinai/phobert-base/resolve/main/bpe.codes""",
        """vinai/phobert-large""": """https://huggingface.co/vinai/phobert-large/resolve/main/bpe.codes""",
    },
}

a     :    Tuple      						=					{
    """vinai/phobert-base""": 2_5_6,
    """vinai/phobert-large""": 2_5_6,
}



def    __lowerCamelCase						(      _lowercase	)   ->    str:
							UpperCAmelCase  :	List[Any]							  =	set()
							UpperCAmelCase  :	Optional[Any]							  =	word[0]
							for char in word[1:]:
														pairs.add((prev_char, char)	)
														UpperCAmelCase  :	Any							  =	char

							UpperCAmelCase  :	List[Any]							  =	set(lowerCamelCase_	)
							return pairs


class     UpperCamelCase_				(							lowerCAmelCase__    ):
	lowercase    =				VOCAB_FILES_NAMES
	lowercase    =				PRETRAINED_VOCAB_FILES_MAP
	lowercase    =				PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES





	def __init__(						self	,	A	,	A	,	A="<s>"	,	A="</s>"	,	A="</s>"	,	A="<s>"	,	A="<unk>"	,	A="<pad>"	,	A="<mask>"	,	**A	,	)    ->    Optional[int]:
								super().__init__(
								    bos_token=_lowerCamelCase	,	eos_token=_lowerCamelCase	,	unk_token=_lowerCamelCase	,	sep_token=_lowerCamelCase	,	cls_token=_lowerCamelCase	,	pad_token=_lowerCamelCase	,	mask_token=_lowerCamelCase	,	**_lowerCamelCase	,	)

								UpperCAmelCase  :	Any							  =	vocab_file
								UpperCAmelCase  :	Optional[int]							  =	merges_file

								UpperCAmelCase  :	Any							  =	{}
								UpperCAmelCase  :	Optional[Any]							  =	0
								UpperCAmelCase  :	str							  =	1
								UpperCAmelCase  :	Tuple							  =	2
								UpperCAmelCase  :	Dict							  =	3

								self.add_from_file(_lowerCamelCase					)

								UpperCAmelCase  :	str							  =	{v: k for k, v in self.encoder.items()}

								with open(_lowerCamelCase	,	encoding="""utf-8"""					) as merges_handle:
															UpperCAmelCase  :	Tuple							  =	merges_handle.read().split("""\n"""					)[:-1]
								UpperCAmelCase  :	Tuple							  =	[tuple(merge.split()[:-1]					) for merge in merges]
								UpperCAmelCase  :	Dict							  =	dict(zip(_lowerCamelCase	,	range(len(_lowerCamelCase					)					)					)					)
								UpperCAmelCase  :	Any							  =	{}





	def 				_lowercase(						self	,	A	,	A = None					)    ->    List[int]:





								if token_ids_a is None:
															return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
								UpperCAmelCase  :	Union[str, Any]							  =	[self.cls_token_id]
								UpperCAmelCase  :	str							  =	[self.sep_token_id]
								return cls + token_ids_a + sep + sep + token_ids_a + sep





	def 				_lowercase(						self	,	A	,	A = None	,	A = False					)    ->    List[int]:





								if already_has_special_tokens:
															return super().get_special_tokens_mask(
															    token_ids_a=_lowerCamelCase	,	token_ids_a=_lowerCamelCase	,	already_has_special_tokens=_lowerCamelCase					)

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





	def 				_lowercase(						self	,	A	,	A = None					)    ->    List[int]:
								UpperCAmelCase  :	Any							  =	[self.sep_token_id]
								UpperCAmelCase  :	str							  =	[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]





	@property
	def 				_lowercase(						self					)    ->    List[str]:
								return len(self.encoder					)





	def 				_lowercase(						self					)    ->    Dict:
								return dict(self.encoder	,	**self.added_tokens_encoder					)





	def 				_lowercase(						self	,	A					)    ->    List[str]:





								if token in self.cache:
															return self.cache[token]
								UpperCAmelCase  :	int							  =	tuple(_lowerCamelCase					)
								UpperCAmelCase  :	Any							  =	tuple(list(word[:-1]					) + [word[-1] + """</w>"""]					)
								UpperCAmelCase  :	Optional[Any]							  =	get_pairs(_lowerCamelCase					)

								if not pairs:
															return token

								while True:
															UpperCAmelCase  :	Dict							  =	min(_lowerCamelCase	,	key=lambda A					: self.bpe_ranks.get(_lowerCamelCase	,	float("""inf"""					)					)					)
															if bigram not in self.bpe_ranks:
																						break
															UpperCAmelCase  ,  UpperCAmelCase  :	Dict							  =	bigram
															UpperCAmelCase  :	Dict							  =	[]
															UpperCAmelCase  :	List[str]							  =	0
															while i < len(_lowerCamelCase					):
																						try:
																													UpperCAmelCase  :	Tuple							  =	word.index(_lowerCamelCase	,	_lowerCamelCase					)
																						except ValueError:
																													new_word.extend(word[i:]					)
																													break
																						else:
																													new_word.extend(word[i:j]					)
																													UpperCAmelCase  :	Optional[int]							  =	j

																						if word[i] == first and i < len(_lowerCamelCase					) - 1 and word[i + 1] == second:
																													new_word.append(first + second					)
																													i += 2
																						else:
																													new_word.append(word[i]					)
																													i += 1
															UpperCAmelCase  :	Optional[int]							  =	tuple(_lowerCamelCase					)
															UpperCAmelCase  :	Optional[int]							  =	new_word
															if len(_lowerCamelCase					) == 1:
																						break
															else:
																						UpperCAmelCase  :	Optional[Any]							  =	get_pairs(_lowerCamelCase					)
								UpperCAmelCase  :	int							  =	"""@@ """.join(_lowerCamelCase					)
								UpperCAmelCase  :	List[str]							  =	word[:-4]
								UpperCAmelCase  :	Dict							  =	word
								return word





	def 				_lowercase(						self	,	A					)    ->    Union[str, Any]:
								UpperCAmelCase  :	Dict							  =	[]

								UpperCAmelCase  :	str							  =	re.findall(r"""\S+\n?"""	,	_lowerCamelCase					)

								for token in words:
															split_tokens.extend(list(self.bpe(_lowerCamelCase					).split(""" """					)					)					)
								return split_tokens





	def 				_lowercase(						self	,	A					)    ->    Dict:
								return self.encoder.get(_lowerCamelCase	,	self.encoder.get(self.unk_token					)					)





	def 				_lowercase(						self	,	A					)    ->    str:
								return self.decoder.get(_lowerCamelCase	,	self.unk_token					)





	def 				_lowercase(						self	,	A					)    ->    int:
								UpperCAmelCase  :	str							  =	""" """.join(_lowerCamelCase					).replace("""@@ """	,	""""""					).strip()
								return out_string





	def 				_lowercase(						self	,	A	,	A = None					)    ->    Tuple[str]:





								if not os.path.isdir(_lowerCamelCase					):
															logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''					)
															return
								UpperCAmelCase  :	List[str]							  =	os.path.join(
								    _lowerCamelCase	,	(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]					)
								UpperCAmelCase  :	Dict							  =	os.path.join(
								    _lowerCamelCase	,	(filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]					)

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

								if os.path.abspath(self.merges_file					) != os.path.abspath(_lowerCamelCase					):
															copyfile(self.merges_file	,	_lowerCamelCase					)

								return out_vocab_file, out_merge_file






	def 				_lowercase(						self	,	A					)    ->    Tuple:





								if isinstance(_lowerCamelCase	,	_lowerCamelCase					):
															try:
																						with open(_lowerCamelCase	,	"""r"""	,	encoding="""utf-8"""					) as fd:
																													self.add_from_file(_lowerCamelCase					)
															except FileNotFoundError as fnfe:
																						raise fnfe
															except UnicodeError:
																						raise Exception(f'''Incorrect encoding detected in {f}, please rebuild the dataset'''					)
															return

								UpperCAmelCase  :	Tuple							  =	f.readlines()
								for lineTmp in lines:
															UpperCAmelCase  :	Tuple							  =	lineTmp.strip()
															UpperCAmelCase  :	List[str]							  =	line.rfind(""" """					)
															if idx == -1:
																						raise ValueError("""Incorrect dictionary format, expected \'<token> <cnt>\'"""					)
															UpperCAmelCase  :	Dict							  =	line[:idx]
															UpperCAmelCase  :	List[Any]							  =	len(self.encoder					)






'''simple docstring'''




from scipy.stats import pearsonr

import datasets


a     :    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.
"""


a     :    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
"""


a     :    Optional[int]      						=					"""
@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     UpperCamelCase_				(							datasets.Metric    ):





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






	def 				_lowercase(						self	,	A	,	A	,	A=False					)    ->    int:
								if return_pvalue:
															UpperCAmelCase  :	int							  =	pearsonr(A	,	A					)
															return {"pearsonr": results[0], "p-value": results[1]}
								else:
															return {"pearsonr": float(pearsonr(A	,	A					)[0]					)}

