



'''simple docstring'''





from __future__ import annotations

import unittest

from transformers import is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
   import tensorflow as tf

   from transformers import (
       TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST,
       TFXLMForMultipleChoice,
       TFXLMForQuestionAnsweringSimple,
       TFXLMForSequenceClassification,
       TFXLMForTokenClassification,
       TFXLMModel,
       TFXLMWithLMHeadModel,
       XLMConfig,
   )






class       lowerCamelCase_					:
  """simple docstring"""




  def __init__(				self   :			Optional[int]    ,			_a   :			Union[str, Any]    ,			)      ->      str:
    __lowerCamelCase : int					 =				parent
    __lowerCamelCase : Union[str, Any]					 =				13
    __lowerCamelCase : int					 =				7
    __lowerCamelCase : List[Any]					 =				True
    __lowerCamelCase : List[str]					 =				True
    __lowerCamelCase : Dict					 =				True
    __lowerCamelCase : str					 =				True
    __lowerCamelCase : List[Any]					 =				True
    __lowerCamelCase : List[Any]					 =				False
    __lowerCamelCase : Optional[Any]					 =				False
    __lowerCamelCase : List[str]					 =				False
    __lowerCamelCase : Union[str, Any]					 =				2
    __lowerCamelCase : Union[str, Any]					 =				99
    __lowerCamelCase : str					 =				0
    __lowerCamelCase : int					 =				32
    __lowerCamelCase : Union[str, Any]					 =				2
    __lowerCamelCase : List[str]					 =				4
    __lowerCamelCase : Optional[Any]					 =				0.1
    __lowerCamelCase : Tuple					 =				0.1
    __lowerCamelCase : str					 =				512
    __lowerCamelCase : str					 =				16
    __lowerCamelCase : Dict					 =				2
    __lowerCamelCase : List[Any]					 =				0.02
    __lowerCamelCase : Tuple					 =				3
    __lowerCamelCase : Dict					 =				4
    __lowerCamelCase : Tuple					 =				'last'
    __lowerCamelCase : Dict					 =				True
    __lowerCamelCase : Any					 =				None
    __lowerCamelCase : Optional[Any]					 =				0




  def 		_lowercase  (				self   :			Union[str, Any]     )      ->      Any:
    __lowerCamelCase : Tuple					 =				ids_tensor([self.batch_size, self.seq_length]    ,			self.vocab_size     )
    __lowerCamelCase : Optional[Any]					 =				random_attention_mask([self.batch_size, self.seq_length]    ,			dtype=tf.floataa     )

    __lowerCamelCase : Optional[int]					 =				None
    if self.use_input_lengths:
      __lowerCamelCase : Any					 =				(
          ids_tensor([self.batch_size]    ,			vocab_size=2     ) + self.seq_length - 2
      )  # small variation of seq_length

    __lowerCamelCase : Optional[Any]					 =				None
    if self.use_token_type_ids:
      __lowerCamelCase : List[Any]					 =				ids_tensor([self.batch_size, self.seq_length]    ,			self.n_langs     )

    __lowerCamelCase : List[str]					 =				None
    __lowerCamelCase : List[str]					 =				None
    __lowerCamelCase : Union[str, Any]					 =				None
    if self.use_labels:
      __lowerCamelCase : str					 =				ids_tensor([self.batch_size]    ,			self.type_sequence_label_size     )
      __lowerCamelCase : List[str]					 =				ids_tensor([self.batch_size, self.seq_length]    ,			self.num_labels     )
      __lowerCamelCase : Union[str, Any]					 =				ids_tensor([self.batch_size]    ,			2    ,			dtype=tf.floataa     )
      __lowerCamelCase : List[Any]					 =				ids_tensor([self.batch_size]    ,			self.num_choices     )

    __lowerCamelCase : Union[str, Any]					 =				XLMConfig(
        vocab_size=self.vocab_size    ,			n_special=self.n_special    ,			emb_dim=self.hidden_size    ,			n_layers=self.num_hidden_layers    ,			n_heads=self.num_attention_heads    ,			dropout=self.hidden_dropout_prob    ,			attention_dropout=self.attention_probs_dropout_prob    ,			gelu_activation=self.gelu_activation    ,			sinusoidal_embeddings=self.sinusoidal_embeddings    ,			asm=self.asm    ,			causal=self.causal    ,			n_langs=self.n_langs    ,			max_position_embeddings=self.max_position_embeddings    ,			initializer_range=self.initializer_range    ,			summary_type=self.summary_type    ,			use_proj=self.use_proj    ,			bos_token_id=self.bos_token_id    ,			)

    return (
        config,
        input_ids,
        token_type_ids,
        input_lengths,
        sequence_labels,
        token_labels,
        is_impossible_labels,
        choice_labels,
        input_mask,
    )




  def 		_lowercase  (				self   :			Dict    ,			_a   :			Tuple    ,			_a   :			Dict    ,			_a   :			List[str]    ,			_a   :			Optional[int]    ,			_a   :			Union[str, Any]    ,			_a   :			List[Any]    ,			_a   :			Optional[Any]    ,			_a   :			List[str]    ,			_a   :			Optional[Any]    ,			)      ->      List[str]:
    __lowerCamelCase : Optional[int]					 =				TFXLMModel(config=_a     )
    __lowerCamelCase : Optional[int]					 =				{'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
    __lowerCamelCase : Union[str, Any]					 =				model(_a     )

    __lowerCamelCase : List[str]					 =				[input_ids, input_mask]
    __lowerCamelCase : Optional[Any]					 =				model(_a     )
    self.parent.assertEqual(result.last_hidden_state.shape    ,			(self.batch_size, self.seq_length, self.hidden_size)     )




  def 		_lowercase  (				self   :			List[str]    ,			_a   :			List[str]    ,			_a   :			Dict    ,			_a   :			int    ,			_a   :			Tuple    ,			_a   :			List[Any]    ,			_a   :			List[str]    ,			_a   :			List[Any]    ,			_a   :			List[str]    ,			_a   :			Optional[int]    ,			)      ->      int:
    __lowerCamelCase : str					 =				TFXLMWithLMHeadModel(_a     )

    __lowerCamelCase : str					 =				{'input_ids': input_ids, 'lengths': input_lengths, 'langs': token_type_ids}
    __lowerCamelCase : str					 =				model(_a     )

    __lowerCamelCase : Optional[int]					 =				outputs

    self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.vocab_size)     )




  def 		_lowercase  (				self   :			Any    ,			_a   :			int    ,			_a   :			List[Any]    ,			_a   :			List[str]    ,			_a   :			Any    ,			_a   :			List[str]    ,			_a   :			int    ,			_a   :			Optional[Any]    ,			_a   :			Union[str, Any]    ,			_a   :			List[Any]    ,			)      ->      str:
    __lowerCamelCase : Optional[Any]					 =				TFXLMForQuestionAnsweringSimple(_a     )

    __lowerCamelCase : str					 =				{'input_ids': input_ids, 'lengths': input_lengths}

    __lowerCamelCase : Tuple					 =				model(_a     )

    self.parent.assertEqual(result.start_logits.shape    ,			(self.batch_size, self.seq_length)     )
    self.parent.assertEqual(result.end_logits.shape    ,			(self.batch_size, self.seq_length)     )




  def 		_lowercase  (				self   :			Dict    ,			_a   :			Optional[int]    ,			_a   :			str    ,			_a   :			Optional[Any]    ,			_a   :			List[str]    ,			_a   :			Union[str, Any]    ,			_a   :			Dict    ,			_a   :			Union[str, Any]    ,			_a   :			Optional[Any]    ,			_a   :			Tuple    ,			)      ->      List[Any]:
    __lowerCamelCase : Union[str, Any]					 =				TFXLMForSequenceClassification(_a     )

    __lowerCamelCase : Dict					 =				{'input_ids': input_ids, 'lengths': input_lengths}

    __lowerCamelCase : str					 =				model(_a     )

    self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.type_sequence_label_size)     )




  def 		_lowercase  (				self   :			str    ,			_a   :			List[str]    ,			_a   :			Dict    ,			_a   :			Dict    ,			_a   :			Union[str, Any]    ,			_a   :			Dict    ,			_a   :			List[Any]    ,			_a   :			List[Any]    ,			_a   :			Union[str, Any]    ,			_a   :			Optional[int]    ,			)      ->      Dict:
    __lowerCamelCase : Any					 =				self.num_labels
    __lowerCamelCase : List[str]					 =				TFXLMForTokenClassification(config=_a     )
    __lowerCamelCase : Optional[Any]					 =				{'input_ids': input_ids, 'attention_mask': input_mask, 'token_type_ids': token_type_ids}
    __lowerCamelCase : str					 =				model(_a     )
    self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.seq_length, self.num_labels)     )




  def 		_lowercase  (				self   :			Optional[Any]    ,			_a   :			Any    ,			_a   :			List[str]    ,			_a   :			Tuple    ,			_a   :			Any    ,			_a   :			Union[str, Any]    ,			_a   :			Any    ,			_a   :			List[Any]    ,			_a   :			Optional[int]    ,			_a   :			Dict    ,			)      ->      Any:
    __lowerCamelCase : Tuple					 =				self.num_choices
    __lowerCamelCase : List[str]					 =				TFXLMForMultipleChoice(config=_a     )
    __lowerCamelCase : Tuple					 =				tf.tile(tf.expand_dims(_a    ,			1     )    ,			(1, self.num_choices, 1)     )
    __lowerCamelCase : str					 =				tf.tile(tf.expand_dims(_a    ,			1     )    ,			(1, self.num_choices, 1)     )
    __lowerCamelCase : Union[str, Any]					 =				tf.tile(tf.expand_dims(_a    ,			1     )    ,			(1, self.num_choices, 1)     )
    __lowerCamelCase : Optional[Any]					 =				{
        'input_ids': multiple_choice_inputs_ids,
        'attention_mask': multiple_choice_input_mask,
        'token_type_ids': multiple_choice_token_type_ids,
    }
    __lowerCamelCase : Optional[int]					 =				model(_a     )
    self.parent.assertEqual(result.logits.shape    ,			(self.batch_size, self.num_choices)     )




  def 		_lowercase  (				self   :			Union[str, Any]     )      ->      Optional[int]:
    __lowerCamelCase : Optional[Any]					 =				self.prepare_config_and_inputs()
    (
        __lowerCamelCase
    ) : Optional[int]					 =				config_and_inputs
    __lowerCamelCase : Optional[int]					 =				{
        'input_ids': input_ids,
        'token_type_ids': token_type_ids,
        'langs': token_type_ids,
        'lengths': input_lengths,
    }
    return config, inputs_dict






