



import unittest

from transformers import BigBirdConfig, is_flax_available
from transformers.testing_utils import require_flax, slow

from ...test_modeling_flax_common import FlaxModelTesterMixin, ids_tensor, random_attention_mask


if is_flax_available():
			import jax

			from transformers.models.big_bird.modeling_flax_big_bird import (
			    FlaxBigBirdForCausalLM,
			    FlaxBigBirdForMaskedLM,
			    FlaxBigBirdForMultipleChoice,
			    FlaxBigBirdForPreTraining,
			    FlaxBigBirdForQuestionAnswering,
			    FlaxBigBirdForSequenceClassification,
			    FlaxBigBirdForTokenClassification,
			    FlaxBigBirdModel,
			)


class 						lowercase    (							unittest.TestCase):
						'''simple docstring'''


						def __init__(  self    :				Any       ,	snake_case    :				str       ,	snake_case    :				Optional[int]=2       ,	snake_case    :				Optional[int]=56       ,	snake_case    :				List[Any]=True       ,	snake_case    :				Tuple=True       ,	snake_case    :				str=True       ,	snake_case    :				Tuple=True       ,	snake_case    :				str=99       ,	snake_case    :				List[Any]=32       ,	snake_case    :				Optional[int]=2       ,	snake_case    :				Optional[Any]=2       ,	snake_case    :				Optional[Any]=7       ,	snake_case    :				List[Any]="gelu_new"       ,	snake_case    :				List[Any]=0.1       ,	snake_case    :				Optional[Any]=0.1       ,	snake_case    :				Dict=512       ,	snake_case    :				Optional[Any]=16       ,	snake_case    :				Union[str, Any]=2       ,	snake_case    :				Union[str, Any]=0.02       ,	snake_case    :				Optional[int]=4       ,	snake_case    :				Optional[Any]="block_sparse"       ,	snake_case    :				Any=True       ,	snake_case    :				Any=False       ,	snake_case    :				int=2       ,	snake_case    :				Union[str, Any]=3       ,	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     List[Any]						=				parent
											SCREAMING_SNAKE_CASE							:     Dict						=				batch_size
											SCREAMING_SNAKE_CASE							:     List[str]						=				seq_length
											SCREAMING_SNAKE_CASE							:     List[str]						=				is_training
											SCREAMING_SNAKE_CASE							:     Optional[int]						=				use_attention_mask
											SCREAMING_SNAKE_CASE							:     str						=				use_token_type_ids
											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				use_labels
											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				vocab_size
											SCREAMING_SNAKE_CASE							:     Any						=				hidden_size
											SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				num_hidden_layers
											SCREAMING_SNAKE_CASE							:     Any						=				num_attention_heads
											SCREAMING_SNAKE_CASE							:     List[str]						=				intermediate_size
											SCREAMING_SNAKE_CASE							:     Dict						=				hidden_act
											SCREAMING_SNAKE_CASE							:     Any						=				hidden_dropout_prob
											SCREAMING_SNAKE_CASE							:     Any						=				attention_probs_dropout_prob
											SCREAMING_SNAKE_CASE							:     Optional[Any]						=				max_position_embeddings
											SCREAMING_SNAKE_CASE							:     List[str]						=				type_vocab_size
											SCREAMING_SNAKE_CASE							:     str						=				type_sequence_label_size
											SCREAMING_SNAKE_CASE							:     List[Any]						=				initializer_range
											SCREAMING_SNAKE_CASE							:     List[str]						=				num_choices

											SCREAMING_SNAKE_CASE							:     int						=				rescale_embeddings
											SCREAMING_SNAKE_CASE							:     Dict						=				attention_type
											SCREAMING_SNAKE_CASE							:     Any						=				use_bias
											SCREAMING_SNAKE_CASE							:     List[Any]						=				block_size
											SCREAMING_SNAKE_CASE							:     Tuple						=				num_random_blocks







						def       lowerCamelCase_				(  self    :				str	):



											'''simple docstring'''


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

											SCREAMING_SNAKE_CASE							:     int						=				None
											if self.use_attention_mask:
																SCREAMING_SNAKE_CASE							:     int						=				random_attention_mask([self.batch_size, self.seq_length]	)

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

											SCREAMING_SNAKE_CASE							:     Optional[int]						=				BigBirdConfig(
											    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=snake_case       ,	initializer_range=self.initializer_range       ,	attention_type=self.attention_type       ,	block_size=self.block_size       ,	num_random_blocks=self.num_random_blocks       ,	use_bias=self.use_bias       ,	rescale_embeddings=self.rescale_embeddings       ,	)

											return config, input_ids, token_type_ids, attention_mask







						def       lowerCamelCase_				(  self    :				Optional[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				self.prepare_config_and_inputs()
											SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Any						=				config_and_inputs
											SCREAMING_SNAKE_CASE							:     Tuple						=				{
											    'input_ids': input_ids,
											    'token_type_ids': token_type_ids,
											    'attention_mask': attention_mask,
											}
											return config, inputs_dict


@require_flax
class 						lowercase    (							SCREAMING_SNAKE_CASE_      ,    unittest.TestCase):
						'''simple docstring'''


						UpperCAmelCase			:		Union[str, Any]		=		(
						    (
						        FlaxBigBirdForCausalLM,
						        FlaxBigBirdModel,
						        FlaxBigBirdForPreTraining,
						        FlaxBigBirdForMaskedLM,
						        FlaxBigBirdForMultipleChoice,
						        FlaxBigBirdForQuestionAnswering,
						        FlaxBigBirdForSequenceClassification,
						        FlaxBigBirdForTokenClassification,
						    )
						    if is_flax_available()
						    else ()
						)

						UpperCAmelCase			:		Union[str, Any]		=		False
						UpperCAmelCase			:		Optional[Any]		=		False







						def       lowerCamelCase_				(  self    :				List[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE							:     Dict						=				FlaxBigBirdModelTester(self	)







						@slow
						# copied from `test_modeling_flax_common` because it takes much longer than other models
						def       lowerCamelCase_				(  self    :				Tuple	):



											'''simple docstring'''


											super().test_from_pretrained_save_pretrained()







						@slow
						# copied from `test_modeling_flax_common` because it takes much longer than other models
						def       lowerCamelCase_				(  self    :				Union[str, Any]	):



											'''simple docstring'''


											super().test_from_pretrained_with_no_automatic_init()







						@slow
						# copied from `test_modeling_flax_common` because it takes much longer than other models
						def       lowerCamelCase_				(  self    :				List[str]	):



											'''simple docstring'''


											super().test_no_automatic_init()







						@slow
						# copied from `test_modeling_flax_common` because it takes much longer than other models
						def       lowerCamelCase_				(  self    :				Any	):



											'''simple docstring'''


											super().test_hidden_states_output()







						@slow
						def       lowerCamelCase_				(  self    :				List[Any]	):



											'''simple docstring'''


											for model_class_name in self.all_model_classes:
																SCREAMING_SNAKE_CASE							:     str						=				model_class_name.from_pretrained('google/bigbird-roberta-base'	)
																self.assertIsNotNone(snake_case	)







						def       lowerCamelCase_				(  self    :				Optional[int]	):



											'''simple docstring'''


											if self.test_attn_probs:
																super().test_attention_outputs()







						@slow
						# copied from `test_modeling_flax_common` because it takes much longer than other models
						def       lowerCamelCase_				(  self    :				Optional[Any]	):



											'''simple docstring'''


											SCREAMING_SNAKE_CASE					,  SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				self.model_tester.prepare_config_and_inputs_for_common()

											for model_class in self.all_model_classes:
																with self.subTest(model_class.__name__	):
																					SCREAMING_SNAKE_CASE							:     Union[str, Any]						=				self._prepare_for_class(snake_case       ,	snake_case	)
																					SCREAMING_SNAKE_CASE							:     Optional[Any]						=				model_class(snake_case	)

																					@jax.jit
																					def model_jitted(snake_case    :				Tuple       ,	snake_case    :				int=None       ,	**snake_case    :				Dict	):
																										return model(input_ids=snake_case       ,	attention_mask=snake_case       ,	**snake_case	)

																					with self.subTest('JIT Enabled'	):
																										SCREAMING_SNAKE_CASE							:     int						=				model_jitted(**snake_case	).to_tuple()

																					with self.subTest('JIT Disabled'	):
																										with jax.disable_jit():
																															SCREAMING_SNAKE_CASE							:     int						=				model_jitted(**snake_case	).to_tuple()

																					self.assertEqual(len(snake_case	)       ,	len(snake_case	)	)
																					for jitted_output, output in zip(snake_case       ,	snake_case	):
																										self.assertEqual(jitted_output.shape       ,	output.shape	)







						def       lowerCamelCase_				(  self    :				List[Any]       ,	snake_case    :				Any       ,	snake_case    :				Optional[Any]       ,	snake_case    :				Any       ,	snake_case    :				int=1E-5       ,	snake_case    :				Any="outputs"       ,	snake_case    :				List[str]=None	):



											'''simple docstring'''


											if name.startswith('outputs.attentions'	):
																return
											else:
																super().check_pt_flax_outputs(snake_case       ,	snake_case       ,	snake_case       ,	snake_case       ,	snake_case       ,	snake_case	)




import requests

_lowerCamelCase    :		int		      =    """https://newsapi.org/v1/articles?source=bbc-news&sortBy=top&apiKey="""

def        __a			(   __lowerCAmelCase   )     ->     None:
					# fetching a list of articles in json format
					SCREAMING_SNAKE_CASE							:     List[str]						=				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>""")