<jupyter_start><jupyter_text>Importing packages.<jupyter_code>import tensorflow as tf
import time<jupyter_output><empty_output><jupyter_text>Creating dataset<jupyter_code>XOR_X = [[0,0],[0,1],[1,0],[1,1]]
XOR_Y = [[0],[0],[0],[1]]<jupyter_output><empty_output><jupyter_text>Creating placeholders for datasets.<jupyter_code>x_ = tf.placeholder(tf.float32, shape=[4,2], name = 'x-input')
y_ = tf.placeholder(tf.float32, shape=[4,1], name = 'y-input')<jupyter_output><empty_output><jupyter_text>Creating weights and biases<jupyter_code>Theta1 = tf.Variable(tf.random_uniform([2,2], -1, 1), name = "Theta1")
Theta2 = tf.Variable(tf.random_uniform([2,1], -1, 1), name = "Theta2")

Bias1 = tf.Variable(tf.zeros([2]), name = "Bias1")
Bias2 = tf.Variable(tf.zeros([1]), name = "Bias2")<jupyter_output><empty_output><jupyter_text>Adding layers<jupyter_code>with tf.name_scope("layer2") as scope:
	A2 = tf.sigmoid(tf.matmul(x_, Theta1) + Bias1)

with tf.name_scope("layer3") as scope:
	Hypothesis = tf.sigmoid(tf.matmul(A2, Theta2) + Bias2)<jupyter_output><empty_output><jupyter_text>Defining cost function<jupyter_code>with tf.name_scope("cost") as scope:
	cost = tf.reduce_mean(( (y_ * tf.log(Hypothesis)) + 
		((1 - y_) * tf.log(1.0 - Hypothesis)) ) * -1)<jupyter_output><empty_output><jupyter_text>Defining training operation.<jupyter_code>with tf.name_scope("train") as scope:
	train_step = tf.train.GradientDescentOptimizer(0.01).minimize(cost)<jupyter_output><empty_output><jupyter_text>Initilising variables and session.<jupyter_code>init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)<jupyter_output><empty_output><jupyter_text>Training the model<jupyter_code>t_start = time.clock()
for i in range(100000):
	sess.run(train_step, feed_dict={x_: AND_X, y_: AND_Y})
	if i % 1000 == 0:
		print('Epoch ', i)
		print('Hypothesis ', sess.run(Hypothesis, feed_dict={x_: AND_X, y_: AND_Y}))
		print('Theta1 ', sess.run(Theta1))
		print('Bias1 ', sess.run(Bias1))
		print('Theta2 ', sess.run(Theta2))
		print('Bias2 ', sess.run(Bias2))
		print('cost ', sess.run(cost, feed_dict={x_: AND_X, y_: AND_Y}))
t_end = time.clock()
print('Elapsed time ', t_end - t_start)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17497733454215775, 'fraction_numerical': 0.032638259292837715, 'mean_word_length': 7.757936507936508, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '168585', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 954, 'n_tokens_neox': 893, 'n_words': 133, 'path': 'tf_and.ipynb', 'repo_name': 'GopikrishnanSasikumar/Intro-to-Machine-Learning-Workshop', 'size': '2206'}