@require_tf
class       lowerCamelCase_					(       SCREAMING_SNAKE_CASE_     ,     SCREAMING_SNAKE_CASE_     ,     unittest.TestCase  ):
  """simple docstring"""




  a_							      =(
      (
          TFXLMModel,
          TFXLMWithLMHeadModel,
          TFXLMForSequenceClassification,
          TFXLMForQuestionAnsweringSimple,
          TFXLMForTokenClassification,
          TFXLMForMultipleChoice,
      )
      if is_tf_available()
      else ()
  )
  a_							      =(
      (TFXLMWithLMHeadModel,) if is_tf_available() else ()
  )  # TODO (PVP): Check other models whether language generation is also applicable
  a_							      =(
      {
          """feature-extraction""": TFXLMModel,
          """fill-mask""": TFXLMWithLMHeadModel,
          """question-answering""": TFXLMForQuestionAnsweringSimple,
          """text-classification""": TFXLMForSequenceClassification,
          """text-generation""": TFXLMWithLMHeadModel,
          """token-classification""": TFXLMForTokenClassification,
          """zero-shot""": TFXLMForSequenceClassification,
      }
      if is_tf_available()
      else {}
  )
  a_							      =False
  a_							      =False




  def 		_lowercase  (				self   :			List[str]    ,			_a   :			Optional[Any]    ,			_a   :			Optional[int]    ,			_a   :			List[Any]    ,			_a   :			str    ,			_a   :			str     )      ->      Any:
    if (
        pipeline_test_casse_name == "QAPipelineTests"
        and tokenizer_name is not None
        and not tokenizer_name.endswith('Fast'     )
    ):
      # `QAPipelineTests` fails for a few models when the slower tokenizer are used.
      # (The slower tokenizers were never used for pipeline tests before the pipeline testing rework)
      # TODO: check (and possibly fix) the `QAPipelineTests` with slower tokenizer
      return True

    return False




  def 		_lowercase  (				self   :			Optional[Any]     )      ->      Optional[Any]:
    __lowerCamelCase : List[str]					 =				TFXLMModelTester(self     )
    __lowerCamelCase : List[str]					 =				ConfigTester(self    ,			config_class=_a    ,			emb_dim=37     )




  def 		_lowercase  (				self   :			List[Any]     )      ->      Tuple:
    self.config_tester.run_common_tests()




  def 		_lowercase  (				self   :			Optional[int]     )      ->      int:
    __lowerCamelCase : str					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_model(*_a     )




  def 		_lowercase  (				self   :			Optional[int]     )      ->      Dict:
    __lowerCamelCase : Dict					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_lm_head(*_a     )




  def 		_lowercase  (				self   :			List[str]     )      ->      int:
    __lowerCamelCase : Tuple					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_qa(*_a     )




  def 		_lowercase  (				self   :			Union[str, Any]     )      ->      Tuple:
    __lowerCamelCase : List[Any]					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_sequence_classif(*_a     )




  def 		_lowercase  (				self   :			Optional[int]     )      ->      Tuple:
    __lowerCamelCase : Dict					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_for_token_classification(*_a     )




  def 		_lowercase  (				self   :			List[Any]     )      ->      Optional[int]:
    __lowerCamelCase : str					 =				self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_xlm_for_multiple_choice(*_a     )




  @slow
  def 		_lowercase  (				self   :			Dict     )      ->      Optional[int]:
    for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
      __lowerCamelCase : Union[str, Any]					 =				TFXLMModel.from_pretrained(_a     )
      self.assertIsNotNone(_a     )






