





"""simple docstring"""




import numpy




class 			_a						:






				def __init__(			self		:   int,			lowerCAmelCase__		:   numpy.ndarray,			lowerCAmelCase__		:   numpy.ndarray							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : str         =   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      : List[str]         =   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      : List[str]         =   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      : Union[str, Any]         =   numpy.random.rand(3,			1							)

										# Real output values provided.
										_UpperCamelCase      : List[Any]         =   output_array

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






				def     snake_case     (			self		:   Optional[Any]							)     ->				numpy.ndarray:




										'''simple docstring'''



										_UpperCamelCase      : Optional[int]         =   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[Any]         =   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      : Optional[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     snake_case     (			self		:   Union[str, Any]							)     ->				None:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   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      : 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      : str         =   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     snake_case     (			self		:   str,			lowerCAmelCase__		:   numpy.ndarray,			lowerCAmelCase__		:   int,			lowerCAmelCase__		:   bool							)     ->				None:




										'''simple docstring'''



										for iteration in range(1,			iterations + 1							):
																_UpperCamelCase      : Tuple         =   self.feedforward()
																self.back_propagation()
																if give_loss:
																						_UpperCamelCase      : List[Any]         =   numpy.mean(numpy.square(output - self.feedforward()							)							)
																						print(f"""Iteration {iteration} Loss: {loss}"""							)






				def     snake_case     (			self		:   Optional[int],			lowerCAmelCase__		:   numpy.ndarray							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   input_arr

										_UpperCamelCase      : Tuple         =   sigmoid(
										    numpy.dot(self.array,			self.input_layer_and_first_hidden_layer_weights							)							)

										_UpperCamelCase      : int         =   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 	a_    (							_lowercase       ):
						return 1 / (1 + numpy.exp(-value       ))





def 	a_    (							_lowercase       ):
						return (value) * (1 - (value))





def 	a_    (							):
						_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      : str         =   numpy.array(([0], [1], [1], [0], [1], [0], [0], [1])	,						dtype=numpy.floataa       )

						# Calling neural network class.
						_UpperCamelCase      : Optional[int]         =   TwoHiddenLayerNeuralNetwork(
						    input_array=_lowercase	,						output_array=_lowercase       )

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

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


if __name__ == "__main__":
						example()










"""simple docstring"""




import json
import os
import shutil
import tempfile
import unittest

import numpy as np
import pytest

from transformers import BertTokenizer, BertTokenizerFast
from transformers.models.bert.tokenization_bert import VOCAB_FILES_NAMES
from transformers.testing_utils import require_vision
from transformers.utils import FEATURE_EXTRACTOR_NAME, is_vision_available


if is_vision_available():
						from PIL import Image

						from transformers import ChineseCLIPImageProcessor, ChineseCLIPProcessor




@require_vision
class 			_a						(				unittest.TestCase    ):






				def     snake_case     (			self		:   Tuple							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : int         =   tempfile.mkdtemp()

										_UpperCamelCase      : List[str]         =   [
										    '''[UNK]''',
										    '''[CLS]''',
										    '''[SEP]''',
										    '''[PAD]''',
										    '''[MASK]''',
										    '''的''',
										    '''价''',
										    '''格''',
										    '''是''',
										    '''15''',
										    '''便''',
										    '''alex''',
										    '''##andra''',
										    '''，''',
										    '''。''',
										    '''-''',
										    '''t''',
										    '''shirt''',
										]
										_UpperCamelCase      : Optional[Any]         =   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]							)							)

										_UpperCamelCase      : Dict         =   {
										    '''do_resize''': True,
										    '''size''': {'''height''': 2_2_4, '''width''': 2_2_4},
										    '''do_center_crop''': True,
										    '''crop_size''': {'''height''': 1_8, '''width''': 1_8},
										    '''do_normalize''': True,
										    '''image_mean''': [0.48_145_466, 0.4_578_275, 0.40_821_073],
										    '''image_std''': [0.26_862_954, 0.26_130_258, 0.27_577_711],
										    '''do_convert_rgb''': True,
										}
										_UpperCamelCase      : Optional[Any]         =   os.path.join(self.tmpdirname,			lowerCAmelCase__							)
										with open(self.image_processor_file,			'''w''',			encoding='''utf-8'''							) as fp:
																json.dump(lowerCAmelCase__,			lowerCAmelCase__							)






				def     snake_case     (			self		:   str,			**lowerCAmelCase__		:   List[Any]							)     ->				Optional[int]:




										'''simple docstring'''



										return BertTokenizer.from_pretrained(self.tmpdirname,			**lowerCAmelCase__							)






				def     snake_case     (			self		:   Union[str, Any],			**lowerCAmelCase__		:   Tuple							)     ->				str:




										'''simple docstring'''



										return BertTokenizerFast.from_pretrained(self.tmpdirname,			**lowerCAmelCase__							)






				def     snake_case     (			self		:   Any,			**lowerCAmelCase__		:   Optional[int]							)     ->				Optional[Any]:




										'''simple docstring'''



										return ChineseCLIPImageProcessor.from_pretrained(self.tmpdirname,			**lowerCAmelCase__							)






				def     snake_case     (			self		:   str							)     ->				Optional[int]:




										'''simple docstring'''



										shutil.rmtree(self.tmpdirname							)






				def     snake_case     (			self		:   Any							)     ->				int:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   [np.random.randint(2_5_5,			size=(3, 3_0, 4_0_0),			dtype=np.uinta							)]

										_UpperCamelCase      : List[Any]         =   [Image.fromarray(np.moveaxis(lowerCAmelCase__,			0,			-1							)							) for x in image_inputs]

										return image_inputs






				def     snake_case     (			self		:   str							)     ->				Any:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   self.get_tokenizer()
										_UpperCamelCase      : int         =   self.get_rust_tokenizer()
										_UpperCamelCase      : int         =   self.get_image_processor()

										_UpperCamelCase      : Tuple         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)
										processor_slow.save_pretrained(self.tmpdirname							)
										_UpperCamelCase      : List[Any]         =   ChineseCLIPProcessor.from_pretrained(self.tmpdirname,			use_fast=lowerCAmelCase__							)

										_UpperCamelCase      : List[Any]         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)
										processor_fast.save_pretrained(self.tmpdirname							)
										_UpperCamelCase      : List[Any]         =   ChineseCLIPProcessor.from_pretrained(self.tmpdirname							)

										self.assertEqual(processor_slow.tokenizer.get_vocab(),			tokenizer_slow.get_vocab()							)
										self.assertEqual(processor_fast.tokenizer.get_vocab(),			tokenizer_fast.get_vocab()							)
										self.assertEqual(tokenizer_slow.get_vocab(),			tokenizer_fast.get_vocab()							)
										self.assertIsInstance(processor_slow.tokenizer,			lowerCAmelCase__							)
										self.assertIsInstance(processor_fast.tokenizer,			lowerCAmelCase__							)

										self.assertEqual(processor_slow.image_processor.to_json_string(),			image_processor.to_json_string()							)
										self.assertEqual(processor_fast.image_processor.to_json_string(),			image_processor.to_json_string()							)
										self.assertIsInstance(processor_slow.image_processor,			lowerCAmelCase__							)
										self.assertIsInstance(processor_fast.image_processor,			lowerCAmelCase__							)






				def     snake_case     (			self		:   int							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : List[Any]         =   ChineseCLIPProcessor(tokenizer=self.get_tokenizer(),			image_processor=self.get_image_processor()							)
										processor.save_pretrained(self.tmpdirname							)

										_UpperCamelCase      : Dict         =   self.get_tokenizer(cls_token='''(CLS)''',			sep_token='''(SEP)'''							)
										_UpperCamelCase      : List[str]         =   self.get_image_processor(do_normalize=lowerCAmelCase__							)

										_UpperCamelCase      : Optional[Any]         =   ChineseCLIPProcessor.from_pretrained(
										    self.tmpdirname,			cls_token='''(CLS)''',			sep_token='''(SEP)''',			do_normalize=lowerCAmelCase__							)

										self.assertEqual(processor.tokenizer.get_vocab(),			tokenizer_add_kwargs.get_vocab()							)
										self.assertIsInstance(processor.tokenizer,			lowerCAmelCase__							)

										self.assertEqual(processor.image_processor.to_json_string(),			image_processor_add_kwargs.to_json_string()							)
										self.assertIsInstance(processor.image_processor,			lowerCAmelCase__							)






				def     snake_case     (			self		:   Optional[int]							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : List[str]         =   self.get_image_processor()
										_UpperCamelCase      : str         =   self.get_tokenizer()

										_UpperCamelCase      : Optional[Any]         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)

										_UpperCamelCase      : List[str]         =   self.prepare_image_inputs()

										_UpperCamelCase      : Any         =   image_processor(lowerCAmelCase__,			return_tensors='''np'''							)
										_UpperCamelCase      : Any         =   processor(images=lowerCAmelCase__,			return_tensors='''np'''							)

										for key in input_feat_extract.keys():
																self.assertAlmostEqual(input_feat_extract[key].sum(),			input_processor[key].sum(),			delta=1e-2							)






				def     snake_case     (			self		:   Optional[Any]							)     ->				Optional[Any]:




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   self.get_image_processor()
										_UpperCamelCase      : Optional[Any]         =   self.get_tokenizer()

										_UpperCamelCase      : Any         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)

										_UpperCamelCase      : Tuple         =   '''Alexandra，T-shirt的价格是15便士。'''

										_UpperCamelCase      : List[str]         =   processor(text=lowerCAmelCase__							)

										_UpperCamelCase      : Any         =   tokenizer(lowerCAmelCase__							)

										for key in encoded_tok.keys():
																self.assertListEqual(encoded_tok[key],			encoded_processor[key]							)






				def     snake_case     (			self		:   Dict							)     ->				Tuple:




										'''simple docstring'''



										_UpperCamelCase      : Tuple         =   self.get_image_processor()
										_UpperCamelCase      : Optional[Any]         =   self.get_tokenizer()

										_UpperCamelCase      : Dict         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)

										_UpperCamelCase      : Any         =   '''Alexandra，T-shirt的价格是15便士。'''
										_UpperCamelCase      : Union[str, Any]         =   self.prepare_image_inputs()

										_UpperCamelCase      : str         =   processor(text=lowerCAmelCase__,			images=lowerCAmelCase__							)

										self.assertListEqual(list(inputs.keys()							),			['''input_ids''', '''token_type_ids''', '''attention_mask''', '''pixel_values''']							)

										# test if it raises when no input is passed
										with pytest.raises(lowerCAmelCase__							):
																processor()






				def     snake_case     (			self		:   Optional[Any]							)     ->				Union[str, Any]:




										'''simple docstring'''



										_UpperCamelCase      : int         =   self.get_image_processor()
										_UpperCamelCase      : int         =   self.get_tokenizer()

										_UpperCamelCase      : Optional[Any]         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)

										_UpperCamelCase      : List[Any]         =   [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

										_UpperCamelCase      : List[Any]         =   processor.batch_decode(lowerCAmelCase__							)
										_UpperCamelCase      : Dict         =   tokenizer.batch_decode(lowerCAmelCase__							)

										self.assertListEqual(lowerCAmelCase__,			lowerCAmelCase__							)






				def     snake_case     (			self		:   Union[str, Any]							)     ->				Dict:




										'''simple docstring'''



										_UpperCamelCase      : Any         =   self.get_image_processor()
										_UpperCamelCase      : Optional[int]         =   self.get_tokenizer()

										_UpperCamelCase      : Optional[Any]         =   ChineseCLIPProcessor(tokenizer=lowerCAmelCase__,			image_processor=lowerCAmelCase__							)

										_UpperCamelCase      : Any         =   '''Alexandra，T-shirt的价格是15便士。'''
										_UpperCamelCase      : int         =   self.prepare_image_inputs()

										_UpperCamelCase      : Dict         =   processor(text=lowerCAmelCase__,			images=lowerCAmelCase__							)

										self.assertListEqual(list(inputs.keys()							),			processor.model_input_names							)



