



'''simple docstring'''



import unittest

from transformers import MraConfig, is_torch_available
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor, random_attention_mask


if is_torch_available():
	import torch

	from transformers import (
	    MraForMaskedLM,
	    MraForMultipleChoice,
	    MraForQuestionAnswering,
	    MraForSequenceClassification,
	    MraForTokenClassification,
	    MraModel,
	)
	from transformers.models.mra.modeling_mra import MRA_PRETRAINED_MODEL_ARCHIVE_LIST






class 					UpperCAmelCase__	:



					def __init__(    self			,				UpperCamelCase			,				UpperCamelCase=2			,				UpperCamelCase=8			,				UpperCamelCase=True			,				UpperCamelCase=True			,				UpperCamelCase=True			,				UpperCamelCase=True			,				UpperCamelCase=99			,				UpperCamelCase=16			,				UpperCamelCase=5			,				UpperCamelCase=2			,				UpperCamelCase=36			,				UpperCamelCase="gelu"			,				UpperCamelCase=0.0			,				UpperCamelCase=0.0			,				UpperCamelCase=512			,				UpperCamelCase=16			,				UpperCamelCase=2			,				UpperCamelCase=0.02			,				UpperCamelCase=3			,				UpperCamelCase=4			,				UpperCamelCase=None			,				)     ->			Tuple:
						__lowerCAmelCase												=  parent
						__lowerCAmelCase												=  batch_size
						__lowerCAmelCase												=  seq_length
						__lowerCAmelCase												=  is_training
						__lowerCAmelCase												=  use_input_mask
						__lowerCAmelCase												=  use_token_type_ids
						__lowerCAmelCase												=  use_labels
						__lowerCAmelCase												=  vocab_size
						__lowerCAmelCase												=  hidden_size
						__lowerCAmelCase												=  num_hidden_layers
						__lowerCAmelCase												=  num_attention_heads
						__lowerCAmelCase												=  intermediate_size
						__lowerCAmelCase												=  hidden_act
						__lowerCAmelCase												=  hidden_dropout_prob
						__lowerCAmelCase												=  attention_probs_dropout_prob
						__lowerCAmelCase												=  max_position_embeddings
						__lowerCAmelCase												=  type_vocab_size
						__lowerCAmelCase												=  type_sequence_label_size
						__lowerCAmelCase												=  initializer_range
						__lowerCAmelCase												=  num_labels
						__lowerCAmelCase												=  num_choices
						__lowerCAmelCase												=  scope



					def        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]			,				self.vocab_size     )

						__lowerCAmelCase												=  None
						if self.use_input_mask:
							__lowerCAmelCase												=  random_attention_mask([self.batch_size, self.seq_length]     )

						__lowerCAmelCase												=  None
						if self.use_token_type_ids:
							__lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]			,				self.type_vocab_size     )

						__lowerCAmelCase												=  None
						__lowerCAmelCase												=  None
						__lowerCAmelCase												=  None
						if self.use_labels:
							__lowerCAmelCase												=  ids_tensor([self.batch_size]			,				self.type_sequence_label_size     )
							__lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]			,				self.num_labels     )
							__lowerCAmelCase												=  ids_tensor([self.batch_size]			,				self.num_choices     )

						__lowerCAmelCase												=  self.get_config()

						return config, input_ids, token_type_ids, input_mask, sequence_labels, token_labels, choice_labels



					def        UpperCAmelCase_ (    self     )     ->			int:
						return MraConfig(
						    vocab_size=self.vocab_size			,				hidden_size=self.hidden_size			,				num_hidden_layers=self.num_hidden_layers			,				num_attention_heads=self.num_attention_heads			,				intermediate_size=self.intermediate_size			,				hidden_act=self.hidden_act			,				hidden_dropout_prob=self.hidden_dropout_prob			,				attention_probs_dropout_prob=self.attention_probs_dropout_prob			,				max_position_embeddings=self.max_position_embeddings			,				type_vocab_size=self.type_vocab_size			,				is_decoder=UpperCamelCase			,				initializer_range=self.initializer_range			,				)



					def        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__lowerCAmelCase												=  self.get_config()
						__lowerCAmelCase												=  300
						return config



					def        UpperCAmelCase_ (    self     )     ->			List[str]:
						(
						    (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       
						)												=  self.prepare_config_and_inputs()

						__lowerCAmelCase												=  True
						__lowerCAmelCase												=  floats_tensor([self.batch_size, self.seq_length, self.hidden_size]     )
						__lowerCAmelCase												=  ids_tensor([self.batch_size, self.seq_length]			,				vocab_size=2     )

						return (
						    config,
						    input_ids,
						    token_type_ids,
						    input_mask,
						    sequence_labels,
						    token_labels,
						    choice_labels,
						    encoder_hidden_states,
						    encoder_attention_mask,
						)



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			Tuple:
						__lowerCAmelCase												=  MraModel(config=UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase     )
						__lowerCAmelCase												=  model(UpperCamelCase			,				token_type_ids=UpperCamelCase     )
						__lowerCAmelCase												=  model(UpperCamelCase     )
						self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				)     ->			List[str]:
						__lowerCAmelCase												=  True
						__lowerCAmelCase												=  MraModel(UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(
						    UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				encoder_hidden_states=UpperCamelCase			,				encoder_attention_mask=UpperCamelCase			,				)
						__lowerCAmelCase												=  model(
						    UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				encoder_hidden_states=UpperCamelCase			,				)
						__lowerCAmelCase												=  model(UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase     )
						self.parent.assertEqual(result.last_hidden_state.shape			,				(self.batch_size, self.seq_length, self.hidden_size)     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			Optional[int]:
						__lowerCAmelCase												=  MraForMaskedLM(config=UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				labels=UpperCamelCase     )
						self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.vocab_size)     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			Optional[Any]:
						__lowerCAmelCase												=  MraForQuestionAnswering(config=UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(
						    UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				start_positions=UpperCamelCase			,				end_positions=UpperCamelCase			,				)
						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        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			List[Any]:
						__lowerCAmelCase												=  self.num_labels
						__lowerCAmelCase												=  MraForSequenceClassification(UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				labels=UpperCamelCase     )
						self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_labels)     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			List[Any]:
						__lowerCAmelCase												=  self.num_labels
						__lowerCAmelCase												=  MraForTokenClassification(config=UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  model(UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				labels=UpperCamelCase     )
						self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.seq_length, self.num_labels)     )



					def        UpperCAmelCase_ (    self			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase			,				UpperCamelCase     )     ->			Optional[int]:
						__lowerCAmelCase												=  self.num_choices
						__lowerCAmelCase												=  MraForMultipleChoice(config=UpperCamelCase     )
						model.to(UpperCamelCase     )
						model.eval()
						__lowerCAmelCase												=  input_ids.unsqueeze(1     ).expand(-1			,				self.num_choices			,				-1     ).contiguous()
						__lowerCAmelCase												=  token_type_ids.unsqueeze(1     ).expand(-1			,				self.num_choices			,				-1     ).contiguous()
						__lowerCAmelCase												=  input_mask.unsqueeze(1     ).expand(-1			,				self.num_choices			,				-1     ).contiguous()
						__lowerCAmelCase												=  model(
						    UpperCamelCase			,				attention_mask=UpperCamelCase			,				token_type_ids=UpperCamelCase			,				labels=UpperCamelCase			,				)
						self.parent.assertEqual(result.logits.shape			,				(self.batch_size, self.num_choices)     )



					def        UpperCAmelCase_ (    self     )     ->			Dict:
						__lowerCAmelCase												=  self.prepare_config_and_inputs()
						(
						    (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       (
						    __lowerCAmelCase
						)							,       
						)												=  config_and_inputs
						__lowerCAmelCase												=  {"input_ids": input_ids, "token_type_ids": token_type_ids, "attention_mask": input_mask}
						return config, inputs_dict






@require_torch
class 					UpperCAmelCase__	(		UpperCamelCase__							,       unittest.TestCase ):
					a      :     Optional[int]        =							(
					    (
					        MraModel,
					        MraForMaskedLM,
					        MraForMultipleChoice,
					        MraForQuestionAnswering,
					        MraForSequenceClassification,
					        MraForTokenClassification,
					    )
					    if is_torch_available()
					    else ()
					)
					a      :     List[Any]        =							False
					a      :     Any        =							False
					a      :     Tuple        =							False
					a      :     Optional[int]        =							False

					a      :     str        =							()



					def        UpperCAmelCase_ (    self     )     ->			Union[str, Any]:
						__lowerCAmelCase												=  MraModelTester(self     )
						__lowerCAmelCase												=  ConfigTester(self			,				config_class=UpperCamelCase			,				hidden_size=37     )



					def        UpperCAmelCase_ (    self     )     ->			Tuple:
						self.config_tester.run_common_tests()



					def        UpperCAmelCase_ (    self     )     ->			List[str]:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			str:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						for type in ["absolute", "relative_key", "relative_key_query"]:
							__lowerCAmelCase												=  type
							self.model_tester.create_and_check_model(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			List[str]:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			Union[str, Any]:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			int:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_question_answering(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			List[Any]:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase     )



					def        UpperCAmelCase_ (    self     )     ->			Tuple:
						__lowerCAmelCase												=  self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_token_classification(*UpperCamelCase     )



					@slow
					def        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						for model_name in MRA_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
							__lowerCAmelCase												=  MraModel.from_pretrained(UpperCamelCase     )
							self.assertIsNotNone(UpperCamelCase     )



					@unittest.skip(reason="MRA does not output attentions"     )
					def        UpperCAmelCase_ (    self     )     ->			Optional[Any]:
						return






@require_torch
class 					UpperCAmelCase__	(		unittest.TestCase ):



					@slow
					def        UpperCAmelCase_ (    self     )     ->			str:
						__lowerCAmelCase												=  MraModel.from_pretrained("uw-madison/mra-base-512-4"     )
						__lowerCAmelCase												=  torch.arange(256     ).unsqueeze(0     )

						with torch.no_grad():
							__lowerCAmelCase												=  model(UpperCamelCase     )[0]

						__lowerCAmelCase												=  torch.Size((1, 256, 768)     )
						self.assertEqual(output.shape			,				UpperCamelCase     )

						__lowerCAmelCase												=  torch.tensor(
						    [[[-0.01_40, 0.08_30, -0.03_81], [0.15_46, 0.14_02, 0.02_20], [0.11_62, 0.08_51, 0.01_65]]]     )

						self.assertTrue(torch.allclose(output[:, :3, :3]			,				UpperCamelCase			,				atol=1E-4     )     )



					@slow
					def        UpperCAmelCase_ (    self     )     ->			List[str]:
						__lowerCAmelCase												=  MraForMaskedLM.from_pretrained("uw-madison/mra-base-512-4"     )
						__lowerCAmelCase												=  torch.arange(256     ).unsqueeze(0     )

						with torch.no_grad():
							__lowerCAmelCase												=  model(UpperCamelCase     )[0]

						__lowerCAmelCase												=  5_0265

						__lowerCAmelCase												=  torch.Size((1, 256, vocab_size)     )
						self.assertEqual(output.shape			,				UpperCamelCase     )

						__lowerCAmelCase												=  torch.tensor(
						    [[[9.25_95, -3.60_38, 11.88_19], [9.38_69, -3.26_93, 11.09_56], [11.85_24, -3.49_38, 13.12_10]]]     )

						self.assertTrue(torch.allclose(output[:, :3, :3]			,				UpperCamelCase			,				atol=1E-4     )     )



					@slow
					def        UpperCAmelCase_ (    self     )     ->			Optional[int]:
						__lowerCAmelCase												=  MraForMaskedLM.from_pretrained("uw-madison/mra-base-4096-8-d3"     )
						__lowerCAmelCase												=  torch.arange(4096     ).unsqueeze(0     )

						with torch.no_grad():
							__lowerCAmelCase												=  model(UpperCamelCase     )[0]

						__lowerCAmelCase												=  5_0265

						__lowerCAmelCase												=  torch.Size((1, 4096, vocab_size)     )
						self.assertEqual(output.shape			,				UpperCamelCase     )

						__lowerCAmelCase												=  torch.tensor(
						    [[[5.47_89, -2.35_64, 7.50_64], [7.90_67, -1.33_69, 9.96_68], [9.07_12, -1.81_06, 7.03_80]]]     )

						self.assertTrue(torch.allclose(output[:, :3, :3]			,				UpperCamelCase			,				atol=1E-4     )     )




'''simple docstring'''



import re



def   __lowerCAmelCase					(							lowerCamelCase   :						str					):






	'''simple docstring'''




	__lowerCAmelCase												=  re.compile(
	    r"^(?:0|94|\+94|0{2}94)" r"7(0|1|2|4|5|6|7|8)" r"(-| |)" r"\d{7}$"					)

	return bool(re.search(lowerCamelCase				,		lowerCamelCase					)					)


if __name__ == "__main__":
	lowerCAmelCase	:		Optional[Any]				=   '''0094702343221'''

	print(is_sri_lankan_phone_number(phone))