


'''simple docstring'''







import os
import unittest

from transformers import BatchEncoding
from transformers.models.bert.tokenization_bert import (
    BasicTokenizer,
    WordpieceTokenizer,
    _is_control,
    _is_punctuation,
    _is_whitespace,
)
from transformers.models.prophetnet.tokenization_prophetnet import VOCAB_FILES_NAMES, ProphetNetTokenizer
from transformers.testing_utils import require_torch, slow

from ...test_tokenization_common import TokenizerTesterMixin


class  lowerCAmelCase_						(       snake_case__		,    unittest.TestCase      ):





  """simple docstring"""



  a_       :int												=ProphetNetTokenizer
  a_       :List[Any]												=False

  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       super().setUp()

       __a       =   [
           """[UNK]""",
           """[CLS]""",
           """[SEP]""",
           """[PAD]""",
           """[MASK]""",
           """want""",
           """##want""",
           """##ed""",
           """wa""",
           """un""",
           """runn""",
           """##ing""",
           """,""",
           """low""",
           """lowest""",
       ]
       __a       =   os.path.join(self.tmpdirname				,							VOCAB_FILES_NAMES["""vocab_file"""]						)
       with open(self.vocab_file				,							"""w"""				,							encoding="""utf-8"""						) as vocab_writer:
            vocab_writer.write("""""".join([x + """\n""" for x in vocab_tokens]						)						)

  def __a						(					self     :							List[str]				,							SCREAMING_SNAKE_CASE__     :							int						):





       '''simple docstring'''

       __a       =   """UNwant\u00E9d,running"""
       __a       =   """unwanted, running"""
       return input_text, output_text

  def __a						(					self     :							Dict						):





       '''simple docstring'''

       __a       =   self.tokenizer_class(self.vocab_file						)

       __a       =   tokenizer.tokenize("""UNwant\u00E9d,running"""						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							["""un""", """##want""", """##ed""", """,""", """runn""", """##ing"""]						)
       self.assertListEqual(tokenizer.convert_tokens_to_ids(SCREAMING_SNAKE_CASE__						)				,							[9, 6, 7, 1_2, 1_0, 1_1]						)

  def __a						(					self     :							List[str]						):





       '''simple docstring'''

       __a       =   BasicTokenizer()

       self.assertListEqual(tokenizer.tokenize("""ah\u535A\u63A8zz"""						)				,							["""ah""", """\u535A""", """\u63A8""", """zz"""]						)

  def __a						(					self     :							Tuple						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """						)				,							["""hello""", """!""", """how""", """are""", """you""", """?"""]						)
       self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,							["""hello"""]						)

  def __a						(					self     :							Any						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				,							strip_accents=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,							["""hällo""", """!""", """how""", """are""", """you""", """?"""]						)
       self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,							["""h\u00E9llo"""]						)

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				,							strip_accents=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,							["""hallo""", """!""", """how""", """are""", """you""", """?"""]						)
       self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,							["""hello"""]						)

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,							["""hallo""", """!""", """how""", """are""", """you""", """?"""]						)
       self.assertListEqual(tokenizer.tokenize("""H\u00E9llo"""						)				,							["""hello"""]						)

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU?  """						)				,							["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)

  def __a						(					self     :							Any						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				,							strip_accents=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,							["""HäLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)

  def __a						(					self     :							Optional[int]						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				,							strip_accents=SCREAMING_SNAKE_CASE__						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHäLLo!how  \n Are yoU?  """						)				,							["""HaLLo""", """!""", """how""", """Are""", """yoU""", """?"""]						)

  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       __a       =   BasicTokenizer(do_lower_case=SCREAMING_SNAKE_CASE__				,							never_split=["""[UNK]"""]						)

       self.assertListEqual(
           tokenizer.tokenize(""" \tHeLLo!how  \n Are yoU? [UNK]"""						)				,							["""HeLLo""", """!""", """how""", """Are""", """yoU""", """?""", """[UNK]"""]						)

  def __a						(					self     :							str						):





       '''simple docstring'''

       __a       =   ["""[UNK]""", """[CLS]""", """[SEP]""", """want""", """##want""", """##ed""", """wa""", """un""", """runn""", """##ing"""]

       __a       =   {}
       for i, token in enumerate(SCREAMING_SNAKE_CASE__						):
            __a       =   i
       __a       =   WordpieceTokenizer(vocab=SCREAMING_SNAKE_CASE__				,							unk_token="""[UNK]"""						)

       self.assertListEqual(tokenizer.tokenize(""""""						)				,							[]						)

       self.assertListEqual(tokenizer.tokenize("""unwanted running"""						)				,							["""un""", """##want""", """##ed""", """runn""", """##ing"""]						)

       self.assertListEqual(tokenizer.tokenize("""unwantedX running"""						)				,							["""[UNK]""", """runn""", """##ing"""]						)

  @require_torch
  def __a						(					self     :							List[Any]						):





       '''simple docstring'''

       __a       =   self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""						)

       __a       =   ["""A long paragraph for summarization.""", """Another paragraph for summarization."""]
       __a       =   [1_0_3_7, 2_1_4_6, 2_0_4_2_3, 2_0_0_5, 7_6_8_0, 7_8_4_9, 3_9_8_9, 1_0_1_2, 1_0_2]
       __a       =   tokenizer(SCREAMING_SNAKE_CASE__				,							padding=SCREAMING_SNAKE_CASE__				,							return_tensors="""pt"""						)
       self.assertIsInstance(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)
       __a       =   list(batch.input_ids.numpy()[0]						)
       self.assertListEqual(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       self.assertEqual((2, 9)				,							batch.input_ids.shape						)
       self.assertEqual((2, 9)				,							batch.attention_mask.shape						)

  def __a						(					self     :							Union[str, Any]						):





       '''simple docstring'''

       self.assertTrue(_is_whitespace(""" """						)						)
       self.assertTrue(_is_whitespace("""\t"""						)						)
       self.assertTrue(_is_whitespace("""\r"""						)						)
       self.assertTrue(_is_whitespace("""\n"""						)						)
       self.assertTrue(_is_whitespace("""\u00A0"""						)						)

       self.assertFalse(_is_whitespace("""A"""						)						)
       self.assertFalse(_is_whitespace("""-"""						)						)

  def __a						(					self     :							Union[str, Any]						):





       '''simple docstring'''

       self.assertTrue(_is_control("""\u0005"""						)						)

       self.assertFalse(_is_control("""A"""						)						)
       self.assertFalse(_is_control(""" """						)						)
       self.assertFalse(_is_control("""\t"""						)						)
       self.assertFalse(_is_control("""\r"""						)						)

  def __a						(					self     :							Any						):





       '''simple docstring'''

       self.assertTrue(_is_punctuation("""-"""						)						)
       self.assertTrue(_is_punctuation("""$"""						)						)
       self.assertTrue(_is_punctuation("""`"""						)						)
       self.assertTrue(_is_punctuation("""."""						)						)

       self.assertFalse(_is_punctuation("""A"""						)						)
       self.assertFalse(_is_punctuation(""" """						)						)


  @slow
  def __a						(					self     :							int						):





       '''simple docstring'''

       __a       =   self.tokenizer_class.from_pretrained("""microsoft/prophetnet-large-uncased"""						)

       __a       =   tokenizer.encode("""sequence builders"""				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.encode("""multi-sequence build"""				,							add_special_tokens=SCREAMING_SNAKE_CASE__						)

       __a       =   tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__						)
       __a       =   tokenizer.build_inputs_with_special_tokens(SCREAMING_SNAKE_CASE__				,							SCREAMING_SNAKE_CASE__						)

       assert encoded_sentence == text + [1_0_2]
       assert encoded_pair == text + [1_0_2] + text_a + [1_0_2]










'''simple docstring'''







import numpy

# List of input, output pairs
SCREAMING_SNAKE_CASE_      =			(
    ((5, 2, 3), 15),
    ((6, 5, 9), 25),
    ((11, 12, 13), 41),
    ((1, 1, 1), 8),
    ((11, 12, 13), 41),
)
SCREAMING_SNAKE_CASE_      =			(((5_15, 22, 13), 5_55), ((61, 35, 49), 1_50))
SCREAMING_SNAKE_CASE_      =			[2, 4, 1, 5]
SCREAMING_SNAKE_CASE_      =			len(train_data)
SCREAMING_SNAKE_CASE_      =			0.0_0_9




def        __lowercase						(      __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE="train"		)				->					Optional[int]:
     """simple docstring"""




     return calculate_hypothesis_value(__SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE		) - output(
         __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE		)




def        __lowercase						(      __SCREAMING_SNAKE_CASE		)				->					int:
     """simple docstring"""




     __a       =   0
     for i in range(len(__SCREAMING_SNAKE_CASE		) - 1		):
          hyp_val += data_input_tuple[i] * parameter_vector[i + 1]
     hyp_val += parameter_vector[0]
     return hyp_val




def        __lowercase						(      __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE		)				->					Optional[int]:
     """simple docstring"""




     if data_set == "train":
          return train_data[example_no][1]
     elif data_set == "test":
          return test_data[example_no][1]
     return None




def        __lowercase						(      __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE		)				->					Tuple:
     """simple docstring"""




     if data_set == "train":
          return _hypothesis_value(train_data[example_no][0]		)
     elif data_set == "test":
          return _hypothesis_value(test_data[example_no][0]		)
     return None




def        __lowercase						(      __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE=m		)				->					Optional[Any]:
     """simple docstring"""




     __a       =   0
     for i in range(__SCREAMING_SNAKE_CASE		):
          if index == -1:
               summation_value += _error(__SCREAMING_SNAKE_CASE		)
          else:
               summation_value += _error(__SCREAMING_SNAKE_CASE		) * train_data[i][0][index]
     return summation_value




def        __lowercase						(      __SCREAMING_SNAKE_CASE		)				->					List[str]:
     """simple docstring"""




     __a       =   summation_of_cost_derivative(__SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE		) / m
     return cost_derivative_value




def        __lowercase						(      )				->					str:
     """simple docstring"""




     global parameter_vector
     # Tune these values to set a tolerance value for predicted output
     __a       =   0.000_002
     __a       =   0
     __a       =   0
     while True:
          j += 1
          __a       =   [0, 0, 0, 0]
          for i in range(0				,  len(__SCREAMING_SNAKE_CASE		)		):
               __a       =   get_cost_derivative(i - 1		)
               __a       =   (
                   parameter_vector[i] - LEARNING_RATE * cost_derivative
               )
          if numpy.allclose(
              __SCREAMING_SNAKE_CASE				,  __SCREAMING_SNAKE_CASE				,  atol=__SCREAMING_SNAKE_CASE				,  rtol=__SCREAMING_SNAKE_CASE				,  ):
               break
          __a       =   temp_parameter_vector
     print(("""Number of iterations:""", j)		)




def        __lowercase						(      )				->					List[Any]:
     """simple docstring"""




     for i in range(len(__SCREAMING_SNAKE_CASE		)		):
          print(("""Actual output value:""", output(__SCREAMING_SNAKE_CASE				,  """test"""		))		)
          print(("""Hypothesis output:""", calculate_hypothesis_value(__SCREAMING_SNAKE_CASE				,  """test"""		))		)


if __name__ == "__main__":
 run_gradient_descent()
 print('\nTesting gradient descent for a linear hypothesis function.\n')
 test_gradient_descent()






