




'''simple docstring'''





import unittest

from transformers import EsmConfig, is_torch_available
from transformers.testing_utils import TestCasePlus, 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 EsmForMaskedLM, EsmForSequenceClassification, EsmForTokenClassification, EsmModel
			from transformers.models.esm.modeling_esm import (
			    ESM_PRETRAINED_MODEL_ARCHIVE_LIST,
			    EsmEmbeddings,
			    create_position_ids_from_input_ids,
			)
class 		SCREAMING_SNAKE_CASE			:




				'''simple docstring'''





				def __init__(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__=13  ,						SCREAMING_SNAKE_CASE__=7  ,						SCREAMING_SNAKE_CASE__=False  ,						SCREAMING_SNAKE_CASE__=True  ,						SCREAMING_SNAKE_CASE__=False  ,						SCREAMING_SNAKE_CASE__=True  ,						SCREAMING_SNAKE_CASE__=33  ,						SCREAMING_SNAKE_CASE__=32  ,						SCREAMING_SNAKE_CASE__=5  ,						SCREAMING_SNAKE_CASE__=4  ,						SCREAMING_SNAKE_CASE__=37  ,						SCREAMING_SNAKE_CASE__="gelu"  ,						SCREAMING_SNAKE_CASE__=0.1  ,						SCREAMING_SNAKE_CASE__=0.1  ,						SCREAMING_SNAKE_CASE__=5_12  ,						SCREAMING_SNAKE_CASE__=16  ,						SCREAMING_SNAKE_CASE__=2  ,						SCREAMING_SNAKE_CASE__=0.02  ,						SCREAMING_SNAKE_CASE__=3  ,						SCREAMING_SNAKE_CASE__=4  ,						SCREAMING_SNAKE_CASE__=None  ,						):
							'''simple docstring'''







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







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Union[str, Any]        =       ids_tensor([self.batch_size, self.seq_length]  ,						self.vocab_size				)

							snake_case:       Tuple        =       None
							if self.use_input_mask:
										snake_case:       Tuple        =       random_attention_mask([self.batch_size, self.seq_length]				)

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

							snake_case:       str        =       self.get_config()

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







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							return EsmConfig(
							    vocab_size=self.vocab_size  ,						hidden_size=self.hidden_size  ,						pad_token_id=1  ,						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  ,						)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[Any]        =       EsmModel(config=lowercase_				)
							model.to(lowercase_				)
							model.eval()
							snake_case:       List[str]        =       model(lowercase_  ,						attention_mask=lowercase_				)
							snake_case:       Optional[Any]        =       model(lowercase_				)
							snake_case:       str        =       model(lowercase_				)

							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        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[Any]        =       EsmForMaskedLM(config=lowercase_				)
							model.to(lowercase_				)
							model.eval()
							snake_case:       Optional[int]        =       model(lowercase_  ,						attention_mask=lowercase_  ,						labels=lowercase_				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.vocab_size)				)







				def        _UpperCamelCase							(   self  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__  ,						SCREAMING_SNAKE_CASE__				):
							'''simple docstring'''







							snake_case:       Optional[int]        =       self.num_labels
							snake_case:       str        =       EsmForTokenClassification(config=lowercase_				)
							model.to(lowercase_				)
							model.eval()
							snake_case:       Union[str, Any]        =       model(lowercase_  ,						attention_mask=lowercase_  ,						labels=lowercase_				)
							self.parent.assertEqual(result.logits.shape  ,						(self.batch_size, self.seq_length, self.num_labels)				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       str        =       self.prepare_config_and_inputs()
							(
							    (
							    snake_case	
							)    ,						(
							    snake_case	
							)    ,						(
							    snake_case	
							)    ,						(
							    snake_case	
							)    ,						(
							    snake_case	
							)    ,						(
							    snake_case	
							)    ,							
							):       int        =       config_and_inputs
							snake_case:       List[Any]        =       {'input_ids': input_ids, 'attention_mask': input_mask}
							return config, inputs_dict






@require_torch
class 		SCREAMING_SNAKE_CASE			(     __a    ,      __a    ,      unittest.TestCase							):




				'''simple docstring'''





				__UpperCamelCase     				=   False

				__UpperCamelCase     				=   (
				    (
				        EsmForMaskedLM,
				        EsmModel,
				        EsmForSequenceClassification,
				        EsmForTokenClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				__UpperCamelCase     				=   ()
				__UpperCamelCase     				=   (
				    {
				        "feature-extraction": EsmModel,
				        "fill-mask": EsmForMaskedLM,
				        "text-classification": EsmForSequenceClassification,
				        "token-classification": EsmForTokenClassification,
				        "zero-shot": EsmForSequenceClassification,
				    }
				    if is_torch_available()
				    else {}
				)
				__UpperCamelCase     				=   True







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Optional[Any]        =       EsmModelTester(self				)
							snake_case:       List[Any]        =       ConfigTester(self  ,						config_class=lowercase_  ,						hidden_size=37				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							self.config_tester.run_common_tests()







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Optional[int]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*lowercase_				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Tuple        =       self.model_tester.prepare_config_and_inputs()
							for type in ["absolute", "relative_key", "relative_key_query"]:
										snake_case:       Any        =       type
										self.model_tester.create_and_check_model(*lowercase_				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Optional[Any]        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_masked_lm(*lowercase_				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Dict        =       self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_for_token_classification(*lowercase_				)







				@slow
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							for model_name in ESM_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										snake_case:       List[str]        =       EsmModel.from_pretrained(lowercase_				)
										self.assertIsNotNone(lowercase_				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       List[Any]        =       self.model_tester.prepare_config_and_inputs()[0]
							snake_case:       Dict        =       EsmEmbeddings(config=lowercase_				)

							snake_case:       Tuple        =       torch.as_tensor([[12, 31, 13, model.padding_idx]]				)
							snake_case:       int        =       torch.as_tensor(
							    [
							        [
							            0 + model.padding_idx + 1,
							            1 + model.padding_idx + 1,
							            2 + model.padding_idx + 1,
							            model.padding_idx,
							        ]
							    ]				)
							snake_case:       List[str]        =       create_position_ids_from_input_ids(lowercase_  ,						model.padding_idx				)
							self.assertEqual(position_ids.shape  ,						expected_positions.shape				)
							self.assertTrue(torch.all(torch.eq(lowercase_  ,						lowercase_				)				)				)







				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							snake_case:       Dict        =       self.model_tester.prepare_config_and_inputs()[0]
							snake_case:       Dict        =       EsmEmbeddings(config=lowercase_				)

							snake_case:       Any        =       torch.empty(2  ,						4  ,						30				)
							snake_case:       str        =       [
							    0 + embeddings.padding_idx + 1,
							    1 + embeddings.padding_idx + 1,
							    2 + embeddings.padding_idx + 1,
							    3 + embeddings.padding_idx + 1,
							]
							snake_case:       Any        =       torch.as_tensor([expected_single_positions, expected_single_positions]				)
							snake_case:       Any        =       embeddings.create_position_ids_from_inputs_embeds(lowercase_				)
							self.assertEqual(position_ids.shape  ,						expected_positions.shape				)
							self.assertTrue(torch.all(torch.eq(lowercase_  ,						lowercase_				)				)				)







				@unittest.skip('Esm does not support embedding resizing'				)
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							pass







				@unittest.skip('Esm does not support embedding resizing'				)
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							pass







				@unittest.skip('Will be fixed soon by reducing the size of the model used for common tests.'				)
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							pass






@require_torch
class 		SCREAMING_SNAKE_CASE			(     __a							):




				'''simple docstring'''





				@slow
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							with torch.no_grad():
										snake_case:       List[Any]        =       EsmForMaskedLM.from_pretrained('facebook/esm2_t6_8M_UR50D'				)
										model.eval()
										snake_case:       int        =       torch.tensor([[0, 1, 2, 3, 4, 5]]				)
										snake_case:       Any        =       model(lowercase_				)[0]

										snake_case:       Optional[int]        =       33

										snake_case:       str        =       torch.Size((1, 6, vocab_size)				)
										self.assertEqual(output.shape  ,						lowercase_				)

										snake_case:       Any        =       torch.tensor(
										    [[[8.92_15, -10.58_98, -6.46_71], [-6.39_67, -13.91_14, -1.12_12], [-7.78_12, -13.95_16, -3.74_06]]]				)
										self.assertTrue(torch.allclose(output[:, :3, :3]  ,						lowercase_  ,						atol=1E-4				)				)







				@slow
				def        _UpperCamelCase							(   self				):
							'''simple docstring'''







							with torch.no_grad():
										snake_case:       Any        =       EsmModel.from_pretrained('facebook/esm2_t6_8M_UR50D'				)
										model.eval()

										snake_case:       List[str]        =       torch.tensor([[0, 6, 4, 13, 5, 4, 16, 12, 11, 7, 2]]				)
										snake_case:       List[Any]        =       model(lowercase_				)[0]
										# compare the actual values for a slice.
										snake_case:       int        =       torch.tensor(
										    [[[0.14_44, 0.54_13, 0.32_48], [0.30_34, 0.00_53, 0.31_08], [0.32_28, -0.24_99, 0.34_15]]]				)
										self.assertTrue(torch.allclose(output[:, :3, :3]  ,						lowercase_  ,						atol=1E-4				)				)
'''simple docstring'''


import requests

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

def   A_      (       SCREAMING_SNAKE_CASE_						)			->None:
  # fetching a list of articles in json format
  lowercase_     =       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>""")

