

from sklearn.metrics import mean_absolute_error

import datasets


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

lowercase     :       List[str]        =       "\\nMean Absolute Error (MAE) is the mean of the magnitude of difference between the predicted and actual\nvalues.\n"


lowercase     :       Optional[int]        =       "\nArgs:\n    predictions: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Estimated target values.\n    references: array-like of shape (n_samples,) or (n_samples, n_outputs)\n        Ground truth (correct) target values.\n    sample_weight: array-like of shape (n_samples,), default=None\n        Sample weights.\n    multioutput: {\"raw_values\", \"uniform_average\"} or array-like of shape (n_outputs,), default=\"uniform_average\"\n        Defines aggregating of multiple output values. Array-like value defines weights used to average errors.\n\n                 \"raw_values\" : Returns a full set of errors in case of multioutput input.\n\n                 \"uniform_average\" : Errors of all outputs are averaged with uniform weight.\n\nReturns:\n    mae : mean absolute error.\n        If multioutput is \"raw_values\", then mean absolute error is returned for each output separately. If multioutput is \"uniform_average\" or an ndarray of weights, then the weighted average of all output errors is returned.\n        MAE output is non-negative floating point. The best value is 0.0.\nExamples:\n\n    >>> mae_metric = datasets.load_metric(\"mae\")\n    >>> predictions = [2.5, 0.0, 2, 8]\n    >>> references = [3, -0.5, 2, 7]\n    >>> results = mae_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'mae': 0.5}\n\n    If you're using multi-dimensional lists, then set the config as follows :\n\n    >>> mae_metric = datasets.load_metric(\"mae\", \"multilist\")\n    >>> predictions = [[0.5, 1], [-1, 1], [7, -6]]\n    >>> references = [[0, 2], [-1, 2], [8, -5]]\n    >>> results = mae_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {'mae': 0.75}\n    >>> results = mae_metric.compute(predictions=predictions, references=references, multioutput='raw_values')\n    >>> print(results)\n    {'mae': array([0.5, 1. ])}\n"
@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION						,	_KWARGS_DESCRIPTION   )
class 		SCREAMING_SNAKE_CASE__					(		datasets.Metric   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


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

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									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 __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase , __UpperCamelCase=None , __UpperCamelCase="uniform_average"    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      mean_absolute_error(__UpperCamelCase , __UpperCamelCase , sample_weight=__UpperCamelCase , multioutput=__UpperCamelCase    )

									return {"mae": mae_score}


import os
import pickle
import tempfile
import unittest
from typing import Callable, Optional

import numpy as np

from transformers import (
    BatchEncoding,
    BertTokenizer,
    BertTokenizerFast,
    PreTrainedTokenizer,
    PreTrainedTokenizerFast,
    TensorType,
    TokenSpan,
    is_tokenizers_available,
)
from transformers.models.gpta.tokenization_gpta import GPTaTokenizer
from transformers.testing_utils import CaptureStderr, require_flax, require_tf, require_tokenizers, require_torch, slow


if is_tokenizers_available():
					from tokenizers import Tokenizer
					from tokenizers.models import WordPiece
class 		SCREAMING_SNAKE_CASE__					(		unittest.TestCase   ):







						"""simple docstring"""




						def __lowerCamelCase					(				self , __UpperCamelCase    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[str]								=      list(tokenizer_class.max_model_input_sizes.keys()    )
									for model_name in sa_models[:1]:
												__UpperCamelCase    :    int								=      tokenizer_class.from_pretrained(__UpperCamelCase    )
												self.assertIsNotNone(__UpperCamelCase    )
												self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )
												self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )

												for special_tok in tokenizer.all_special_tokens:
															self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )
															__UpperCamelCase    :    str								=      tokenizer.convert_tokens_to_ids(__UpperCamelCase    )
															self.assertIsInstance(__UpperCamelCase , __UpperCamelCase    )

						def __lowerCamelCase					(				self , __UpperCamelCase , __UpperCamelCase = None    )							->	Tuple:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[Any]								=      pickle.dumps(__UpperCamelCase    )
									self.assertIsNotNone(__UpperCamelCase    )

									__UpperCamelCase    :    List[str]								=      pickle.loads(__UpperCamelCase    )

									# Ensure is_fast is correctly restored
									self.assertEqual(be_restored.is_fast , be_original.is_fast    )

									# Ensure encodings are potentially correctly restored
									if be_original.is_fast:
												self.assertIsNotNone(be_restored.encodings    )
									else:
												self.assertIsNone(be_restored.encodings    )

									# Ensure the keys are the same
									for original_v, restored_v in zip(be_original.values() , be_restored.values()    ):
												if equal_op:
															self.assertTrue(equal_op(__UpperCamelCase , __UpperCamelCase    )    )
												else:
															self.assertEqual(__UpperCamelCase , __UpperCamelCase    )

						@slow
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									self.check_tokenizer_from_pretrained(__UpperCamelCase    )

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									self.assertEqual(TensorType("tf"    ) , TensorType.TENSORFLOW    )
									self.assertEqual(TensorType("pt"    ) , TensorType.PYTORCH    )
									self.assertEqual(TensorType("np"    ) , TensorType.NUMPY    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									import numpy as np

									__UpperCamelCase    :    str								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Optional[Any]								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									# Python no tensor
									with self.subTest("BatchEncoding (Python, return_tensors=None)"    ):
												self.assert_dump_and_restore(tokenizer_p("Small example to encode"    )    )

									with self.subTest("BatchEncoding (Python, return_tensors=NUMPY)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.NUMPY    ) , np.array_equal    )

									with self.subTest("BatchEncoding (Rust, return_tensors=None)"    ):
												self.assert_dump_and_restore(tokenizer_r("Small example to encode"    )    )

									with self.subTest("BatchEncoding (Rust, return_tensors=NUMPY)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.NUMPY    ) , np.array_equal    )

						@require_tf
						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									import tensorflow as tf

									def tf_array_equals(__UpperCamelCase , __UpperCamelCase    ):
												return tf.reduce_all(tf.equal(__UpperCamelCase , __UpperCamelCase    )    )

									__UpperCamelCase    :    int								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Dict								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("BatchEncoding (Python, return_tensors=TENSORFLOW)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.TENSORFLOW    ) , __UpperCamelCase    )

									with self.subTest("BatchEncoding (Rust, return_tensors=TENSORFLOW)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.TENSORFLOW    ) , __UpperCamelCase    )

						@require_torch
						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									import torch

									__UpperCamelCase    :    List[Any]								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Optional[Any]								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("BatchEncoding (Python, return_tensors=PYTORCH)"    ):
												self.assert_dump_and_restore(
												    tokenizer_p("Small example to encode" , return_tensors=TensorType.PYTORCH    ) , torch.equal    )

									with self.subTest("BatchEncoding (Rust, return_tensors=PYTORCH)"    ):
												self.assert_dump_and_restore(
												    tokenizer_r("Small example to encode" , return_tensors=TensorType.PYTORCH    ) , torch.equal    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Any:




									'''simple docstring'''


									__UpperCamelCase    :    Optional[int]								=      BertTokenizer.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Tuple								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )

									with self.subTest("Python Tokenizer"    ):
												self.assertFalse(tokenizer_p("Small example to_encode"    ).is_fast    )

									with self.subTest("Rust Tokenizer"    ):
												self.assertTrue(tokenizer_r("Small example to_encode"    ).is_fast    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Union[str, Any]:




									'''simple docstring'''


									__UpperCamelCase    :    Any								=      BertTokenizerFast.from_pretrained("bert-base-cased"    )
									__UpperCamelCase    :    Dict								=      tokenizer_r(["Test", "\xad", "test"] , is_split_into_words=__UpperCamelCase    )

									self.assertEqual(encoded.word_to_tokens(0    ) , TokenSpan(start=1 , end=2    )    )
									self.assertEqual(encoded.word_to_tokens(1    ) , __UpperCamelCase    )
									self.assertEqual(encoded.word_to_tokens(2    ) , TokenSpan(start=2 , end=3    )    )

						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    List[str]								=      batch.convert_to_tensors(tensor_type="np"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Optional[Any]								=      batch.convert_to_tensors(tensor_type="np"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Union[str, Any]								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    int								=      batch.convert_to_tensors(tensor_type="np" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_torch
						def __lowerCamelCase					(				self    )							->	List[str]:




									'''simple docstring'''


									__UpperCamelCase    :    Dict								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    List[Any]								=      batch.convert_to_tensors(tensor_type="pt"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Tuple								=      batch.convert_to_tensors(tensor_type="pt"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Union[str, Any]								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    List[Any]								=      batch.convert_to_tensors(tensor_type="pt" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_tf
						def __lowerCamelCase					(				self    )							->	Optional[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    Tuple								=      batch.convert_to_tensors(tensor_type="tf"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Optional[int]								=      batch.convert_to_tensors(tensor_type="tf"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    Union[str, Any]								=      batch.convert_to_tensors(tensor_type="tf" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						@require_flax
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      BatchEncoding({"inputs": [[1, 2, 3], [4, 5, 6]], "labels": [0, 1]}    )
									__UpperCamelCase    :    int								=      batch.convert_to_tensors(tensor_type="jax"    )
									self.assertEqual(tensor_batch["inputs"].shape , (2, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (2,)    )
									# test converting the converted
									with CaptureStderr() as cs:
												__UpperCamelCase    :    Dict								=      batch.convert_to_tensors(tensor_type="jax"    )
									self.assertFalse(len(cs.err    ) , msg=f'''should have no warning, but got {cs.err}'''    )

									__UpperCamelCase    :    Tuple								=      BatchEncoding({"inputs": [1, 2, 3], "labels": 0}    )
									__UpperCamelCase    :    Union[str, Any]								=      batch.convert_to_tensors(tensor_type="jax" , prepend_batch_axis=__UpperCamelCase    )
									self.assertEqual(tensor_batch["inputs"].shape , (1, 3)    )
									self.assertEqual(tensor_batch["labels"].shape , (1,)    )

						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    str								=      [{"input_ids": np.array([0, 1, 2]    )}, {"input_ids": np.array([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    Any								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , np.ndarray    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="np"    )
									self.assertTrue(isinstance(batch["input_ids"] , np.ndarray    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_torch
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									import torch

									__UpperCamelCase    :    List[str]								=      [{"input_ids": torch.tensor([0, 1, 2]    )}, {"input_ids": torch.tensor([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    str								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    str								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , torch.Tensor    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    int								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="pt"    )
									self.assertTrue(isinstance(batch["input_ids"] , torch.Tensor    )    )
									self.assertEqual(batch["input_ids"].tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_tf
						def __lowerCamelCase					(				self    )							->	List[Any]:




									'''simple docstring'''


									import tensorflow as tf

									__UpperCamelCase    :    List[Any]								=      [{"input_ids": tf.constant([0, 1, 2]    )}, {"input_ids": tf.constant([0, 1, 2, 3]    )}]
									__UpperCamelCase    :    int								=      BertTokenizer.from_pretrained("bert-base-cased"    )

									__UpperCamelCase    :    Optional[Any]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase    )
									self.assertTrue(isinstance(batch["input_ids"] , tf.Tensor    )    )
									self.assertEqual(batch["input_ids"].numpy().tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )
									__UpperCamelCase    :    List[str]								=      tokenizer.pad(__UpperCamelCase , padding=__UpperCamelCase , return_tensors="tf"    )
									self.assertTrue(isinstance(batch["input_ids"] , tf.Tensor    )    )
									self.assertEqual(batch["input_ids"].numpy().tolist() , [[0, 1, 2, tokenizer.pad_token_id], [0, 1, 2, 3]]    )

						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	int:




									'''simple docstring'''


									__UpperCamelCase    :    List[Any]								=      Tokenizer(WordPiece(unk_token="[UNK]"    )    )
									PreTrainedTokenizerFast(tokenizer_object=__UpperCamelCase    )




						@require_tokenizers
						def __lowerCamelCase					(				self    )							->	Optional[int]:




									'''simple docstring'''


									__UpperCamelCase    :    Union[str, Any]								=      Tokenizer(WordPiece(unk_token="[UNK]"    )    )
									with tempfile.TemporaryDirectory() as tmpdirname:
												bert_tokenizer.save(os.path.join(__UpperCamelCase , "tokenizer.json"    )    )
												PreTrainedTokenizerFast(tokenizer_file=os.path.join(__UpperCamelCase , "tokenizer.json"    )    )