


'''simple docstring'''


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 	__lowerCAmelCase		:


  '''simple docstring'''







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

        '''simple docstring'''




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






  def        _a							(							self :       Optional[int] ):

        '''simple docstring'''




        A_						:  Tuple          =				ids_tensor([self.batch_size, self.seq_length]	,self.vocab_size )

        A_						:  int          =				None
        if self.use_input_mask:
              A_						:  Optional[int]          =				random_attention_mask([self.batch_size, self.seq_length] )

        A_						:  List[Any]          =				None
        if self.use_token_type_ids:
              A_						:  str          =				ids_tensor([self.batch_size, self.seq_length]	,self.type_vocab_size )

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

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

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






  def        _a							(							self :       List[str] ):

        '''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        _a							(							self :       str	,_a :       List[str]	,_a :       List[str]	,_a :       Optional[Any]	,_a :       Optional[Any]	,_a :       List[str]	,_a :       List[str]	,_a :       List[Any] ):

        '''simple docstring'''




        A_						:  Optional[int]          =				NystromformerModel(config=_a )
        model.to(_a )
        model.eval()
        A_						:  Optional[Any]          =				model(_a	,attention_mask=_a	,token_type_ids=_a )
        A_						:  Any          =				model(_a	,token_type_ids=_a )
        A_						:  Tuple          =				model(_a )
        self.parent.assertEqual(result.last_hidden_state.shape	,(self.batch_size, self.seq_length, self.hidden_size) )






  def        _a							(							self :       Tuple	,_a :       List[Any]	,_a :       Dict	,_a :       Tuple	,_a :       Optional[Any]	,_a :       Any	,_a :       List[Any]	,_a :       int ):

        '''simple docstring'''




        A_						:  int          =				NystromformerForMaskedLM(config=_a )
        model.to(_a )
        model.eval()
        A_						:  Tuple          =				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        _a							(							self :       Any	,_a :       Optional[Any]	,_a :       Dict	,_a :       Any	,_a :       Optional[int]	,_a :       str	,_a :       Dict	,_a :       List[str] ):

        '''simple docstring'''




        A_						:  List[str]          =				NystromformerForQuestionAnswering(config=_a )
        model.to(_a )
        model.eval()
        A_						:  Dict          =				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        _a							(							self :       str	,_a :       Optional[int]	,_a :       List[str]	,_a :       List[str]	,_a :       Any	,_a :       Tuple	,_a :       Union[str, Any]	,_a :       Union[str, Any] ):

        '''simple docstring'''




        A_						:  Optional[Any]          =				self.num_labels
        A_						:  Optional[int]          =				NystromformerForSequenceClassification(_a )
        model.to(_a )
        model.eval()
        A_						:  List[Any]          =				model(_a	,attention_mask=_a	,token_type_ids=_a	,labels=_a )
        self.parent.assertEqual(result.logits.shape	,(self.batch_size, self.num_labels) )






  def        _a							(							self :       Optional[int]	,_a :       List[Any]	,_a :       int	,_a :       Tuple	,_a :       Optional[Any]	,_a :       Any	,_a :       Union[str, Any]	,_a :       Tuple ):

        '''simple docstring'''




        A_						:  List[str]          =				self.num_labels
        A_						:  List[Any]          =				NystromformerForTokenClassification(config=_a )
        model.to(_a )
        model.eval()
        A_						:  Dict          =				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        _a							(							self :       int	,_a :       Tuple	,_a :       List[Any]	,_a :       Optional[Any]	,_a :       Any	,_a :       Optional[int]	,_a :       Tuple	,_a :       Any ):

        '''simple docstring'''




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






  def        _a							(							self :       List[str] ):

        '''simple docstring'''




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







@require_torch
class 	__lowerCAmelCase		(							__SCREAMING_SNAKE_CASE  , __SCREAMING_SNAKE_CASE  , unittest.TestCase    ):


  '''simple docstring'''







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






  def        _a							(							self :       int ):

        '''simple docstring'''




        A_						:  Any          =				NystromformerModelTester(self )
        A_						:  Any          =				ConfigTester(self	,config_class=_a	,hidden_size=37 )






  def        _a							(							self :       List[str] ):

        '''simple docstring'''




        self.config_tester.run_common_tests()






  def        _a							(							self :       List[Any] ):

        '''simple docstring'''




        A_						:  Dict          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_model(*_a )






  def        _a							(							self :       Optional[int] ):

        '''simple docstring'''




        A_						:  Tuple          =				self.model_tester.prepare_config_and_inputs()
        for type in ["absolute", "relative_key", "relative_key_query"]:
              A_						:  List[str]          =				type
              self.model_tester.create_and_check_model(*_a )






  def        _a							(							self :       str ):

        '''simple docstring'''




        A_						:  Dict          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_masked_lm(*_a )






  def        _a							(							self :       Tuple ):

        '''simple docstring'''




        A_						:  Tuple          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_multiple_choice(*_a )






  def        _a							(							self :       Dict ):

        '''simple docstring'''




        A_						:  str          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_question_answering(*_a )






  def        _a							(							self :       Any ):

        '''simple docstring'''




        A_						:  Dict          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_sequence_classification(*_a )






  def        _a							(							self :       int ):

        '''simple docstring'''




        A_						:  Dict          =				self.model_tester.prepare_config_and_inputs()
        self.model_tester.create_and_check_for_token_classification(*_a )






  @slow
  def        _a							(							self :       int ):

        '''simple docstring'''




        for model_name in NYSTROMFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
              A_						:  Optional[int]          =				NystromformerModel.from_pretrained(_a )
              self.assertIsNotNone(_a )







@require_torch
class 	__lowerCAmelCase		(							unittest.TestCase    ):


  '''simple docstring'''







  @slow
  def        _a							(							self :       int ):

        '''simple docstring'''




        A_						:  Optional[int]          =				NystromformerModel.from_pretrained("""uw-madison/nystromformer-512""" )
        A_						:  int          =				torch.tensor([[0, 1, 2, 3, 4, 5]] )

        with torch.no_grad():
              A_						:  int          =				model(_a )[0]

        A_						:  Union[str, Any]          =				torch.Size((1, 6, 768) )
        self.assertEqual(output.shape	,_a )

        A_						:  Tuple          =				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        _a							(							self :       Optional[int] ):

        '''simple docstring'''




        A_						:  Tuple          =				"""the [MASK] of Belgium is Brussels"""

        A_						:  List[Any]          =				AutoTokenizer.from_pretrained("""uw-madison/nystromformer-512""" )
        A_						:  List[Any]          =				NystromformerForMaskedLM.from_pretrained("""uw-madison/nystromformer-512""" )

        A_						:  Tuple          =				tokenizer(_a	,return_tensors="""pt""" )

        with torch.no_grad():
              A_						:  Union[str, Any]          =				model(encoding.input_ids ).logits

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

        self.assertEqual(tokenizer.decode(_a )	,"""capital""" )




'''simple docstring'''


import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
     print('Googling.....')
     __magic_name__			=      'https://www.google.com/search?q=' + ' '.join(sys.argv[1:])
     __magic_name__			=      requests.get(url, headers={'UserAgent': UserAgent().random})
     # res.raise_for_status()
     with open('project1a.html', 'wb') as out_file:  # only for knowing the class
          for data in res.iter_content(10_000):
               out_file.write(data)
     __magic_name__			=      BeautifulSoup(res.text, 'html.parser')
     __magic_name__			=      list(soup.select('.eZt8xd'))[:5]

     print(len(links))
     for link in links:
          if link.text == "Maps":
               webbrowser.open(link.get('href'))
          else:
               webbrowser.open(f"""https://google.com{link.get('href')}""")
