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






		def __init__(	self	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							str							,    )  ->							Optional[int]:
						__lowerCamelCase					      =			parent
						__lowerCamelCase					      =			13
						__lowerCamelCase					      =			7
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			False
						__lowerCamelCase					      =			False
						__lowerCamelCase					      =			False
						__lowerCamelCase					      =			2
						__lowerCamelCase					      =			99
						__lowerCamelCase					      =			0
						__lowerCamelCase					      =			32
						__lowerCamelCase					      =			2
						__lowerCamelCase					      =			4
						__lowerCamelCase					      =			0.1
						__lowerCamelCase					      =			0.1
						__lowerCamelCase					      =			5_12
						__lowerCamelCase					      =			16
						__lowerCamelCase					      =			2
						__lowerCamelCase					      =			0.02
						__lowerCamelCase					      =			3
						__lowerCamelCase					      =			4
						__lowerCamelCase					      =			'''last'''
						__lowerCamelCase					      =			True
						__lowerCamelCase					      =			None
						__lowerCamelCase					      =			0






		def 				__A (	self	:							Tuple						)  ->							Tuple:
						__lowerCamelCase					      =			ids_tensor([self.batch_size, self.seq_length]							,    self.vocab_size						)
						__lowerCamelCase					      =			random_attention_mask([self.batch_size, self.seq_length]							,    dtype=tf.floataa						)

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

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

						__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]							,    2							,    dtype=tf.floataa						)
										__lowerCamelCase					      =			ids_tensor([self.batch_size]							,    self.num_choices						)

						__lowerCamelCase					      =			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 				__A (	self	:							Dict							,    SCREAMING_SNAKE_CASE__	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							Tuple							,    SCREAMING_SNAKE_CASE__	:							Dict							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Any							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							List[Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    )  ->							Dict:
						__lowerCamelCase					      =			TFXLMModel(config=SCREAMING_SNAKE_CASE__						)
						__lowerCamelCase					      =			{'''input_ids''': input_ids, '''lengths''': input_lengths, '''langs''': token_type_ids}
						__lowerCamelCase					      =			model(SCREAMING_SNAKE_CASE__						)

						__lowerCamelCase					      =			[input_ids, input_mask]
						__lowerCamelCase					      =			model(SCREAMING_SNAKE_CASE__						)
						self.parent.assertEqual(result.last_hidden_state.shape							,    (self.batch_size, self.seq_length, self.hidden_size)						)






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

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

						__lowerCamelCase					      =			outputs

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






		def 				__A (	self	:							Tuple							,    SCREAMING_SNAKE_CASE__	:							Tuple							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							int							,    SCREAMING_SNAKE_CASE__	:							Union[str, Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Any							,    SCREAMING_SNAKE_CASE__	:							Any							,    SCREAMING_SNAKE_CASE__	:							Any							,    )  ->							Dict:
						__lowerCamelCase					      =			TFXLMForQuestionAnsweringSimple(SCREAMING_SNAKE_CASE__						)

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

						__lowerCamelCase					      =			model(SCREAMING_SNAKE_CASE__						)

						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 				__A (	self	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							Dict							,    SCREAMING_SNAKE_CASE__	:							str							,    SCREAMING_SNAKE_CASE__	:							Any							,    SCREAMING_SNAKE_CASE__	:							Tuple							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    SCREAMING_SNAKE_CASE__	:							Any							,    SCREAMING_SNAKE_CASE__	:							Optional[int]							,    )  ->							Optional[int]:
						__lowerCamelCase					      =			TFXLMForSequenceClassification(SCREAMING_SNAKE_CASE__						)

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

						__lowerCamelCase					      =			model(SCREAMING_SNAKE_CASE__						)

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






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






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







		def 				__A (	self	:							Optional[int]						)  ->							Union[str, Any]:
						__lowerCamelCase					      =			self.prepare_config_and_inputs()
						(
						    __lowerCamelCase	
						)					      =			config_and_inputs
						__lowerCamelCase					      =			{
						    '''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__  (			A_						,			A_						,			unittest.TestCase    ):
		a__ :		Union[str, Any]   						=	(
		    (
		        TFXLMModel,
		        TFXLMWithLMHeadModel,
		        TFXLMForSequenceClassification,
		        TFXLMForQuestionAnsweringSimple,
		        TFXLMForTokenClassification,
		        TFXLMForMultipleChoice,
		    )
		    if is_tf_available()
		    else ()
		)
		a__ :		Optional[Any]   						=	(
		    (TFXLMWithLMHeadModel,) if is_tf_available() else ()
		)  # TODO (PVP): Check other models whether language generation is also applicable
		a__ :		Any   						=	(
		    {
		        """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__ :		Optional[int]   						=	False
		a__ :		str   						=	False






		def 				__A (	self	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							List[Any]							,    SCREAMING_SNAKE_CASE__	:							Tuple							,    SCREAMING_SNAKE_CASE__	:							Optional[Any]							,    SCREAMING_SNAKE_CASE__	:							List[Any]							,    SCREAMING_SNAKE_CASE__	:							Optional[int]						)  ->							Optional[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 				__A (	self	:							List[str]						)  ->							Union[str, Any]:
						__lowerCamelCase					      =			TFXLMModelTester(self						)
						__lowerCamelCase					      =			ConfigTester(self							,    config_class=SCREAMING_SNAKE_CASE__							,    emb_dim=37						)






		def 				__A (	self	:							int						)  ->							Any:
						self.config_tester.run_common_tests()






		def 				__A (	self	:							Dict						)  ->							Union[str, Any]:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_model(*SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							Dict						)  ->							Dict:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_lm_head(*SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							Optional[int]						)  ->							Dict:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_qa(*SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							int						)  ->							int:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_sequence_classif(*SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							List[str]						)  ->							Tuple:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_for_token_classification(*SCREAMING_SNAKE_CASE__						)






		def 				__A (	self	:							Tuple						)  ->							Any:
						__lowerCamelCase					      =			self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_xlm_for_multiple_choice(*SCREAMING_SNAKE_CASE__						)







		@slow
		def 				__A (	self	:							str						)  ->							Optional[int]:



						for model_name in TF_XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										__lowerCamelCase					      =			TFXLMModel.from_pretrained(SCREAMING_SNAKE_CASE__						)
										self.assertIsNotNone(SCREAMING_SNAKE_CASE__						)





@require_tf
class      lowerCAmelCase__  (			unittest.TestCase    ):






		@slow
		def 				__A (	self	:							List[Any]						)  ->							Tuple:
						__lowerCamelCase					      =			TFXLMWithLMHeadModel.from_pretrained('''xlm-mlm-en-2048'''						)
						__lowerCamelCase					      =			tf.convert_to_tensor([[14, 4_47]]							,    dtype=tf.intaa						)  # the president
						__lowerCamelCase					      =			[
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						    14,
						    4_47,
						]  # 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					      =			model.generate(SCREAMING_SNAKE_CASE__							,    do_sample=SCREAMING_SNAKE_CASE__						)
						self.assertListEqual(output_ids[0].numpy().tolist()							,    SCREAMING_SNAKE_CASE__						)





import bsa
import requests




def 				__magic_name__				(     __lowerCAmelCase			:		bsa.element.ResultSet							)    ->     dict[str, str]:
				return {
				    "name": soup.ha.a.text,
				    "genre": soup.find('''span'''	,						class_='''genre'''							).text.strip(),
				    "rating": soup.strong.text,
				    "page_link": f'''https://www.imdb.com{soup.a.get('href'							)}''',
				}




def 				__magic_name__				(     __lowerCAmelCase			:		int = 5							)    ->     tuple:
				__lowerCamelCase					      =			int(float(__lowerCAmelCase							)							)
				if num_movies < 1:
								return ()
				__lowerCamelCase					      =			(
				    '''https://www.imdb.com/search/title?title_type='''
				    f'''feature&sort=num_votes,desc&count={num_movies}'''
				)
				__lowerCamelCase					      =			bsa.BeautifulSoup(requests.get(__lowerCAmelCase							).content	,						'''html.parser'''							)
				return tuple(
				    get_movie_data_from_soup(__lowerCAmelCase							)
				    for movie in source.find_all('''div'''	,						class_='''lister-item mode-advanced'''							)							)


if __name__ == "__main__":
					import json

					SCREAMING_SNAKE_CASE__     :    str      							=					int(input("How many movies would you like to see? "))
					print(
					    ", ".join(
					        json.dumps(movie, indent=4) for movie in get_imdb_top_movies(num_movies)
					    )
					)



