


'''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    lowercase	:

		"""simple docstring"""

		def __init__(		self    ,   UpperCamelCase_    ,   UpperCamelCase_=13    ,   UpperCamelCase_=7    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=True    ,   UpperCamelCase_=99    ,   UpperCamelCase_=16    ,   UpperCamelCase_=36    ,   UpperCamelCase_=6    ,   UpperCamelCase_=6    ,   UpperCamelCase_=6    ,   UpperCamelCase_=37    ,   UpperCamelCase_="gelu"    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=0.1    ,   UpperCamelCase_=512    ,   UpperCamelCase_=16    ,   UpperCamelCase_=2    ,   UpperCamelCase_=0.02    ,   UpperCamelCase_=3    ,   UpperCamelCase_=4    ,   UpperCamelCase_=None    ,   ):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= parent
							UpperCamelCase__   :List[Any]												= batch_size
							UpperCamelCase__   :Any												= seq_length
							UpperCamelCase__   :Optional[int]												= is_training
							UpperCamelCase__   :Union[str, Any]												= use_input_mask
							UpperCamelCase__   :List[str]												= use_token_type_ids
							UpperCamelCase__   :List[Any]												= use_labels
							UpperCamelCase__   :List[Any]												= vocab_size
							UpperCamelCase__   :Dict												= embedding_size
							UpperCamelCase__   :int												= hidden_size
							UpperCamelCase__   :str												= num_hidden_layers
							UpperCamelCase__   :List[Any]												= num_hidden_groups
							UpperCamelCase__   :Any												= num_attention_heads
							UpperCamelCase__   :Optional[int]												= intermediate_size
							UpperCamelCase__   :Tuple												= hidden_act
							UpperCamelCase__   :List[Any]												= hidden_dropout_prob
							UpperCamelCase__   :Optional[int]												= attention_probs_dropout_prob
							UpperCamelCase__   :List[str]												= max_position_embeddings
							UpperCamelCase__   :List[str]												= type_vocab_size
							UpperCamelCase__   :Dict												= type_sequence_label_size
							UpperCamelCase__   :Union[str, Any]												= initializer_range
							UpperCamelCase__   :List[Any]												= num_labels
							UpperCamelCase__   :Union[str, Any]												= num_choices
							UpperCamelCase__   :Tuple												= scope




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :int												= ids_tensor([self.batch_size, self.seq_length]    ,   self.vocab_size							)

							UpperCamelCase__   :Dict												= None
							if self.use_input_mask:
												UpperCamelCase__   :Optional[int]												= random_attention_mask([self.batch_size, self.seq_length]							)

							UpperCamelCase__   :Union[str, Any]												= None
							if self.use_token_type_ids:
												UpperCamelCase__   :str												= ids_tensor([self.batch_size, self.seq_length]    ,   self.type_vocab_size							)

							UpperCamelCase__   :int												= None
							UpperCamelCase__   :str												= None
							UpperCamelCase__   :Optional[Any]												= None
							if self.use_labels:
												UpperCamelCase__   :Optional[int]												= ids_tensor([self.batch_size]    ,   self.type_sequence_label_size							)
												UpperCamelCase__   :List[str]												= ids_tensor([self.batch_size, self.seq_length]    ,   self.num_labels							)
												UpperCamelCase__   :Tuple												= ids_tensor([self.batch_size]    ,   self.num_choices							)

							UpperCamelCase__   :List[str]												= self.get_config()

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




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :str												= AlbertModel(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Dict												= model(UpperCamelCase_    ,   attention_mask=UpperCamelCase_    ,   token_type_ids=UpperCamelCase_							)
							UpperCamelCase__   :Optional[int]												= model(UpperCamelCase_    ,   token_type_ids=UpperCamelCase_							)
							UpperCamelCase__   :int												= model(UpperCamelCase_							)
							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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :List[Any]												= AlbertForPreTraining(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Dict												= model(
							    UpperCamelCase_    ,   attention_mask=UpperCamelCase_    ,   token_type_ids=UpperCamelCase_    ,   labels=UpperCamelCase_    ,   sentence_order_label=UpperCamelCase_    ,   )
							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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :int												= AlbertForMaskedLM(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :List[str]												= 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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :int												= AlbertForQuestionAnswering(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Optional[Any]												= 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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :str												= self.num_labels
							UpperCamelCase__   :Any												= AlbertForSequenceClassification(UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Dict												= model(UpperCamelCase_    ,   attention_mask=UpperCamelCase_    ,   token_type_ids=UpperCamelCase_    ,   labels=UpperCamelCase_							)
							self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_labels)							)




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Any												= self.num_labels
							UpperCamelCase__   :Union[str, Any]												= AlbertForTokenClassification(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Any												= 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     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= self.num_choices
							UpperCamelCase__   :Optional[int]												= AlbertForMultipleChoice(config=UpperCamelCase_							)
							model.to(UpperCamelCase_							)
							model.eval()
							UpperCamelCase__   :Union[str, Any]												= input_ids.unsqueeze(1							).expand(-1    ,   self.num_choices    ,   -1							).contiguous()
							UpperCamelCase__   :Union[str, Any]												= token_type_ids.unsqueeze(1							).expand(-1    ,   self.num_choices    ,   -1							).contiguous()
							UpperCamelCase__   :Tuple												= input_mask.unsqueeze(1							).expand(-1    ,   self.num_choices    ,   -1							).contiguous()
							UpperCamelCase__   :Any												= model(
							    UpperCamelCase_    ,   attention_mask=UpperCamelCase_    ,   token_type_ids=UpperCamelCase_    ,   labels=UpperCamelCase_    ,   )
							self.parent.assertEqual(result.logits.shape    ,   (self.batch_size, self.num_choices)							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= self.prepare_config_and_inputs()
							(
							    (
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				(
							    UpperCamelCase__
							)					,				
							)   :List[Any]												= config_and_inputs
							UpperCamelCase__   :List[Any]												= {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
							return config, inputs_dict



@require_torch
class    lowercase	(							A__	,		A__	,		unittest.TestCase					):

		"""simple docstring"""

		_a     =				(
		    (
		        AlbertModel,
		        AlbertForPreTraining,
		        AlbertForMaskedLM,
		        AlbertForMultipleChoice,
		        AlbertForSequenceClassification,
		        AlbertForTokenClassification,
		        AlbertForQuestionAnswering,
		    )
		    if is_torch_available()
		    else ()
		)
		_a     =				(
		    {
		        'feature-extraction': AlbertModel,
		        'fill-mask': AlbertForMaskedLM,
		        'question-answering': AlbertForQuestionAnswering,
		        'text-classification': AlbertForSequenceClassification,
		        'token-classification': AlbertForTokenClassification,
		        'zero-shot': AlbertForSequenceClassification,
		    }
		    if is_torch_available()
		    else {}
		)
		_a     =				True




		def     lowerCAmelCase__				(		self    ,   UpperCamelCase_    ,   UpperCamelCase_    ,   UpperCamelCase_=False							):

							'''simple docstring'''


							UpperCamelCase__   :Tuple												= super()._prepare_for_class(UpperCamelCase_    ,   UpperCamelCase_    ,   return_labels=UpperCamelCase_							)

							if return_labels:
												if model_class in get_values(UpperCamelCase_							):
																	UpperCamelCase__   :Union[str, Any]												= torch.zeros(
																	    (self.model_tester.batch_size, self.model_tester.seq_length)    ,   dtype=torch.long    ,   device=UpperCamelCase_							)
																	UpperCamelCase__   :str												= torch.zeros(
																	    self.model_tester.batch_size    ,   dtype=torch.long    ,   device=UpperCamelCase_							)
							return inputs_dict




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :int												= AlbertModelTester(self							)
							UpperCamelCase__   :int												= ConfigTester(self    ,   config_class=UpperCamelCase_    ,   hidden_size=37							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							self.config_tester.run_common_tests()




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :int												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_pretraining(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[Any]												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :str												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_multiple_choice(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :List[str]												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_question_answering(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Dict												= self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_sequence_classification(*UpperCamelCase_							)




		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
												UpperCamelCase__   :Any												= type
												self.model_tester.create_and_check_model(*UpperCamelCase_							)




		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							for model_name in ALBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
												UpperCamelCase__   :Optional[int]												= AlbertModel.from_pretrained(UpperCamelCase_							)
												self.assertIsNotNone(UpperCamelCase_							)



@require_torch
class    lowercase	(							unittest.TestCase					):

		"""simple docstring"""

		@slow
		def     lowerCAmelCase__				(		self							):

							'''simple docstring'''


							UpperCamelCase__   :Optional[int]												= AlbertModel.from_pretrained('''albert-base-v2'''							)
							UpperCamelCase__   :int												= torch.tensor([[0, 345, 232, 328, 740, 140, 1695, 69, 6078, 1588, 2]]							)
							UpperCamelCase__   :List[str]												= torch.tensor([[0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]							)
							with torch.no_grad():
												UpperCamelCase__   :Optional[int]												= model(UpperCamelCase_    ,   attention_mask=UpperCamelCase_							)[0]
							UpperCamelCase__   :Any												= torch.Size((1, 11, 768)							)
							self.assertEqual(output.shape    ,   UpperCamelCase_							)
							UpperCamelCase__   :Optional[Any]												= torch.tensor(
							    [[[-0.6513, 1.5035, -0.2766], [-0.6515, 1.5046, -0.2780], [-0.6512, 1.5049, -0.2784]]]							)

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



'''simple docstring'''
import re

from filelock import FileLock


try:
		import nltk

		__snake_case							      =     True
except (ImportError, ModuleNotFoundError):
		__snake_case							      =     False

if NLTK_AVAILABLE:
		with FileLock('''.lock''') as lock:
				nltk.download('''punkt''', quiet=True)


def 			a      (			__a   )  ->	str:



					'''simple docstring'''






					re.sub('''<n>''' ,					'''''' ,					__a   )  # remove pegasus newline char
					assert NLTK_AVAILABLE, "nltk must be installed to separate newlines between sentences. (pip install nltk)"
					return "\n".join(nltk.sent_tokenize(__a   )   )