
"""simple docstring"""


from sklearn.metrics import mean_squared_error

import datasets


_lowercase							      = '''\
@article{scikit-learn,
 title={Scikit-learn: Machine Learning in {P}ython},
 author={Pedregosa, F. and Varoquaux, G. and Gramfort, A. and Michel, V.
         and Thirion, B. and Grisel, O. and Blondel, M. and Prettenhofer, P.
         and Weiss, R. and Dubourg, V. and Vanderplas, J. and Passos, A. and
         Cournapeau, D. and Brucher, M. and Perrot, M. and Duchesnay, E.},
 journal={Journal of Machine Learning Research},
 volume={12},
 pages={2825--2830},
 year={2011}
}
'''

_lowercase							      = '''\
Mean Squared Error(MSE) is the average of the square of difference between the predicted
and actual values.
'''


_lowercase							      = '''
Args:
    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Estimated target values.
    references: array-like of shape (n_samples,) or (n_samples, n_outputs)
        Ground truth (correct) target values.
    sample_weight: array-like of shape (n_samples,), default=None
        Sample weights.
    multioutput: {"raw_values", "uniform_average"} or array-like of shape (n_outputs,), default="uniform_average"
        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.

        "raw_values" : Returns a full set of errors in case of multioutput input.

        "uniform_average" : Errors of all outputs are averaged with uniform weight.

    squared : bool, default=True
        If True returns MSE value, if False returns RMSE (Root Mean Squared Error) value.

Returns:
    mse : mean squared error.
Examples:

    >>> mse_metric = datasets.load_metric("mse")
    >>> predictions = [2.5, 0.0, 2, 8]
    >>> references = [3, -0.5, 2, 7]
    >>> results = mse_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'mse\': 0.375}
    >>> rmse_result = mse_metric.compute(predictions=predictions, references=references, squared=False)
    >>> print(rmse_result)
    {\'mse\': 0.6123724356957945}

    If you\'re using multi-dimensional lists, then set the config as follows :

    >>> mse_metric = datasets.load_metric("mse", "multilist")
    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]
    >>> references = [[0, 2], [-1, 2], [8, -5]]
    >>> results = mse_metric.compute(predictions=predictions, references=references)
    >>> print(results)
    {\'mse\': 0.7083333333333334}
    >>> results = mse_metric.compute(predictions=predictions, references=references, multioutput=\'raw_values\')
    >>> print(results) # doctest: +NORMALIZE_WHITESPACE
    {\'mse\': array([0.41666667, 1. ])}
'''







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



						'''simple docstring'''


						def   _SCREAMING_SNAKE_CASE					(       self   :					Any					)   ->      List[Any]:
							return datasets.MetricInfo(
							    description=_DESCRIPTION     ,citation=_CITATION     ,inputs_description=_KWARGS_DESCRIPTION     ,features=datasets.Features(self._get_feature_types()					)     ,reference_urls=[
							        'https://scikit-learn.org/stable/modules/generated/sklearn.metrics.mean_squared_error.html'
							    ]     ,)


						def   _SCREAMING_SNAKE_CASE					(       self   :					Optional[int]					)   ->      Any:


							if self.config_name == "multilist":
								return {
								    "predictions": datasets.Sequence(datasets.Value('float'					)					),
								    "references": datasets.Sequence(datasets.Value('float'					)					),
								}
							else:
								return {
								    "predictions": datasets.Value('float'					),
								    "references": datasets.Value('float'					),
								}




						def   _SCREAMING_SNAKE_CASE					(       self   :					Union[str, Any]     ,A_   :					Dict     ,A_   :					Dict     ,A_   :					List[str]=None     ,A_   :					Tuple="uniform_average"     ,A_   :					Any=True					)   ->      List[str]:
							A        =      mean_squared_error(
							    A_     ,A_     ,sample_weight=A_     ,multioutput=A_     ,squared=A_					)

							return {"mse": mse}

import os
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_pegasus import PegasusTokenizer
else:
			_lowerCamelCase       :				int       =			None


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


_lowerCamelCase       :				Tuple       =			'''▁'''

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

_lowerCamelCase       :				Any       =			{
    '''vocab_file''': {'''google/pegasus-xsum''': '''https://huggingface.co/google/pegasus-xsum/resolve/main/spiece.model'''},
    '''tokenizer_file''': {
        '''google/pegasus-xsum''': '''https://huggingface.co/google/pegasus-xsum/resolve/main/tokenizer.json'''
    },
}

_lowerCamelCase       :				Optional[int]       =			{
    '''google/pegasus-xsum''': 512,
}




