






from __future__ import annotations

import unittest

from transformers import RoFormerConfig, 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 import (
					    TFRoFormerForCausalLM,
					    TFRoFormerForMaskedLM,
					    TFRoFormerForMultipleChoice,
					    TFRoFormerForQuestionAnswering,
					    TFRoFormerForSequenceClassification,
					    TFRoFormerForTokenClassification,
					    TFRoFormerModel,
					)
					from transformers.models.roformer.modeling_tf_roformer import (
					    TFRoFormerSelfAttention,
					    TFRoFormerSinusoidalPositionalEmbedding,
					)
class     lowerCamelCase_					:







				def __init__(    self							,       __lowerCAmelCase							,       __lowerCAmelCase=1_3							,       __lowerCAmelCase=7							,       __lowerCAmelCase=True							,       __lowerCAmelCase=True							,       __lowerCAmelCase=True							,       __lowerCAmelCase=True							,       __lowerCAmelCase=9_9							,       __lowerCAmelCase=3_2							,       __lowerCAmelCase=2							,       __lowerCAmelCase=4							,       __lowerCAmelCase=3_7							,       __lowerCAmelCase="gelu"							,       __lowerCAmelCase=0.1							,       __lowerCAmelCase=0.1							,       __lowerCAmelCase=5_1_2							,       __lowerCAmelCase=1_6							,       __lowerCAmelCase=2							,       __lowerCAmelCase=0.02							,       __lowerCAmelCase=3							,       __lowerCAmelCase=4							,       __lowerCAmelCase=None							,       ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   parent
								__magic_name__		:List[Any]   =   1_3
								__magic_name__		:Union[str, Any]   =   7
								__magic_name__		:Optional[Any]   =   True
								__magic_name__		:Tuple   =   True
								__magic_name__		:List[str]   =   True
								__magic_name__		:List[Any]   =   True
								__magic_name__		:int   =   9_9
								__magic_name__		:Any   =   3_2
								__magic_name__		:Union[str, Any]   =   2
								__magic_name__		:List[str]   =   4
								__magic_name__		:List[Any]   =   3_7
								__magic_name__		:Tuple   =   '''gelu'''
								__magic_name__		:Any   =   0.1
								__magic_name__		:str   =   0.1
								__magic_name__		:List[str]   =   5_1_2
								__magic_name__		:int   =   1_6
								__magic_name__		:Any   =   2
								__magic_name__		:List[Any]   =   0.02
								__magic_name__		:Optional[Any]   =   3
								__magic_name__		:Tuple   =   4
								__magic_name__		:Optional[Any]   =   None







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   ids_tensor([self.batch_size, self.seq_length]							,       self.vocab_size  )

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

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

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

								__magic_name__		:str   =   RoFormerConfig(
								    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							,       initializer_range=self.initializer_range							,       return_dict=__lowerCAmelCase							,       )

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







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:int   =   TFRoFormerModel(config=__lowerCAmelCase  )
								__magic_name__		:Optional[Any]   =   {'''input_ids''': input_ids, '''attention_mask''': input_mask, '''token_type_ids''': token_type_ids}

								__magic_name__		:List[str]   =   [input_ids, input_mask]
								__magic_name__		:Any   =   model(__lowerCAmelCase  )

								__magic_name__		:List[str]   =   model(__lowerCAmelCase  )

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







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Dict   =   True
								__magic_name__		:List[str]   =   TFRoFormerForCausalLM(config=__lowerCAmelCase  )
								__magic_name__		:str   =   {
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}
								__magic_name__		:Optional[Any]   =   model(__lowerCAmelCase  )['''logits''']
								self.parent.assertListEqual(
								    list(prediction_scores.numpy().shape  )							,       [self.batch_size, self.seq_length, self.vocab_size]  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Optional[Any]   =   TFRoFormerForMaskedLM(config=__lowerCAmelCase  )
								__magic_name__		:Any   =   {
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}
								__magic_name__		:Dict   =   model(__lowerCAmelCase  )
								self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.seq_length, self.vocab_size)  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:int   =   self.num_labels
								__magic_name__		:str   =   TFRoFormerForSequenceClassification(config=__lowerCAmelCase  )
								__magic_name__		:Optional[int]   =   {
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}

								__magic_name__		:str   =   model(__lowerCAmelCase  )
								self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.num_labels)  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Union[str, Any]   =   self.num_choices
								__magic_name__		:Tuple   =   TFRoFormerForMultipleChoice(config=__lowerCAmelCase  )
								__magic_name__		:int   =   tf.tile(tf.expand_dims(__lowerCAmelCase							,       1  )							,       (1, self.num_choices, 1)  )
								__magic_name__		:Optional[Any]   =   tf.tile(tf.expand_dims(__lowerCAmelCase							,       1  )							,       (1, self.num_choices, 1)  )
								__magic_name__		:Union[str, Any]   =   tf.tile(tf.expand_dims(__lowerCAmelCase							,       1  )							,       (1, self.num_choices, 1)  )
								__magic_name__		:str   =   {
								    '''input_ids''': multiple_choice_inputs_ids,
								    '''attention_mask''': multiple_choice_input_mask,
								    '''token_type_ids''': multiple_choice_token_type_ids,
								}
								__magic_name__		:Tuple   =   model(__lowerCAmelCase  )
								self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.num_choices)  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   self.num_labels
								__magic_name__		:Any   =   TFRoFormerForTokenClassification(config=__lowerCAmelCase  )
								__magic_name__		:str   =   {
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}
								__magic_name__		:Dict   =   model(__lowerCAmelCase  )
								self.parent.assertEqual(result.logits.shape							,       (self.batch_size, self.seq_length, self.num_labels)  )







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								__magic_name__		:List[str]   =   TFRoFormerForQuestionAnswering(config=__lowerCAmelCase  )
								__magic_name__		:List[str]   =   {
								    '''input_ids''': input_ids,
								    '''attention_mask''': input_mask,
								    '''token_type_ids''': token_type_ids,
								}

								__magic_name__		:Union[str, Any]   =   model(__lowerCAmelCase  )
								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  ):
								"""simple docstring"""
								__magic_name__		:Union[str, Any]   =   self.prepare_config_and_inputs()
								(
								    (
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					(
								    __magic_name__
								)  ,					
								)		:Union[str, Any]   =   config_and_inputs
								__magic_name__		:Optional[Any]   =   {'''input_ids''': input_ids, '''token_type_ids''': token_type_ids, '''attention_mask''': input_mask}
								return config, inputs_dict







@require_tf
class     lowerCamelCase_					(   lowerCamelCase      ,					lowerCamelCase      ,					unittest.TestCase			):
				a__       							=	(
				    (
				        TFRoFormerModel,
				        TFRoFormerForCausalLM,
				        TFRoFormerForMaskedLM,
				        TFRoFormerForQuestionAnswering,
				        TFRoFormerForSequenceClassification,
				        TFRoFormerForTokenClassification,
				        TFRoFormerForMultipleChoice,
				    )
				    if is_tf_available()
				    else ()
				)
				a__       							=	(
				    {
				        '''feature-extraction''': TFRoFormerModel,
				        '''fill-mask''': TFRoFormerForMaskedLM,
				        '''question-answering''': TFRoFormerForQuestionAnswering,
				        '''text-classification''': TFRoFormerForSequenceClassification,
				        '''text-generation''': TFRoFormerForCausalLM,
				        '''token-classification''': TFRoFormerForTokenClassification,
				        '''zero-shot''': TFRoFormerForSequenceClassification,
				    }
				    if is_tf_available()
				    else {}
				)

				a__       							=	False
				a__       							=	False







				def       A						(    self							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  ):
								"""simple docstring"""
								if pipeline_test_casse_name == "TextGenerationPipelineTests":
												return True

								return False







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:List[str]   =   TFRoFormerModelTester(self  )
								__magic_name__		:List[str]   =   ConfigTester(self							,       config_class=__lowerCAmelCase							,       hidden_size=3_7  )







				def       A						(    self  ):
								"""simple docstring"""
								self.config_tester.run_common_tests()







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[Any]   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_model(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Union[str, Any]   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_masked_lm(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Tuple   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_lm_head(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[Any]   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_multiple_choice(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Tuple   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_question_answering(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Dict   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_sequence_classification(*__lowerCAmelCase  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   self.model_tester.prepare_config_and_inputs()
								self.model_tester.create_and_check_for_token_classification(*__lowerCAmelCase  )







				@slow
				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[Any]   =   TFRoFormerModel.from_pretrained('''junnyu/roformer_chinese_base'''  )
								self.assertIsNotNone(__lowerCAmelCase  )







@require_tf
class     lowerCamelCase_					(   unittest.TestCase			):







				@slow
				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:int   =   TFRoFormerForMaskedLM.from_pretrained('''junnyu/roformer_chinese_base'''  )
								__magic_name__		:Dict   =   tf.constant([[0, 1, 2, 3, 4, 5]]  )
								__magic_name__		:Optional[Any]   =   model(__lowerCAmelCase  )[0]

								# TODO Replace vocab size
								__magic_name__		:int   =   5_0_0_0_0

								__magic_name__		:Tuple   =   [1, 6, vocab_size]
								self.assertEqual(output.shape							,       __lowerCAmelCase  )

								print(output[:, :3, :3]  )

								# TODO Replace values below with what was printed above.
								__magic_name__		:Any   =   tf.constant(
								    [
								        [
								            [-0.12053341, -1.0264901, 0.29221946],
								            [-1.5133783, 0.197433, 0.15190607],
								            [-5.0135403, -3.900256, -0.84038764],
								        ]
								    ]  )
								tf.debugging.assert_near(output[:, :3, :3]							,       __lowerCAmelCase							,       atol=1E-4  )







@require_tf
class     lowerCamelCase_					(   unittest.TestCase			):
				a__       							=	1e-4







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Optional[int]   =   tf.constant([[4, 1_0]]  )
								__magic_name__		:Optional[int]   =   TFRoFormerSinusoidalPositionalEmbedding(num_positions=6							,       embedding_dim=6  )

								__magic_name__		:Optional[Any]   =   emba(input_ids.shape  )
								__magic_name__		:List[str]   =   tf.constant(
								    [[0.0000, 0.0000, 0.0000, 1.0000, 1.0000, 1.0000], [0.8415, 0.0464, 0.0022, 0.5403, 0.9989, 1.0000]]  )

								tf.debugging.assert_near(__lowerCAmelCase							,       __lowerCAmelCase							,       atol=self.tolerance  )







				def       A						(    self  ):
								"""simple docstring"""
								__magic_name__		:Tuple   =   tf.constant(
								    [
								        [0.0000, 0.0000, 0.0000, 0.0000, 0.0000],
								        [0.8415, 0.8219, 0.8020, 0.7819, 0.7617],
								        [0.9093, 0.9364, 0.9581, 0.9749, 0.9870],
								    ]  )
								__magic_name__		:Union[str, Any]   =   TFRoFormerSinusoidalPositionalEmbedding(num_positions=5_1_2							,       embedding_dim=5_1_2  )
								emba([2, 1_6, 5_1_2]  )
								__magic_name__		:Optional[int]   =   emba.weight[:3, :5]

								tf.debugging.assert_near(__lowerCAmelCase							,       __lowerCAmelCase							,       atol=self.tolerance  )







@require_tf
class     lowerCamelCase_					(   unittest.TestCase			):
				a__       							=	1e-4







				def       A						(    self  ):
								"""simple docstring"""
								# 2,12,16,64
								__magic_name__		:int   =   tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4							,       dtype=tf.floataa  )							,       shape=(2, 1_2, 1_6, 6_4)  ) / 1_0_0

								__magic_name__		:str   =   -tf.reshape(tf.range(2 * 1_2 * 1_6 * 6_4							,       dtype=tf.floataa  )							,       shape=(2, 1_2, 1_6, 6_4)  ) / 1_0_0

								__magic_name__		:int   =   TFRoFormerSinusoidalPositionalEmbedding(num_positions=3_2							,       embedding_dim=6_4  )
								__magic_name__		:List[str]   =   embed_positions([2, 1_6, 7_6_8]  )[None, None, :, :]

								__magic_name__  ,					__magic_name__		:Union[str, Any]   =   TFRoFormerSelfAttention.apply_rotary_position_embeddings(
								    __lowerCAmelCase							,       __lowerCAmelCase							,       __lowerCAmelCase  )

								__magic_name__		:Tuple   =   tf.constant(
								    [
								        [0.0000, 0.0100, 0.0200, 0.0300, 0.0400, 0.0500, 0.0600, 0.0700],
								        [-0.2012, 0.8897, 0.0263, 0.9401, 0.2074, 0.9463, 0.3481, 0.9343],
								        [-1.7057, 0.6271, -1.2145, 1.3897, -0.6303, 1.7647, -0.1173, 1.8985],
								        [-2.1731, -1.6397, -2.7358, 0.2854, -2.1840, 1.7183, -1.3018, 2.4871],
								        [0.2717, -3.6173, -2.9206, -2.1988, -3.6638, 0.3858, -2.9155, 2.2980],
								        [3.9859, -2.1580, -0.7984, -4.4904, -4.1181, -2.0252, -4.4782, 1.1253],
								    ]  )
								__magic_name__		:List[str]   =   tf.constant(
								    [
								        [0.0000, -0.0100, -0.0200, -0.0300, -0.0400, -0.0500, -0.0600, -0.0700],
								        [0.2012, -0.8897, -0.0263, -0.9401, -0.2074, -0.9463, -0.3481, -0.9343],
								        [1.7057, -0.6271, 1.2145, -1.3897, 0.6303, -1.7647, 0.1173, -1.8985],
								        [2.1731, 1.6397, 2.7358, -0.2854, 2.1840, -1.7183, 1.3018, -2.4871],
								        [-0.2717, 3.6173, 2.9206, 2.1988, 3.6638, -0.3858, 2.9155, -2.2980],
								        [-3.9859, 2.1580, 0.7984, 4.4904, 4.1181, 2.0252, 4.4782, -1.1253],
								    ]  )

								tf.debugging.assert_near(query_layer[0, 0, :6, :8]							,       __lowerCAmelCase							,       atol=self.tolerance  )
								tf.debugging.assert_near(key_layer[0, 0, :6, :8]							,       __lowerCAmelCase							,       atol=self.tolerance  )












'''simple docstring'''


import numpy
class 						a_				:




	def __init__(       self     :  Any       ,		__lowerCAmelCase     :  numpy.ndarray       ,		__lowerCAmelCase     :  numpy.ndarray      ):
							__snake_case						 =   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.
							__snake_case						 =   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.
							__snake_case						 =   numpy.random.rand(
							    4       ,		3      )

							# Random initial values for the second hidden layer.
							# Second hidden layer has 3 nodes.
							# Output layer has 1 node.
							__snake_case						 =   numpy.random.rand(3       ,		1      )

							# Real output values provided.
							__snake_case						 =   output_array

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




	def   lowercase__   (       self     :  Optional[Any]      ):
							__snake_case						 =   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.
							__snake_case						 =   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.
							__snake_case						 =   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   lowercase__   (       self     :  List[str]      ):
							__snake_case						 =   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      )       ,		)
							__snake_case						 =   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      )       ,		)
							__snake_case						 =   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   lowercase__   (       self     :  Optional[Any]       ,		__lowerCAmelCase     :  numpy.ndarray       ,		__lowerCAmelCase     :  int       ,		__lowerCAmelCase     :  bool      ):
							for iteration in range(1       ,		iterations + 1      ):
													__snake_case						 =   self.feedforward()
													self.back_propagation()
													if give_loss:
																			__snake_case						 =   numpy.mean(numpy.square(output - self.feedforward()      )      )
																			print(F'Iteration {iteration} Loss: {loss}'      )




	def   lowercase__   (       self     :  Optional[Any]       ,		__lowerCAmelCase     :  numpy.ndarray      ):
							__snake_case						 =   input_arr

							__snake_case						 =   sigmoid(
							    numpy.dot(self.array       ,		self.input_layer_and_first_hidden_layer_weights      )      )

							__snake_case						 =   sigmoid(
							    numpy.dot(
							        self.layer_between_input_and_first_hidden_layer       ,		self.first_hidden_layer_and_second_hidden_layer_weights       ,		)      )

							__snake_case						 =   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__   (				a							):
						return 1 / (1 + numpy.exp(-value							))
def 						lowerCamelCase__   (				a							):
						return (value) * (1 - (value))
def 						lowerCamelCase__   (				):
						__snake_case						 =   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.
						__snake_case						 =   numpy.array(([0], [1], [1], [0], [1], [0], [0], [1])    ,	dtype=numpy.floataa							)

						# Calling neural network class.
						__snake_case						 =   TwoHiddenLayerNeuralNetwork(
						    input_array=a    ,	output_array=a							)

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

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


if __name__ == "__main__":
	example()

