

import unittest

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

from ...generation.test_utils import GenerationTesterMixin
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 (
			    XLMForMultipleChoice,
			    XLMForQuestionAnswering,
			    XLMForQuestionAnsweringSimple,
			    XLMForSequenceClassification,
			    XLMForTokenClassification,
			    XLMModel,
			    XLMWithLMHeadModel,
			)
			from transformers.models.xlm.modeling_xlm import XLM_PRETRAINED_MODEL_ARCHIVE_LIST






class _UpperCamelCase							:
			'''simple docstring'''







			def __init__(	self							:       Optional[int]					,					a							:       List[Any]					,					a							:       Optional[Any]=13					,					a							:       Optional[int]=7					,					a							:       Tuple=True					,					a							:       Optional[Any]=True					,					a							:       int=True					,					a							:       Dict=True					,					a							:       Union[str, Any]=True					,					a							:       List[str]=False					,					a							:       int=False					,					a							:       List[str]=False					,					a							:       Any=2					,					a							:       Tuple=99					,					a							:       Optional[Any]=0					,					a							:       Optional[Any]=32					,					a							:       Optional[Any]=5					,					a							:       Union[str, Any]=4					,					a							:       Optional[Any]=0.1					,					a							:       Optional[int]=0.1					,					a							:       Dict=512					,					a							:       Any=2					,					a							:       Optional[Any]=0.02					,					a							:       str=2					,					a							:       Dict=4					,					a							:       Optional[int]="last"					,					a							:       str=True					,					a							:       List[Any]=None					,					a							:       Optional[int]=0					,					)							->				Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				parent
				SCREAMING_SNAKE_CASE      :					List[str]    =				batch_size
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				seq_length
				SCREAMING_SNAKE_CASE      :					Any    =				is_training
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				use_input_lengths
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				use_token_type_ids
				SCREAMING_SNAKE_CASE      :					Any    =				use_labels
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				gelu_activation
				SCREAMING_SNAKE_CASE      :					Dict    =				sinusoidal_embeddings
				SCREAMING_SNAKE_CASE      :					List[str]    =				causal
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				asm
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				n_langs
				SCREAMING_SNAKE_CASE      :					str    =				vocab_size
				SCREAMING_SNAKE_CASE      :					List[str]    =				n_special
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				hidden_size
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				num_hidden_layers
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				num_attention_heads
				SCREAMING_SNAKE_CASE      :					Dict    =				hidden_dropout_prob
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				attention_probs_dropout_prob
				SCREAMING_SNAKE_CASE      :					Any    =				max_position_embeddings
				SCREAMING_SNAKE_CASE      :					Dict    =				type_sequence_label_size
				SCREAMING_SNAKE_CASE      :					Any    =				initializer_range
				SCREAMING_SNAKE_CASE      :					int    =				num_labels
				SCREAMING_SNAKE_CASE      :					int    =				num_choices
				SCREAMING_SNAKE_CASE      :					int    =				summary_type
				SCREAMING_SNAKE_CASE      :					Tuple    =				use_proj
				SCREAMING_SNAKE_CASE      :					List[str]    =				scope
				SCREAMING_SNAKE_CASE      :					int    =				bos_token_id
			def 							__UpperCamelCase       (	self							:       str		)							->				int:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				ids_tensor([self.batch_size, self.seq_length]					,					self.vocab_size		)
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				random_attention_mask([self.batch_size, self.seq_length]		)

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

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

				SCREAMING_SNAKE_CASE      :					Dict    =				None
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				None
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				None
				if self.use_labels:
					SCREAMING_SNAKE_CASE      :					List[str]    =				ids_tensor([self.batch_size]					,					self.type_sequence_label_size		)
					SCREAMING_SNAKE_CASE      :					int    =				ids_tensor([self.batch_size, self.seq_length]					,					self.num_labels		)
					SCREAMING_SNAKE_CASE      :					str    =				ids_tensor([self.batch_size]					,					2		).float()
					SCREAMING_SNAKE_CASE      :					int    =				ids_tensor([self.batch_size]					,					self.num_choices		)

				SCREAMING_SNAKE_CASE      :					List[Any]    =				self.get_config()

				return (
				    config,
				    input_ids,
				    token_type_ids,
				    input_lengths,
				    sequence_labels,
				    token_labels,
				    is_impossible_labels,
				    choice_labels,
				    input_mask,
				)
			def 							__UpperCamelCase       (	self							:       Any		)							->				List[str]:

				"""simple docstring"""

				return 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					,					num_labels=self.num_labels					,					bos_token_id=self.bos_token_id					,					)
			def 							__UpperCamelCase       (	self							:       Dict					,					a							:       List[Any]					,					a							:       Tuple					,					a							:       int					,					a							:       Optional[Any]					,					a							:       Union[str, Any]					,					a							:       Tuple					,					a							:       Tuple					,					a							:       Optional[Any]					,					a							:       Union[str, Any]					,					)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				XLMModel(config=a		)
				model.to(a		)
				model.eval()
				SCREAMING_SNAKE_CASE      :					Tuple    =				model(a					,					lengths=a					,					langs=a		)
				SCREAMING_SNAKE_CASE      :					Any    =				model(a					,					langs=a		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				model(a		)
				self.parent.assertEqual(result.last_hidden_state.shape					,					(self.batch_size, self.seq_length, self.hidden_size)		)
			def 							__UpperCamelCase       (	self							:       List[str]					,					a							:       List[Any]					,					a							:       Union[str, Any]					,					a							:       Union[str, Any]					,					a							:       Union[str, Any]					,					a							:       List[Any]					,					a							:       List[str]					,					a							:       Optional[int]					,					a							:       Tuple					,					a							:       Optional[Any]					,					)							->				Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				XLMWithLMHeadModel(a		)
				model.to(a		)
				model.eval()

				SCREAMING_SNAKE_CASE      :					Any    =				model(a					,					token_type_ids=a					,					labels=a		)
				self.parent.assertEqual(result.loss.shape					,					()		)
				self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.vocab_size)		)
			def 							__UpperCamelCase       (	self							:       Union[str, Any]					,					a							:       Tuple					,					a							:       Any					,					a							:       Any					,					a							:       Dict					,					a							:       Optional[int]					,					a							:       Optional[Any]					,					a							:       Dict					,					a							:       Union[str, Any]					,					a							:       Optional[int]					,					)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				XLMForQuestionAnsweringSimple(a		)
				model.to(a		)
				model.eval()

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				model(a		)

				SCREAMING_SNAKE_CASE      :					Optional[int]    =				model(a					,					start_positions=a					,					end_positions=a		)
				SCREAMING_SNAKE_CASE      :					List[Any]    =				outputs
				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							:       List[Any]					,					a							:       Any					,					a							:       Dict					,					a							:       Optional[Any]					,					a							:       Any					,					a							:       Optional[int]					,					a							:       Any					,					a							:       Any					,					a							:       str					,					a							:       Optional[int]					,					)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					int    =				XLMForQuestionAnswering(a		)
				model.to(a		)
				model.eval()

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				model(a		)

				SCREAMING_SNAKE_CASE      :					List[str]    =				model(
				    a					,					start_positions=a					,					end_positions=a					,					cls_index=a					,					is_impossible=a					,					p_mask=a					,					)

				SCREAMING_SNAKE_CASE      :					Dict    =				model(
				    a					,					start_positions=a					,					end_positions=a					,					cls_index=a					,					is_impossible=a					,					)

				((SCREAMING_SNAKE_CASE)   ,)      :					Any    =				result_with_labels.to_tuple()

				SCREAMING_SNAKE_CASE      :					int    =				model(a					,					start_positions=a					,					end_positions=a		)

				((SCREAMING_SNAKE_CASE)   ,)      :					Optional[Any]    =				result_with_labels.to_tuple()

				self.parent.assertEqual(result_with_labels.loss.shape					,					()		)
				self.parent.assertEqual(result.start_top_log_probs.shape					,					(self.batch_size, model.config.start_n_top)		)
				self.parent.assertEqual(result.start_top_index.shape					,					(self.batch_size, model.config.start_n_top)		)
				self.parent.assertEqual(
				    result.end_top_log_probs.shape					,					(self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
				self.parent.assertEqual(
				    result.end_top_index.shape					,					(self.batch_size, model.config.start_n_top * model.config.end_n_top)		)
				self.parent.assertEqual(result.cls_logits.shape					,					(self.batch_size,)		)
			def 							__UpperCamelCase       (	self							:       Union[str, Any]					,					a							:       List[Any]					,					a							:       Dict					,					a							:       List[str]					,					a							:       Any					,					a							:       Union[str, Any]					,					a							:       str					,					a							:       Any					,					a							:       Tuple					,					a							:       int					,					)							->				List[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					str    =				XLMForSequenceClassification(a		)
				model.to(a		)
				model.eval()

				SCREAMING_SNAKE_CASE      :					Any    =				model(a		)
				SCREAMING_SNAKE_CASE      :					Dict    =				model(a					,					labels=a		)
				self.parent.assertEqual(result.loss.shape					,					()		)
				self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.type_sequence_label_size)		)
			def 							__UpperCamelCase       (	self							:       str					,					a							:       Any					,					a							:       List[str]					,					a							:       Optional[Any]					,					a							:       str					,					a							:       Optional[int]					,					a							:       Tuple					,					a							:       int					,					a							:       str					,					a							:       Dict					,					)							->				Dict:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				self.num_labels
				SCREAMING_SNAKE_CASE      :					Dict    =				XLMForTokenClassification(a		)
				model.to(a		)
				model.eval()

				SCREAMING_SNAKE_CASE      :					List[str]    =				model(a					,					attention_mask=a					,					labels=a		)
				self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.seq_length, self.num_labels)		)
			def 							__UpperCamelCase       (	self							:       Any					,					a							:       str					,					a							:       Tuple					,					a							:       List[str]					,					a							:       List[Any]					,					a							:       Optional[Any]					,					a							:       List[str]					,					a							:       Dict					,					a							:       Tuple					,					a							:       Tuple					,					)							->				Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				self.num_choices
				SCREAMING_SNAKE_CASE      :					str    =				XLMForMultipleChoice(config=a		)
				model.to(a		)
				model.eval()
				SCREAMING_SNAKE_CASE      :					Any    =				input_ids.unsqueeze(1		).expand(-1					,					self.num_choices					,					-1		).contiguous()
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				token_type_ids.unsqueeze(1		).expand(-1					,					self.num_choices					,					-1		).contiguous()
				SCREAMING_SNAKE_CASE      :					int    =				input_mask.unsqueeze(1		).expand(-1					,					self.num_choices					,					-1		).contiguous()
				SCREAMING_SNAKE_CASE      :					str    =				model(
				    a					,					attention_mask=a					,					token_type_ids=a					,					labels=a					,					)
				self.parent.assertEqual(result.logits.shape					,					(self.batch_size, self.num_choices)		)






			def 							__UpperCamelCase       (	self							:       Optional[Any]		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				self.prepare_config_and_inputs()
				(
				    (
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,(
				    SCREAMING_SNAKE_CASE
				)   ,
				)      :					int    =				config_and_inputs
				SCREAMING_SNAKE_CASE      :					Optional[int]    =				{"input_ids": input_ids, "token_type_ids": token_type_ids, "lengths": input_lengths}
				return config, inputs_dict






@require_torch
class _UpperCamelCase							(							__A							,		__A							,		__A							,		unittest.TestCase      ):
			'''simple docstring'''







			lowerCamelCase__							=(
			    (
			        XLMModel,
			        XLMWithLMHeadModel,
			        XLMForQuestionAnswering,
			        XLMForSequenceClassification,
			        XLMForQuestionAnsweringSimple,
			        XLMForTokenClassification,
			        XLMForMultipleChoice,
			    )
			    if is_torch_available()
			    else ()
			)
			lowerCamelCase__							=(
			    (XLMWithLMHeadModel,) if is_torch_available() else ()
			)  # TODO (PVP): Check other models whether language generation is also applicable
			lowerCamelCase__							=(
			    {
			        'feature-extraction': XLMModel,
			        'fill-mask': XLMWithLMHeadModel,
			        'question-answering': XLMForQuestionAnsweringSimple,
			        'text-classification': XLMForSequenceClassification,
			        'text-generation': XLMWithLMHeadModel,
			        'token-classification': XLMForTokenClassification,
			        'zero-shot': XLMForSequenceClassification,
			    }
			    if is_torch_available()
			    else {}
			)
			def 							__UpperCamelCase       (	self							:       Any					,					a							:       Tuple					,					a							:       Union[str, Any]					,					a							:       int					,					a							:       Union[str, Any]					,					a							:       Optional[int]		)							->				List[Any]:

				"""simple docstring"""

				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 							__UpperCamelCase       (	self							:       Dict					,					a							:       Optional[int]					,					a							:       Optional[int]					,					a							:       Dict=False		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					int    =				super()._prepare_for_class(a					,					a					,					return_labels=a		)

				if return_labels:
					if model_class.__name__ == "XLMForQuestionAnswering":
						SCREAMING_SNAKE_CASE      :					List[Any]    =				torch.zeros(
						    self.model_tester.batch_size					,					dtype=torch.long					,					device=a		)
						SCREAMING_SNAKE_CASE      :					str    =				torch.zeros(
						    self.model_tester.batch_size					,					dtype=torch.long					,					device=a		)

				return inputs_dict
			def 							__UpperCamelCase       (	self							:       Optional[Any]		)							->				Optional[int]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[Any]    =				XLMModelTester(self		)
				SCREAMING_SNAKE_CASE      :					Tuple    =				ConfigTester(self					,					config_class=a					,					emb_dim=37		)
			def 							__UpperCamelCase       (	self							:       Any		)							->				Optional[int]:

				"""simple docstring"""

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

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Any    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_model(*a		)
			def 							__UpperCamelCase       (	self							:       Dict		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					List[str]    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_lm_head(*a		)
			def 							__UpperCamelCase       (	self							:       Union[str, Any]		)							->				Optional[Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_simple_qa(*a		)
			def 							__UpperCamelCase       (	self							:       Optional[int]		)							->				Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_qa(*a		)
			def 							__UpperCamelCase       (	self							:       Dict		)							->				Union[str, Any]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Dict    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_sequence_classif(*a		)
			def 							__UpperCamelCase       (	self							:       str		)							->				Tuple:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Tuple    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_token_classif(*a		)
			def 							__UpperCamelCase       (	self							:       List[Any]		)							->				Any:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				self.model_tester.prepare_config_and_inputs()
				self.model_tester.create_and_check_xlm_for_multiple_choice(*a		)
			def 							__UpperCamelCase       (	self							:       str					,					a							:       Union[str, Any]					,					a							:       Optional[int]					,					a							:       int					,					a							:       Any					,					a							:       Tuple					,					a							:       str=False					,					a							:       Tuple=1		)							->				str:

				"""simple docstring"""

				self.assertIsInstance(a					,					a		)
				self.assertListEqual(
				    [isinstance(a					,					a		) for iter_attentions in attentions]					,					[True] * len(a		)		)
				self.assertEqual(len(a		)					,					(max_length - min_length) * num_beam_groups		)

				for idx, iter_attentions in enumerate(a		):
					# adds PAD dummy token
					SCREAMING_SNAKE_CASE      :					Tuple    =				min_length + idx + 1
					SCREAMING_SNAKE_CASE      :					Tuple    =				min_length + idx + 1

					SCREAMING_SNAKE_CASE      :					str    =				(
					    batch_size * num_beam_groups,
					    config.num_attention_heads,
					    tgt_len,
					    src_len,
					)
					# check attn size
					self.assertListEqual(
					    [layer_attention.shape for layer_attention in iter_attentions]					,					[expected_shape] * len(a		)		)
			def 							__UpperCamelCase       (	self							:       List[Any]					,					a							:       Dict					,					a							:       Dict					,					a							:       List[Any]					,					a							:       List[str]					,					a							:       Optional[Any]					,					a							:       Union[str, Any]=False					,					a							:       Dict=1		)							->				Dict:

				"""simple docstring"""

				self.assertIsInstance(a					,					a		)
				self.assertListEqual(
				    [isinstance(a					,					a		) for iter_hidden_states in hidden_states]					,					[True] * len(a		)					,					)
				self.assertEqual(len(a		)					,					(max_length - min_length) * num_beam_groups		)

				for idx, iter_hidden_states in enumerate(a		):
					# adds PAD dummy token
					SCREAMING_SNAKE_CASE      :					str    =				min_length + idx + 1
					SCREAMING_SNAKE_CASE      :					Dict    =				(batch_size * num_beam_groups, seq_len, config.hidden_size)
					# check hidden size
					self.assertListEqual(
					    [layer_hidden_states.shape for layer_hidden_states in iter_hidden_states]					,					[expected_shape] * len(a		)					,					)
				pass






			@slow
			def 							__UpperCamelCase       (	self							:       Any		)							->				str:

				"""simple docstring"""

				for model_name in XLM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
					SCREAMING_SNAKE_CASE      :					Dict    =				XLMModel.from_pretrained(a		)
					self.assertIsNotNone(a		)






@require_torch
class _UpperCamelCase							(							unittest.TestCase      ):
			'''simple docstring'''







			@slow
			def 							__UpperCamelCase       (	self							:       int		)							->				List[str]:

				"""simple docstring"""

				SCREAMING_SNAKE_CASE      :					str    =				XLMWithLMHeadModel.from_pretrained("xlm-mlm-en-2048"		)
				model.to(a		)
				SCREAMING_SNAKE_CASE      :					Optional[Any]    =				torch.tensor([[14, 447]]					,					dtype=torch.long					,					device=a		)  # the president
				SCREAMING_SNAKE_CASE      :					Dict    =				[
				    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
				SCREAMING_SNAKE_CASE      :					Union[str, Any]    =				model.generate(a					,					do_sample=a		)
				self.assertListEqual(output_ids[0].cpu().numpy().tolist()					,					a		)
'''simple docstring'''

import requests

__a: str          =   """https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="""
def 			__UpperCamelCase       (   UpperCAmelCase     ):
 # fetching a list of articles in json format
 lowercase__				:    Optional[Any]  =					requests.get(_NEWS_API + bbc_news_api_key     ).json()
 # each article in the list is a dict
 for i, article in enumerate(bbc_news_page['''articles''']		,     1     ):
  print(F"""{i}.) {article['title']}"""     )


if __name__ == "__main__":
  fetch_bbc_news(bbc_news_api_key="""<Your BBC News API key goes here>""")

