





import unittest

from transformers import AutoTokenizer, NystromformerConfig, is_torch_available
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 (
      NystromformerForMaskedLM,
      NystromformerForMultipleChoice,
      NystromformerForQuestionAnswering,
      NystromformerForSequenceClassification,
      NystromformerForTokenClassification,
      NystromformerModel,
  )
  from transformers.models.nystromformer.modeling_nystromformer import NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST


class        UpperCamelCase_					:

    '''simple docstring'''






    def __init__(    self   :			Union[str, Any]      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			Any=13      ,				UpperCAmelCase__   :			str=7      ,				UpperCAmelCase__   :			Optional[Any]=True      ,				UpperCAmelCase__   :			Tuple=True      ,				UpperCAmelCase__   :			Dict=True      ,				UpperCAmelCase__   :			int=True      ,				UpperCAmelCase__   :			Optional[int]=99      ,				UpperCAmelCase__   :			int=32      ,				UpperCAmelCase__   :			List[str]=5      ,				UpperCAmelCase__   :			int=4      ,				UpperCAmelCase__   :			Tuple=37      ,				UpperCAmelCase__   :			Dict="gelu"      ,				UpperCAmelCase__   :			Tuple=0.1      ,				UpperCAmelCase__   :			List[Any]=0.1      ,				UpperCAmelCase__   :			str=512      ,				UpperCAmelCase__   :			Optional[int]=16      ,				UpperCAmelCase__   :			Any=2      ,				UpperCAmelCase__   :			Any=0.02      ,				UpperCAmelCase__   :			Dict=3      ,				UpperCAmelCase__   :			Optional[Any]=4      ,				UpperCAmelCase__   :			Dict=None      ,				)		->Tuple:





           '''simple docstring'''

           A__   				=					parent
           A__   				=					batch_size
           A__   				=					seq_length
           A__   				=					is_training
           A__   				=					use_input_mask
           A__   				=					use_token_type_ids
           A__   				=					use_labels
           A__   				=					vocab_size
           A__   				=					hidden_size
           A__   				=					num_hidden_layers
           A__   				=					num_attention_heads
           A__   				=					intermediate_size
           A__   				=					hidden_act
           A__   				=					hidden_dropout_prob
           A__   				=					attention_probs_dropout_prob
           A__   				=					max_position_embeddings
           A__   				=					type_vocab_size
           A__   				=					type_sequence_label_size
           A__   				=					initializer_range
           A__   				=					num_labels
           A__   				=					num_choices
           A__   				=					scope


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->List[str]:





           '''simple docstring'''

           A__   				=					ids_tensor([self.batch_size, self.seq_length]      ,				self.vocab_size)

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

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

           A__   				=					None
           A__   				=					None
           A__   				=					None
           if self.use_labels:
                  A__   				=					ids_tensor([self.batch_size]      ,				self.type_sequence_label_size)
                  A__   				=					ids_tensor([self.batch_size, self.seq_length]      ,				self.num_labels)
                  A__   				=					ids_tensor([self.batch_size]      ,				self.num_choices)

           A__   				=					self.get_config()

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


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





           '''simple docstring'''

           return NystromformerConfig(
               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=a_      ,				initializer_range=self.initializer_range      ,				)


    def  SCREAMING_SNAKE_CASE							(    self   :			Tuple      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Tuple)		->Optional[int]:





           '''simple docstring'''

           A__   				=					NystromformerModel(config=a_)
           model.to(a_)
           model.eval()
           A__   				=					model(a_      ,				attention_mask=a_      ,				token_type_ids=a_)
           A__   				=					model(a_      ,				token_type_ids=a_)
           A__   				=					model(a_)
           self.parent.assertEqual(result.last_hidden_state.shape      ,				(self.batch_size, self.seq_length, self.hidden_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Any      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			str)		->List[Any]:





           '''simple docstring'''

           A__   				=					NystromformerForMaskedLM(config=a_)
           model.to(a_)
           model.eval()
           A__   				=					model(a_      ,				attention_mask=a_      ,				token_type_ids=a_      ,				labels=a_)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.vocab_size))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Union[str, Any]      ,				UpperCAmelCase__   :			List[str]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Tuple)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					NystromformerForQuestionAnswering(config=a_)
           model.to(a_)
           model.eval()
           A__   				=					model(
               a_      ,				attention_mask=a_      ,				token_type_ids=a_      ,				start_positions=a_      ,				end_positions=a_      ,				)
           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  SCREAMING_SNAKE_CASE							(    self   :			Union[str, Any]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any)		->Optional[Any]:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					NystromformerForSequenceClassification(a_)
           model.to(a_)
           model.eval()
           A__   				=					model(a_      ,				attention_mask=a_      ,				token_type_ids=a_      ,				labels=a_)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			Dict      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			List[Any]      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Union[str, Any])		->Optional[Any]:





           '''simple docstring'''

           A__   				=					self.num_labels
           A__   				=					NystromformerForTokenClassification(config=a_)
           model.to(a_)
           model.eval()
           A__   				=					model(a_      ,				attention_mask=a_      ,				token_type_ids=a_      ,				labels=a_)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.seq_length, self.num_labels))


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any]      ,				UpperCAmelCase__   :			Tuple      ,				UpperCAmelCase__   :			str      ,				UpperCAmelCase__   :			Optional[int]      ,				UpperCAmelCase__   :			Any      ,				UpperCAmelCase__   :			Optional[Any]      ,				UpperCAmelCase__   :			int      ,				UpperCAmelCase__   :			Dict)		->Dict:





           '''simple docstring'''

           A__   				=					self.num_choices
           A__   				=					NystromformerForMultipleChoice(config=a_)
           model.to(a_)
           model.eval()
           A__   				=					input_ids.unsqueeze(1).expand(-1      ,				self.num_choices      ,				-1).contiguous()
           A__   				=					token_type_ids.unsqueeze(1).expand(-1      ,				self.num_choices      ,				-1).contiguous()
           A__   				=					input_mask.unsqueeze(1).expand(-1      ,				self.num_choices      ,				-1).contiguous()
           A__   				=					model(
               a_      ,				attention_mask=a_      ,				token_type_ids=a_      ,				labels=a_      ,				)
           self.parent.assertEqual(result.logits.shape      ,				(self.batch_size, self.num_choices))





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





           '''simple docstring'''

           A__   				=					self.prepare_config_and_inputs()
           (
               A__      
           )   				=					config_and_inputs
           A__   				=					{"""input_ids""": input_ids, """token_type_ids""": token_type_ids, """attention_mask""": input_mask}
           return config, inputs_dict


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

    '''simple docstring'''






    UpperCAmelCase__													=   (
        (
            NystromformerModel,
            NystromformerForMaskedLM,
            NystromformerForMultipleChoice,
            NystromformerForQuestionAnswering,
            NystromformerForSequenceClassification,
            NystromformerForTokenClassification,
        )
        if is_torch_available()
        else ()
    )
    UpperCAmelCase__													=   (
        {
            '''feature-extraction''': NystromformerModel,
            '''fill-mask''': NystromformerForMaskedLM,
            '''question-answering''': NystromformerForQuestionAnswering,
            '''text-classification''': NystromformerForSequenceClassification,
            '''token-classification''': NystromformerForTokenClassification,
            '''zero-shot''': NystromformerForSequenceClassification,
        }
        if is_torch_available()
        else {}
    )
    UpperCAmelCase__													=   False
    UpperCAmelCase__													=   False


    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Dict:





           '''simple docstring'''

           A__   				=					NystromformerModelTester(self)
           A__   				=					ConfigTester(self      ,				config_class=a_      ,				hidden_size=37)


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





           '''simple docstring'''

           self.config_tester.run_common_tests()


    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->List[str]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_model(*a_)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           for type in ["absolute", "relative_key", "relative_key_query"]:
                  A__   				=					type
                  self.model_tester.create_and_check_model(*a_)


    def  SCREAMING_SNAKE_CASE							(    self   :			Optional[Any])		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_masked_lm(*a_)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_multiple_choice(*a_)


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





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_question_answering(*a_)


    def  SCREAMING_SNAKE_CASE							(    self   :			Dict)		->Dict:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_sequence_classification(*a_)


    def  SCREAMING_SNAKE_CASE							(    self   :			str)		->Union[str, Any]:





           '''simple docstring'''

           A__   				=					self.model_tester.prepare_config_and_inputs()
           self.model_tester.create_and_check_for_token_classification(*a_)





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			int)		->Tuple:





           '''simple docstring'''

           for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                  A__   				=					NystromformerModel.from_pretrained(a_)
                  self.assertIsNotNone(a_)


