


'''simple docstring'''






import unittest

from transformers import AlbertConfig, is_torch_available
from transformers.models.auto import get_values
from transformers.testing_utils import require_torch, slow, torch_device

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
		import torch

		from transformers import (
		    MODEL_FOR_PRETRAINING_MAPPING,
		    AlbertForMaskedLM,
		    AlbertForMultipleChoice,
		    AlbertForPreTraining,
		    AlbertForQuestionAnswering,
		    AlbertForSequenceClassification,
		    AlbertForTokenClassification,
		    AlbertModel,
		)
		from transformers.models.albert.modeling_albert import ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST




class 	a__       :





							'''simple docstring'''






							def __init__(	self      ,					lowerCamelCase_      ,					lowerCamelCase_=13      ,					lowerCamelCase_=7      ,					lowerCamelCase_=True      ,					lowerCamelCase_=True      ,					lowerCamelCase_=True      ,					lowerCamelCase_=True      ,					lowerCamelCase_=99      ,					lowerCamelCase_=16      ,					lowerCamelCase_=36      ,					lowerCamelCase_=6      ,					lowerCamelCase_=6      ,					lowerCamelCase_=6      ,					lowerCamelCase_=37      ,					lowerCamelCase_="gelu"      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=0.1      ,					lowerCamelCase_=5_12      ,					lowerCamelCase_=16      ,					lowerCamelCase_=2      ,					lowerCamelCase_=0.02      ,					lowerCamelCase_=3      ,					lowerCamelCase_=4      ,					lowerCamelCase_=None      ,					) ->							List[Any]:
														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__      =			embedding_size
														lowerCAmelCase__      =			hidden_size
														lowerCAmelCase__      =			num_hidden_layers
														lowerCAmelCase__      =			num_hidden_groups
														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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														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 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														return AlbertConfig(
														    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      ,					initializer_range=self.initializer_range      ,					num_hidden_groups=self.num_hidden_groups      ,					)







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							List[str]:
														lowerCAmelCase__      =			AlbertModel(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_     )
														lowerCAmelCase__      =			model(lowerCamelCase_      ,					token_type_ids=lowerCamelCase_     )
														lowerCAmelCase__      =			model(lowerCamelCase_     )
														self.parent.assertEqual(result.last_hidden_state.shape      ,					(self.batch_size, self.seq_length, self.hidden_size)     )
														self.parent.assertEqual(result.pooler_output.shape      ,					(self.batch_size, self.hidden_size)     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							List[Any]:
														lowerCAmelCase__      =			AlbertForPreTraining(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(
														    lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					labels=lowerCamelCase_      ,					sentence_order_label=lowerCamelCase_      ,					)
														self.parent.assertEqual(result.prediction_logits.shape      ,					(self.batch_size, self.seq_length, self.vocab_size)     )
														self.parent.assertEqual(result.sop_logits.shape      ,					(self.batch_size, config.num_labels)     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							List[str]:
														lowerCAmelCase__      =			AlbertForMaskedLM(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					labels=lowerCamelCase_     )
														self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.vocab_size)     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Union[str, Any]:
														lowerCAmelCase__      =			AlbertForQuestionAnswering(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(
														    lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					start_positions=lowerCamelCase_      ,					end_positions=lowerCamelCase_      ,					)
														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 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Any:
														lowerCAmelCase__      =			self.num_labels
														lowerCAmelCase__      =			AlbertForSequenceClassification(lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					labels=lowerCamelCase_     )
														self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_labels)     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							str:
														lowerCAmelCase__      =			self.num_labels
														lowerCAmelCase__      =			AlbertForTokenClassification(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														model.eval()
														lowerCAmelCase__      =			model(lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					labels=lowerCamelCase_     )
														self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.seq_length, self.num_labels)     )







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_     ) ->							Optional[int]:
														lowerCAmelCase__      =			self.num_choices
														lowerCAmelCase__      =			AlbertForMultipleChoice(config=lowerCamelCase_     )
														model.to(lowerCamelCase_     )
														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(
														    lowerCamelCase_      ,					attention_mask=lowerCamelCase_      ,					token_type_ids=lowerCamelCase_      ,					labels=lowerCamelCase_      ,					)
														self.parent.assertEqual(result.logits.shape      ,					(self.batch_size, self.num_choices)     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														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 	a__       (							a__       ,       a__       ,       unittest.TestCase						):





							'''simple docstring'''






							lowercase__    :     Dict					=   (
							    (
							        AlbertModel,
							        AlbertForPreTraining,
							        AlbertForMaskedLM,
							        AlbertForMultipleChoice,
							        AlbertForSequenceClassification,
							        AlbertForTokenClassification,
							        AlbertForQuestionAnswering,
							    )
							    if is_torch_available()
							    else ()
							)
							lowercase__    :     str					=   (
							    {
							        "feature-extraction": AlbertModel,
							        "fill-mask": AlbertForMaskedLM,
							        "question-answering": AlbertForQuestionAnswering,
							        "text-classification": AlbertForSequenceClassification,
							        "token-classification": AlbertForTokenClassification,
							        "zero-shot": AlbertForSequenceClassification,
							    }
							    if is_torch_available()
							    else {}
							)
							lowercase__    :     Optional[int]					=   True







							def 						__SCREAMING_SNAKE_CASE							(	self      ,					lowerCamelCase_      ,					lowerCamelCase_      ,					lowerCamelCase_=False     ) ->							int:
														lowerCAmelCase__      =			super()._prepare_for_class(lowerCamelCase_      ,					lowerCamelCase_      ,					return_labels=lowerCamelCase_     )

														if return_labels:
																					if model_class in get_values(lowerCamelCase_     ):
																												lowerCAmelCase__      =			torch.zeros(
																												    (self.model_tester.batch_size, self.model_tester.seq_length)      ,					dtype=torch.long      ,					device=lowerCamelCase_     )
																												lowerCAmelCase__      =			torch.zeros(
																												    self.model_tester.batch_size      ,					dtype=torch.long      ,					device=lowerCamelCase_     )
														return inputs_dict







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[Any]:
														lowerCAmelCase__      =			AlbertModelTester(self     )
														lowerCAmelCase__      =			ConfigTester(self      ,					config_class=lowerCamelCase_      ,					hidden_size=37     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														self.config_tester.run_common_tests()







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[Any]:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_model(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Any:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_pretraining(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_masked_lm(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Union[str, Any]:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_multiple_choice(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Tuple:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_question_answering(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[str]:
														lowerCAmelCase__      =			self.model_tester.prepare_config_and_inputs()
														self.model_tester.create_and_check_for_sequence_classification(*lowerCamelCase_     )







							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Union[str, Any]:
														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(*lowerCamelCase_     )







							@slow
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							Tuple:
														for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
																					lowerCAmelCase__      =			AlbertModel.from_pretrained(lowerCamelCase_     )
																					self.assertIsNotNone(lowerCamelCase_     )




@require_torch
class 	a__       (							unittest.TestCase						):





							'''simple docstring'''






							@slow
							def 						__SCREAMING_SNAKE_CASE							(	self     ) ->							List[Any]:
														lowerCAmelCase__      =			AlbertModel.from_pretrained('''albert-base-v2'''     )
														lowerCAmelCase__      =			torch.tensor([[0, 3_45, 2_32, 3_28, 7_40, 1_40, 16_95, 69, 60_78, 15_88, 2]]     )
														lowerCAmelCase__      =			torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]     )
														with torch.no_grad():
																					lowerCAmelCase__      =			model(lowerCamelCase_      ,					attention_mask=lowerCamelCase_     )[0]
														lowerCAmelCase__      =			torch.Size((1, 11, 7_68)     )
														self.assertEqual(output.shape      ,					lowerCamelCase_     )
														lowerCAmelCase__      =			torch.tensor(
														    [[[-0.6_513, 1.5_035, -0.2_766], [-0.6_515, 1.5_046, -0.2_780], [-0.6_512, 1.5_049, -0.2_784]]]     )

														self.assertTrue(torch.allclose(output[:, 1:4, 1:4]      ,					lowerCamelCase_      ,					atol=1e-4     )     )



'''simple docstring'''






from collections import Counter
from timeit import timeit


def       _snake_case     (  A = ""				,					)		->					bool:
							return sum(c % 2 for c in Counter(input_str.replace(''' '''				,					'''''' ).lower() ).values() ) < 2


def       _snake_case     (  A = "" )		->					bool:
							if len(A ) == 0:
														return True
							lowerCAmelCase__      =			input_str.replace(''' '''				,					'''''' ).lower()
							# character_freq_dict: Stores the frequency of every character in the input string
							lowerCAmelCase__      =			{}

							for character in lower_case_input_str:
														lowerCAmelCase__      =			character_freq_dict.get(A				,					0 ) + 1
							lowerCAmelCase__      =			0

							for character_count in character_freq_dict.values():
														if character_count % 2:
																					odd_char += 1
							if odd_char > 1:
														return False
							return True


def       _snake_case     (  A = "" )		->					None:
							print('''\nFor string = '''				,					A				,					''':''' )
							print(
							    '''> can_string_be_rearranged_as_palindrome_counter()'''				,					'''\tans ='''				,					can_string_be_rearranged_as_palindrome_counter(A )				,					'''\ttime ='''				,					timeit(
							        '''z.can_string_be_rearranged_as_palindrome_counter(z.check_str)'''				,					setup='''import __main__ as z'''				,					)				,					'''seconds'''				,					)
							print(
							    '''> can_string_be_rearranged_as_palindrome()'''				,					'''\tans ='''				,					can_string_be_rearranged_as_palindrome(A )				,					'''\ttime ='''				,					timeit(
							        '''z.can_string_be_rearranged_as_palindrome(z.check_str)'''				,					setup='''import __main__ as z'''				,					)				,					'''seconds'''				,					)


if __name__ == "__main__":
		__UpperCAmelCase					       =							input(
		    '''Enter string to determine if it can be rearranged as a palindrome or not: '''
		).strip()
		benchmark(check_str)
		__UpperCAmelCase					       =							can_string_be_rearranged_as_palindrome_counter(check_str)
		print(f"""{check_str} can {'' if status else 'not '}be rearranged as a palindrome""")