



from __future__ import annotations

import unittest

from transformers import DistilBertConfig, is_tf_available
from transformers.testing_utils import require_tf, slow

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, ids_tensor, random_attention_mask
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
							import tensorflow as tf

							from transformers.models.distilbert.modeling_tf_distilbert import (
							    TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST,
							    TFDistilBertForMaskedLM,
							    TFDistilBertForMultipleChoice,
							    TFDistilBertForQuestionAnswering,
							    TFDistilBertForSequenceClassification,
							    TFDistilBertForTokenClassification,
							    TFDistilBertModel,
							)


class      __lowerCAmelCase     :
					"""simple docstring"""






					def __init__(     self					:       Any				,					_snake_case					:       int				,					):






								"""simple docstring"""


								A__       =    parent
								A__       =    13
								A__       =    7
								A__       =    True
								A__       =    True
								A__       =    False
								A__       =    True
								A__       =    99
								A__       =    32
								A__       =    2
								A__       =    4
								A__       =    37
								A__       =    """gelu"""
								A__       =    0.1
								A__       =    0.1
								A__       =    5_12
								A__       =    16
								A__       =    2
								A__       =    0.02
								A__       =    3
								A__       =    4
								A__       =    None



					def     _a							(     self					:       List[Any]					):






								"""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
								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__       =    DistilBertConfig(
								    vocab_size=self.vocab_size				,					dim=self.hidden_size				,					n_layers=self.num_hidden_layers				,					n_heads=self.num_attention_heads				,					hidden_dim=self.intermediate_size				,					hidden_act=self.hidden_act				,					dropout=self.hidden_dropout_prob				,					attention_dropout=self.attention_probs_dropout_prob				,					max_position_embeddings=self.max_position_embeddings				,					initializer_range=self.initializer_range				,					)

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



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






								"""simple docstring"""


								A__       =    TFDistilBertModel(config=lowercase__					)
								A__       =    {"""input_ids""": input_ids, """attention_mask""": input_mask}

								A__       =    model(lowercase__					)

								A__       =    [input_ids, input_mask]

								A__       =    model(lowercase__					)

								self.parent.assertEqual(result.last_hidden_state.shape				,					(self.batch_size, self.seq_length, self.hidden_size)					)



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






								"""simple docstring"""


								A__       =    TFDistilBertForMaskedLM(config=lowercase__					)
								A__       =    {"""input_ids""": input_ids, """attention_mask""": input_mask}
								A__       =    model(lowercase__					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.vocab_size)					)



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






								"""simple docstring"""


								A__       =    TFDistilBertForQuestionAnswering(config=lowercase__					)
								A__       =    {
								    """input_ids""": input_ids,
								    """attention_mask""": input_mask,
								}
								A__       =    model(lowercase__					)
								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					:       List[Any]				,					_snake_case					:       Optional[int]				,					_snake_case					:       Optional[Any]				,					_snake_case					:       Any				,					_snake_case					:       int				,					_snake_case					:       Optional[int]				,					_snake_case					:       str					):






								"""simple docstring"""


								A__       =    self.num_labels
								A__       =    TFDistilBertForSequenceClassification(lowercase__					)
								A__       =    {"""input_ids""": input_ids, """attention_mask""": input_mask}
								A__       =    model(lowercase__					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_labels)					)



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






								"""simple docstring"""


								A__       =    self.num_choices
								A__       =    TFDistilBertForMultipleChoice(lowercase__					)
								A__       =    tf.tile(tf.expand_dims(lowercase__				,					1					)				,					(1, self.num_choices, 1)					)
								A__       =    tf.tile(tf.expand_dims(lowercase__				,					1					)				,					(1, self.num_choices, 1)					)
								A__       =    {
								    """input_ids""": multiple_choice_inputs_ids,
								    """attention_mask""": multiple_choice_input_mask,
								}
								A__       =    model(lowercase__					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.num_choices)					)



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






								"""simple docstring"""


								A__       =    self.num_labels
								A__       =    TFDistilBertForTokenClassification(lowercase__					)
								A__       =    {"""input_ids""": input_ids, """attention_mask""": input_mask}
								A__       =    model(lowercase__					)
								self.parent.assertEqual(result.logits.shape				,					(self.batch_size, self.seq_length, self.num_labels)					)



					def     _a							(     self					:       Any					):






								"""simple docstring"""


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







@require_tf
class      __lowerCAmelCase     (		_UpperCAmelCase							,     _UpperCAmelCase							,     unittest.TestCase      ):
					"""simple docstring"""






					A__				:		List[str]			       =    (
					    (
					        TFDistilBertModel,
					        TFDistilBertForMaskedLM,
					        TFDistilBertForQuestionAnswering,
					        TFDistilBertForSequenceClassification,
					        TFDistilBertForTokenClassification,
					        TFDistilBertForMultipleChoice,
					    )
					    if is_tf_available()
					    else None
					)
					A__				:		Dict			       =    (
					    {
					        """feature-extraction""": TFDistilBertModel,
					        """fill-mask""": TFDistilBertForMaskedLM,
					        """question-answering""": TFDistilBertForQuestionAnswering,
					        """text-classification""": TFDistilBertForSequenceClassification,
					        """token-classification""": TFDistilBertForTokenClassification,
					        """zero-shot""": TFDistilBertForSequenceClassification,
					    }
					    if is_tf_available()
					    else {}
					)
					A__				:		Tuple			       =    False
					A__				:		int			       =    False



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    TFDistilBertModelTester(self					)
								A__       =    ConfigTester(self				,					config_class=lowercase__				,					dim=37					)



					def     _a							(     self					:       int					):






								"""simple docstring"""


								self.config_tester.run_common_tests()



					def     _a							(     self					:       Any					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_model(*lowercase__					)



					def     _a							(     self					:       str					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_masked_lm(*lowercase__					)



					def     _a							(     self					:       Any					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_question_answering(*lowercase__					)



					def     _a							(     self					:       List[Any]					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_sequence_classification(*lowercase__					)



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_multiple_choice(*lowercase__					)



					def     _a							(     self					:       Optional[int]					):






								"""simple docstring"""


								A__       =    self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_distilbert_for_token_classification(*lowercase__					)



					@slow
					def     _a							(     self					:       List[str]					):






								"""simple docstring"""


								for model_name in list(TF_DISTILBERT_PRETRAINED_MODEL_ARCHIVE_LIST[:1]					):
											A__       =    TFDistilBertModel.from_pretrained(lowercase__					)
											self.assertIsNotNone(lowercase__					)







@require_tf
class      __lowerCAmelCase     (		unittest.TestCase      ):
					"""simple docstring"""






					@slow
					def     _a							(     self					:       Optional[Any]					):






								"""simple docstring"""


								A__       =    TFDistilBertModel.from_pretrained('distilbert-base-uncased'					)
								A__       =    tf.constant([[0, 1, 2, 3, 4, 5]]					)
								A__       =    model(lowercase__					)[0]

								A__       =    [1, 6, 7_68]
								self.assertEqual(output.shape				,					lowercase__					)

								A__       =    tf.constant(
								    [
								        [
								            [0.1926_1885, -0.1373_2955, 0.411_9799],
								            [0.2215_0156, -0.0742_2661, 0.3903_7204],
								            [0.2275_6018, -0.089_6414, 0.370_1467],
								        ]
								    ]					)
								tf.debugging.assert_near(output[:, :3, :3]				,					lowercase__				,					atol=1E-4					)











import webbrowser
from sys import argv
from urllib.parse import parse_qs, quote

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
							SCREAMING_SNAKE_CASE__       =      '''%20'''.join(argv[1:]) if len(argv) > 1 else quote(str(input('''Search: ''')))

							print('''Googling.....''')

							SCREAMING_SNAKE_CASE__       =      f'https://www.google.com/search?q={query}&num=100'

							SCREAMING_SNAKE_CASE__       =      requests.get(
							    url,
							    headers={'''User-Agent''': str(UserAgent().random)},
							)

							try:
														SCREAMING_SNAKE_CASE__       =      (
														    BeautifulSoup(res.text, '''html.parser''')
														    .find('''div''', attrs={'''class''': '''yuRUbf'''})
														    .find('''a''')
														    .get('''href''')
														)

							except AttributeError:
														SCREAMING_SNAKE_CASE__       =      parse_qs(
														    BeautifulSoup(res.text, '''html.parser''')
														    .find('''div''', attrs={'''class''': '''kCrYT'''})
														    .find('''a''')
														    .get('''href''')
														)['''url'''][0]

							webbrowser.open(link)