@require_torch
class        UpperCamelCase_					(				unittest.TestCase  ):

    '''simple docstring'''






    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			List[Any])		->Tuple:





           '''simple docstring'''

           A__   				=					NystromformerModel.from_pretrained('''uw-madison/nystromformer-512''')
           A__   				=					torch.tensor([[0, 1, 2, 3, 4, 5]])

           with torch.no_grad():
                  A__   				=					model(a_)[0]

           A__   				=					torch.Size((1, 6, 768))
           self.assertEqual(output.shape      ,				a_)

           A__   				=					torch.tensor(
               [[[-0.4532, -0.0936, 0.5137], [-0.2676, 0.0628, 0.6186], [-0.3629, -0.1726, 0.4716]]])

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





    @slow
    def  SCREAMING_SNAKE_CASE							(    self   :			Any)		->Optional[int]:





           '''simple docstring'''

           A__   				=					"""the [MASK] of Belgium is Brussels"""

           A__   				=					AutoTokenizer.from_pretrained('''uw-madison/nystromformer-512''')
           A__   				=					NystromformerForMaskedLM.from_pretrained('''uw-madison/nystromformer-512''')

           A__   				=					tokenizer(a_      ,				return_tensors='''pt''')

           with torch.no_grad():
                  A__   				=					model(encoding.input_ids).logits

           A__   				=					token_logits[:, 2, :].argmax(-1)[0]

           self.assertEqual(tokenizer.decode(a_)      ,				'''capital''')








from collections import namedtuple

import requests
from lxml import html  # type: ignore

_lowerCamelCase			:	Optional[int]							 =     namedtuple("""covid_data""", """cases deaths recovered""")







def SCREAMING_SNAKE_CASE       ( lowercase_ = "https://www.worldometers.info/coronavirus/"		)     -> covid_data:



       """simple docstring"""

       A__   				=					'''//div[@class = "maincounter-number"]/span/text()'''
       return covid_data(*html.fromstring(requests.get(lowercase_		).content		).xpath(lowercase_		)		)


_lowerCamelCase			:	Optional[int]							 =     """Total COVID-19 cases in the world: {}
Total deaths due to COVID-19 in the world: {}
Total COVID-19 patients recovered in the world: {}"""
print(fmt.format(*covid_stats()))