@require_tf
class       lowerCamelCase_					(       unittest.TestCase  ):
  """simple docstring"""




  @slow
  def 		_lowercase  (				self   :			List[Any]     )      ->      Tuple:
    __lowerCamelCase : Tuple					 =				TFXLMWithLMHeadModel.from_pretrained('xlm-mlm-en-2048'     )
    __lowerCamelCase : Any					 =				tf.convert_to_tensor([[14, 447]]    ,			dtype=tf.intaa     )  # the president
    __lowerCamelCase : Optional[int]					 =				[
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
        14,
        447,
    ]  # the president the president the president the president the president the president the president the president the president the president
    # TODO(PVP): this and other input_ids I tried for generation give pretty bad results. Not sure why. Model might just not be made for auto-regressive inference
    __lowerCamelCase : Dict					 =				model.generate(_a    ,			do_sample=_a     )
    self.assertListEqual(output_ids[0].numpy().tolist()    ,			_a     )











'''simple docstring'''





import decimal

def  a_  (							)   ->   int:
  __lowerCamelCase : int					 =				0
  __lowerCamelCase : Any					 =				decimal.Context(prec=105 )
  for i in range(2 ,100 ):
    __lowerCamelCase : str					 =				decimal.Decimal(_lowerCAmelCase )
    __lowerCamelCase : int					 =				number.sqrt(_lowerCAmelCase )
    if len(str(_lowerCAmelCase ) ) > 1:
      answer += int(str(_lowerCAmelCase )[0] )
      __lowerCamelCase : List[str]					 =				str(_lowerCAmelCase )[2:101]
      answer += sum(int(_lowerCAmelCase ) for x in sqrt_number_str )
  return answer


if __name__ == "__main__":
   import doctest

   doctest.testmod()
   print(f'''{solution() = }''')






