"""simple docstring"""

import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard






class 						_lowercase      (		unittest.TestCase	):



						"""simple docstring"""




						def    UpperCAmelCase_      (							self				:  List[Any]							)							->							Tuple:
													'''simple docstring'''



													__UpperCamelCase		     ={
													    "model_details": {
													        "Organization": "testing",
													        "Model date": "today",
													        "Model version": "v2.1, Developed by Test Corp in 2019.",
													        "Architecture": "Convolutional Neural Network.",
													    },
													    "metrics": "BLEU and ROUGE-1",
													    "evaluation_data": {
													        "Datasets": {"BLEU": "My-great-dataset-v1", "ROUGE-1": "My-short-dataset-v2.1"},
													        "Preprocessing": "See details on https://arxiv.org/pdf/1810.03993.pdf",
													    },
													    "training_data": {
													        "Dataset": "English Wikipedia dump dated 2018-12-01",
													        "Preprocessing": (
													            "Using SentencePiece vocabulary of size 52k tokens. See details on"
													            " https://arxiv.org/pdf/1810.03993.pdf"
													        ),
													    },
													    "quantitative_analyses": {"BLEU": 55.1, "ROUGE-1": 76},
													}





						def    UpperCAmelCase_      (							self				:  Union[str, Any]							)							->							Optional[Any]:
													'''simple docstring'''



													__UpperCamelCase		     =ModelCard.from_dict(self.inputs_dict							)
													self.assertTrue(hasattr(lowercase_			,      '''model_details'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''intended_use'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''factors'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''metrics'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''evaluation_data'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''training_data'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''quantitative_analyses'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''ethical_considerations'''							)							)
													self.assertTrue(hasattr(lowercase_			,      '''caveats_and_recommendations'''							)							)





						def    UpperCAmelCase_      (							self				:  Any							)							->							Optional[int]:
													'''simple docstring'''



													__UpperCamelCase		     =ModelCard.from_dict(self.inputs_dict							)
													__UpperCamelCase		     =json.loads(modelcard.to_json_string()							)
													for key, value in self.inputs_dict.items():
																				self.assertEqual(obj[key]			,      lowercase_							)





						def    UpperCAmelCase_      (							self				:  Optional[int]							)							->							Union[str, Any]:
													'''simple docstring'''



													__UpperCamelCase		     =ModelCard.from_dict(self.inputs_dict							)

													with tempfile.TemporaryDirectory() as tmpdirname:
																				__UpperCamelCase		     =os.path.join(lowercase_			,      '''modelcard.json'''							)
																				model_card_first.to_json_file(lowercase_							)
																				__UpperCamelCase		     =ModelCard.from_json_file(lowercase_							)

													self.assertEqual(model_card_second.to_dict()			,      model_card_first.to_dict()							)





						def    UpperCAmelCase_      (							self				:  Tuple							)							->							Optional[Any]:
													'''simple docstring'''



													__UpperCamelCase		     =ModelCard.from_dict(self.inputs_dict							)

													with tempfile.TemporaryDirectory() as tmpdirname:
																				model_card_first.save_pretrained(lowercase_							)
																				__UpperCamelCase		     =ModelCard.from_pretrained(lowercase_							)

													self.assertEqual(model_card_second.to_dict()			,      model_card_first.to_dict()							)




import unittest

import numpy as np

from transformers import is_tf_available
from transformers.testing_utils import require_tf


if is_tf_available():
				import tensorflow as tf

				from transformers.activations_tf import get_tf_activation



@require_tf
class    lowercase_    (     unittest.TestCase		):



							def        UpperCamelCase       (						self				):
													_snake_case						:     int				=    tf.constant([-100, -1.0, -0.1, 0, 0.1, 1.0, 100.0]				)
													_snake_case						:     List[Any]				=    get_tf_activation("gelu"				)
													_snake_case						:     Any				=    get_tf_activation("gelu_10"				)

													_snake_case						:     Dict				=    gelu(lowercase_				)
													_snake_case						:     Optional[int]				=    geluaa(lowercase_				)

													_snake_case						:     Tuple				=    tf.where(y_gelu_aa < 10.0      ,				1.0      ,				0.0				)

													self.assertEqual(tf.math.reduce_max(lowercase_				).numpy().item()      ,				10.0				)
													self.assertTrue(np.allclose(y_gelu * clipped_mask      ,				y_gelu_aa * clipped_mask				)				)



							def        UpperCamelCase       (						self				):
													get_tf_activation("gelu"				)
													get_tf_activation("gelu_10"				)
													get_tf_activation("gelu_fast"				)
													get_tf_activation("gelu_new"				)
													get_tf_activation("glu"				)
													get_tf_activation("mish"				)
													get_tf_activation("quick_gelu"				)
													get_tf_activation("relu"				)
													get_tf_activation("sigmoid"				)
													get_tf_activation("silu"				)
													get_tf_activation("swish"				)
													get_tf_activation("tanh"				)
													with self.assertRaises(lowercase_				):
																			get_tf_activation("bogus"				)
													with self.assertRaises(lowercase_				):
																			get_tf_activation(lowercase_				)