





import unittest
from pathlib import Path
from tempfile import TemporaryDirectory

from transformers import AutoConfig, TFAutoModel, is_tensorflow_text_available, is_tf_available
from transformers.models.bert.tokenization_bert import BertTokenizer
from transformers.testing_utils import require_tensorflow_text, require_tf, slow


if is_tf_available():
       import tensorflow as tf

if is_tensorflow_text_available():
       from transformers.models.bert import TFBertTokenizer


_lowerCamelCase			       =      ['bert-base-uncased', 'bert-base-cased']
_lowerCamelCase			       =      'hf-internal-testing/tiny-bert-tf-only'

if is_tf_available():







       class 			__A       (      tf.keras.Model  ):




             """simple docstring"""







             def __init__(		self      ,							a__):



                    """simple docstring"""





                    super().__init__()
                    _lowerCamelCase							:     Any	=		tokenizer
                    _lowerCamelCase							:     Dict	=		AutoConfig.from_pretrained(a__)
                    _lowerCamelCase							:     int	=		TFAutoModel.from_config(a__)



             def 				__snake_case			(		self      ,							a__):



                    """simple docstring"""





                    _lowerCamelCase							:     int	=		self.tokenizer(a__)
                    _lowerCamelCase							:     List[Any]	=		self.bert(**a__)
                    return out["pooler_output"]







@require_tf
@require_tensorflow_text
class 			__A       (      unittest.TestCase  ):




      """simple docstring"""







      def 				__snake_case			(		self):



             """simple docstring"""





             super().setUp()

             _lowerCamelCase							:     List[str]	=		[
                 BertTokenizer.from_pretrained(a__) for checkpoint in (TOKENIZER_CHECKPOINTS * 2)
             ]  # repeat for when fast_bert_tokenizer=false
             _lowerCamelCase							:     Any	=		[TFBertTokenizer.from_pretrained(a__) for checkpoint in TOKENIZER_CHECKPOINTS] + [
                 TFBertTokenizer.from_pretrained(a__      ,							use_fast_bert_tokenizer=a__)
                 for checkpoint in TOKENIZER_CHECKPOINTS
             ]
             assert len(self.tokenizers) == len(self.tf_tokenizers)

             _lowerCamelCase							:     int	=		[
                 '''This is a straightforward English test sentence.''',
                 '''This one has some weird characters\rto\nsee\r\nif  those\u00E9break things.''',
                 '''Now we\'re going to add some Chinese: 一 二 三 一二三''',
                 '''And some much more rare Chinese: 齉 堃 齉堃''',
                 '''Je vais aussi écrire en français pour tester les accents''',
                 '''Classical Irish also has some unusual characters, so in they go: Gaelaċ, ꝼ''',
             ]
             _lowerCamelCase							:     int	=		list(zip(self.test_sentences      ,							self.test_sentences[::-1]))


      def 				__snake_case			(		self):



             """simple docstring"""





             for tokenizer, tf_tokenizer in zip(self.tokenizers      ,							self.tf_tokenizers):
                    for test_inputs in (self.test_sentences, self.paired_sentences):
                           _lowerCamelCase							:     List[str]	=		tokenizer(a__      ,							return_tensors='''tf'''      ,							padding='''longest''')
                           _lowerCamelCase							:     Dict	=		tf_tokenizer(a__)

                           for key in python_outputs.keys():
                                  self.assertTrue(tf.reduce_all(python_outputs[key].shape == tf_outputs[key].shape))
                                  self.assertTrue(tf.reduce_all(tf.cast(python_outputs[key]      ,							tf.intaa) == tf_outputs[key]))


      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             for tf_tokenizer in self.tf_tokenizers:
                    _lowerCamelCase							:     Optional[Any]	=		tf_tokenizer(self.paired_sentences)
                    _lowerCamelCase							:     Union[str, Any]	=		tf_tokenizer(
                        text=[sentence[0] for sentence in self.paired_sentences]      ,							text_pair=[sentence[1] for sentence in self.paired_sentences]      ,							)
                    for key in merged_outputs.keys():
                           self.assertTrue(tf.reduce_all(tf.cast(merged_outputs[key]      ,							tf.intaa) == separated_outputs[key]))


      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             for tf_tokenizer in self.tf_tokenizers:
                    _lowerCamelCase							:     str	=		tf.function(a__)
                    for test_inputs in (self.test_sentences, self.paired_sentences):
                           _lowerCamelCase							:     List[Any]	=		tf.constant(a__)
                           _lowerCamelCase							:     int	=		compiled_tokenizer(a__)
                           _lowerCamelCase							:     List[str]	=		tf_tokenizer(a__)

                           for key in eager_outputs.keys():
                                  self.assertTrue(tf.reduce_all(eager_outputs[key] == compiled_outputs[key]))



      @slow
      def 				__snake_case			(		self):



             """simple docstring"""





             for tf_tokenizer in self.tf_tokenizers:
                    _lowerCamelCase							:     Optional[Any]	=		ModelToSave(tokenizer=a__)
                    _lowerCamelCase							:     int	=		tf.convert_to_tensor(self.test_sentences)
                    _lowerCamelCase							:     Optional[Any]	=		model(a__)  # Build model with some sample inputs
                    with TemporaryDirectory() as tempdir:
                           _lowerCamelCase							:     Dict	=		Path(a__) / '''saved.model'''
                           model.save(a__)
                           _lowerCamelCase							:     str	=		tf.keras.models.load_model(a__)
                    _lowerCamelCase							:     Optional[Any]	=		loaded_model(a__)
                    # We may see small differences because the loaded model is compiled, so we need an epsilon for the test
                    self.assertLessEqual(tf.reduce_max(tf.abs(out - loaded_output))      ,							1e-5)








def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       return round(float(moles / volume      ) * nfactor      )




def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       return round(float((moles * 0.0_8_2_1 * temperature) / (volume)      )      )




def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       return round(float((moles * 0.0_8_2_1 * temperature) / (pressure)      )      )




def    __UpperCAmelCase(      lowercase_ ,    lowercase_ ,    lowercase_      ):
       return round(float((pressure * volume) / (0.0_8_2_1 * moles)      )      )


if __name__ == "__main__":
       import doctest

       doctest.testmod()

