


'''simple docstring'''






import numpy






class  __magic_name__							:






       def __init__(      self  ,							snake_case  ,							snake_case)						->  None:




          '''simple docstring'''
          _UpperCAmelCase       :       Tuple							   =input_array

          # Random initial weights are assigned where first argument is the
          # number of nodes in previous layer and second argument is the
          # number of nodes in the next layer.

          # Random initial weights are assigned.
          # self.input_array.shape[1] is used to represent number of nodes in input layer.
          # First hidden layer consists of 4 nodes.
          _UpperCAmelCase       :       int							   =numpy.random.rand(
              self.input_array.shape[1]  ,							4)

          # Random initial values for the first hidden layer.
          # First hidden layer has 4 nodes.
          # Second hidden layer has 3 nodes.
          _UpperCAmelCase       :       Tuple							   =numpy.random.rand(
              4  ,							3)

          # Random initial values for the second hidden layer.
          # Second hidden layer has 3 nodes.
          # Output layer has 1 node.
          _UpperCAmelCase       :       Optional[Any]							   =numpy.random.rand(3  ,							1)

          # Real output values provided.
          _UpperCAmelCase       :       List[str]							   =output_array

          # Predicted output values by the neural network.
          # Predicted_output array initially consists of zeroes.
          _UpperCAmelCase       :       Dict							   =numpy.zeros(output_array.shape)






       def       lowerCAmelCase		(      self)						->  numpy.ndarray:




          '''simple docstring'''
          _UpperCAmelCase       :       Any							   =sigmoid(
              numpy.dot(self.input_array  ,							self.input_layer_and_first_hidden_layer_weights))

          # layer_between_first_hidden_layer_and_second_hidden_layer is the layer
          # connecting the first hidden set of nodes with the second hidden set of nodes.
          _UpperCAmelCase       :       List[str]							   =sigmoid(
              numpy.dot(
                  self.layer_between_input_and_first_hidden_layer  ,							self.first_hidden_layer_and_second_hidden_layer_weights  ,							))

          # layer_between_second_hidden_layer_and_output is the layer connecting
          # second hidden layer with the output node.
          _UpperCAmelCase       :       List[Any]							   =sigmoid(
              numpy.dot(
                  self.layer_between_first_hidden_layer_and_second_hidden_layer  ,							self.second_hidden_layer_and_output_layer_weights  ,							))

          return self.layer_between_second_hidden_layer_and_output






       def       lowerCAmelCase		(      self)						->  None:




          '''simple docstring'''
          _UpperCAmelCase       :       int							   =numpy.dot(
              self.layer_between_first_hidden_layer_and_second_hidden_layer.T  ,							2
              * (self.output_array - self.predicted_output)
              * sigmoid_derivative(self.predicted_output)  ,							)
          _UpperCAmelCase       :       List[Any]							   =numpy.dot(
              self.layer_between_input_and_first_hidden_layer.T  ,							numpy.dot(
                  2
                  * (self.output_array - self.predicted_output)
                  * sigmoid_derivative(self.predicted_output)  ,							self.second_hidden_layer_and_output_layer_weights.T  ,							)
              * sigmoid_derivative(
                  self.layer_between_first_hidden_layer_and_second_hidden_layer)  ,							)
          _UpperCAmelCase       :       Dict							   =numpy.dot(
              self.input_array.T  ,							numpy.dot(
                  numpy.dot(
                      2
                      * (self.output_array - self.predicted_output)
                      * sigmoid_derivative(self.predicted_output)  ,							self.second_hidden_layer_and_output_layer_weights.T  ,							)
                  * sigmoid_derivative(
                      self.layer_between_first_hidden_layer_and_second_hidden_layer)  ,							self.first_hidden_layer_and_second_hidden_layer_weights.T  ,							)
              * sigmoid_derivative(self.layer_between_input_and_first_hidden_layer)  ,							)

          self.input_layer_and_first_hidden_layer_weights += (
              updated_input_layer_and_first_hidden_layer_weights
          )
          self.first_hidden_layer_and_second_hidden_layer_weights += (
              updated_first_hidden_layer_and_second_hidden_layer_weights
          )
          self.second_hidden_layer_and_output_layer_weights += (
              updated_second_hidden_layer_and_output_layer_weights
          )






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case  ,							snake_case)						->  None:




          '''simple docstring'''
          for iteration in range(1  ,							iterations + 1):
             _UpperCAmelCase       :       Dict							   =self.feedforward()
             self.back_propagation()
             if give_loss:
                _UpperCAmelCase       :       Optional[int]							   =numpy.mean(numpy.square(output - self.feedforward()))
                print(f"Iteration {iteration} Loss: {loss}")






       def       lowerCAmelCase		(      self  ,							snake_case)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   =input_arr

          _UpperCAmelCase       :       Dict							   =sigmoid(
              numpy.dot(self.array  ,							self.input_layer_and_first_hidden_layer_weights))

          _UpperCAmelCase       :       str							   =sigmoid(
              numpy.dot(
                  self.layer_between_input_and_first_hidden_layer  ,							self.first_hidden_layer_and_second_hidden_layer_weights  ,							))

          _UpperCAmelCase       :       Dict							   =sigmoid(
              numpy.dot(
                  self.layer_between_first_hidden_layer_and_second_hidden_layer  ,							self.second_hidden_layer_and_output_layer_weights  ,							))

          return int(self.layer_between_second_hidden_layer_and_output > 0.6)