class    SCREAMING_SNAKE_CASE__     (	UpperCAmelCase					):





	'''simple docstring'''



	_UpperCAmelCase       :		int       =					VOCAB_FILES_NAMES
	_UpperCAmelCase       :		Union[str, Any]       =					PRETRAINED_VOCAB_FILES_MAP
	_UpperCAmelCase       :		Union[str, Any]       =					PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
	_UpperCAmelCase       :		Any       =					PegasusTokenizer
	_UpperCAmelCase       :		Dict       =					["input_ids", "attention_mask"]



	def __init__(  self	:    Tuple			,  lowercase	:    str=None			,  lowercase	:    Any=None			,  lowercase	:    List[Any]="<pad>"			,  lowercase	:    List[Any]="</s>"			,  lowercase	:    Tuple="<unk>"			,  lowercase	:    Any="<mask_2>"			,  lowercase	:    List[str]="<mask_1>"			,  lowercase	:    List[Any]=None			,  lowercase	:    Dict=103			,  **lowercase	:    Optional[Any]			,  ):


				'''simple docstring'''


				_snake_case		=			offset

				if additional_special_tokens is not None:
							if not isinstance(lowercase			,  lowercase	):
										raise TypeError(
										    f'''additional_special_tokens should be of type {type(lowercase	)}, but is'''
										    f''' {type(lowercase	)}'''	)

							_snake_case		=			(
							    ([mask_token_sent] + additional_special_tokens)
							    if mask_token_sent not in additional_special_tokens and mask_token_sent is not None
							    else additional_special_tokens
							)
							# fill additional tokens with ..., <unk_token_102> in case not all additional tokens are already taken
							additional_special_tokens_extended += [
							    f'''<unk_{i}>''' for i in range(len(lowercase	)			,  self.offset - 1	)
							]

							if len(set(lowercase	)	) != len(lowercase	):
										raise ValueError(
										    'Please make sure that the provided additional_special_tokens do not contain an incorrectly'
										    f''' shifted list of <unk_x> tokens. Found {additional_special_tokens_extended}.'''	)
							_snake_case		=			additional_special_tokens_extended
				else:
							_snake_case		=			[mask_token_sent] if mask_token_sent is not None else []
							additional_special_tokens += [f'''<unk_{i}>''' for i in range(2			,  self.offset	)]

				super().__init__(
				    lowercase			,  tokenizer_file=lowercase			,  pad_token=lowercase			,  eos_token=lowercase			,  unk_token=lowercase			,  mask_token=lowercase			,  mask_token_sent=lowercase			,  offset=lowercase			,  additional_special_tokens=lowercase			,  **lowercase			,  )
				_snake_case		=			vocab_file
				_snake_case		=			False if not self.vocab_file else True



	def  A							(  self	:    List[str]			,  lowercase	:    Optional[int]	):


				'''simple docstring'''


				_snake_case		=			set(self.all_special_ids	)  # call it once instead of inside list comp
				all_special_ids.remove(self.unk_token_id	)  # <unk> is only sometimes special

				if all_special_ids != set(range(len(self.additional_special_tokens	) + 3	)	):
							raise ValueError(
							    'There should be 3 special tokens: mask_token, pad_token, and eos_token +'
							    f''' {len(self.additional_special_tokens	)} additional_special_tokens, but got {all_special_ids}'''	)

				return [1 if x in all_special_ids else 0 for x in seq]



	def  A							(  self	:    List[Any]			,  lowercase	:    List			,  lowercase	:    Optional[List] = None			,  lowercase	:    bool = False	):


				'''simple docstring'''


				if already_has_special_tokens:
							return self._special_token_mask(lowercase	)
				elif token_ids_a is None:
							return self._special_token_mask(lowercase	) + [1]
				else:
							return self._special_token_mask(token_ids_a + token_ids_a	) + [1]



	def  A							(  self	:    Any			,  lowercase	:    Tuple			,  lowercase	:    Any=None	):


				'''simple docstring'''


				if token_ids_a is None:
							return token_ids_a + [self.eos_token_id]
				# We don't expect to process pairs, but leave the pair logic for API consistency
				return token_ids_a + token_ids_a + [self.eos_token_id]





	def  A							(  self	:    int			,  lowercase	:    str			,  lowercase	:    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(lowercase	):
							logger.error(f'''Vocabulary path ({save_directory}) should be a directory'''	)
							return
				_snake_case		=			os.path.join(
				    lowercase			,  (filename_prefix + '-' if filename_prefix else '') + VOCAB_FILES_NAMES['vocab_file']	)

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

				return (out_vocab_file,)