def lowerCamelCase__      (						__lowerCamelCase	:							numpy.ndarray							):







   '''simple docstring'''




   return 1 / (1 + numpy.exp(-value							))





def lowerCamelCase__      (						__lowerCamelCase	:							numpy.ndarray							):







   '''simple docstring'''




   return (value) * (1 - (value))





def lowerCamelCase__      (						):







   '''simple docstring'''




   _UpperCAmelCase       :       List[Any]							   =numpy.array(
       (
           [0, 0, 0],
           [0, 0, 1],
           [0, 1, 0],
           [0, 1, 1],
           [1, 0, 0],
           [1, 0, 1],
           [1, 1, 0],
           [1, 1, 1],
       )	,   dtype=numpy.floataa	,   )

   # True output values for the given input values.
   _UpperCAmelCase       :       Dict							   =numpy.array(([0], [1], [1], [0], [1], [0], [0], [1])	,   dtype=numpy.floataa							)

   # Calling neural network class.
   _UpperCAmelCase       :       Any							   =TwoHiddenLayerNeuralNetwork(
       input_array=__lowerCamelCase	,   output_array=__lowerCamelCase							)

   # Calling training function.
   # Set give_loss to True if you want to see loss in every iteration.
   neural_network.train(output=__lowerCamelCase	,   iterations=1_0	,   give_loss=__lowerCamelCase							)

   return neural_network.predict(numpy.array(([1, 1, 1])	,   dtype=numpy.floataa							)							)


if __name__ == "__main__":
 example()





'''simple docstring'''






import datasets

from .evaluate import evaluate


lowercase							='\\n@inproceedings{Rajpurkar2016SQuAD10,\n  title={SQuAD: 100, 000+ Questions for Machine Comprehension of Text},\n  author={Pranav Rajpurkar and Jian Zhang and Konstantin Lopyrev and Percy Liang},\n  booktitle={EMNLP},\n  year={2016}\n}\n'

lowercase							='\nThis metric wrap the official scoring script for version 1 of the Stanford Question Answering Dataset (SQuAD).\n\nStanford Question Answering Dataset (SQuAD) is a reading comprehension dataset, consisting of questions posed by\ncrowdworkers on a set of Wikipedia articles, where the answer to every question is a segment of text, or span,\nfrom the corresponding reading passage, or the question might be unanswerable.\n'

lowercase							='\nComputes SQuAD scores (F1 and EM).\nArgs:\n    predictions: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair as given in the references (see below)\n        - \'prediction_text\': the text of the answer\n    references: List of question-answers dictionaries with the following key-values:\n        - \'id\': id of the question-answer pair (see above),\n        - \'answers\': a Dict in the SQuAD dataset format\n            {\n                \'text\': list of possible texts for the answer, as a list of strings\n                \'answer_start\': list of start positions for the answer, as a list of ints\n            }\n            Note that answer_start values are not taken into account to compute the metric.\nReturns:\n    \'exact_match\': Exact match (the normalized answer exactly match the gold answer)\n    \'f1\': The F-score of predicted tokens versus the gold answer\nExamples:\n\n    >>> predictions = [{\'prediction_text\': \'1976\', \'id\': \'56e10a3be3433e1400422b22\'}]\n    >>> references = [{\'answers\': {\'answer_start\': [97], \'text\': [\'1976\']}, \'id\': \'56e10a3be3433e1400422b22\'}]\n    >>> squad_metric = datasets.load_metric("squad")\n    >>> results = squad_metric.compute(predictions=predictions, references=references)\n    >>> print(results)\n    {\'exact_match\': 100.0, \'f1\': 100.0}\n'






@datasets.utils.file_utils.add_start_docstrings(_DESCRIPTION ,_KWARGS_DESCRIPTION    )
class  __magic_name__							(		datasets.Metric    ):






       def       lowerCAmelCase		(      self)						->  List[str]:




          '''simple docstring'''
          return datasets.MetricInfo(
              description=_DESCRIPTION  ,							citation=_CITATION  ,							inputs_description=_KWARGS_DESCRIPTION  ,							features=datasets.Features(
                  {
                      'predictions': {'id': datasets.Value('string'), 'prediction_text': datasets.Value('string')},
                      'references': {
                          'id': datasets.Value('string'),
                          'answers': datasets.features.Sequence(
                              {
                                  'text': datasets.Value('string'),
                                  'answer_start': datasets.Value('int32'),
                              }),
                      },
                  })  ,							codebase_urls=['https://rajpurkar.github.io/SQuAD-explorer/']  ,							reference_urls=['https://rajpurkar.github.io/SQuAD-explorer/']  ,							)






       def       lowerCAmelCase		(      self  ,							snake_case  ,							snake_case)						->  int:




          '''simple docstring'''
          _UpperCAmelCase       :       Optional[int]							   ={prediction['id']: prediction['prediction_text'] for prediction in predictions}
          _UpperCAmelCase       :       Optional[int]							   =[
              {
                  'paragraphs': [
                      {
                          'qas': [
                              {
                                  'answers': [{'text': answer_text} for answer_text in ref['answers']['text']],
                                  'id': ref['id'],
                              }
                              for ref in references
                          ]
                      }
                  ]
              }
          ]
          _UpperCAmelCase       :       List[Any]							   =evaluate(dataset=snake_case  ,							predictions=snake_case)
          return score

