<jupyter_start><jupyter_text>Download the sample data<jupyter_code>from tensorflow.examples.tutorials.mnist import input_data
mninst = input_data.read_data_sets("MNINST_data/", one_hot=True)<jupyter_output>Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting MNINST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting MNINST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting MNINST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting MNINST_data/t10k-labels-idx1-ubyte.gz<jupyter_text>There are 55000 images, each of which is a 28 x 28 grid of greyscale pixels. These have been reshaped to be a 784 x 1 list of numbers.<jupyter_code>mninst.train.images.shape<jupyter_output><empty_output><jupyter_text>Set up our network First we have the placeholder for our input `x`. `x` consists of rows of 784 columns (one each for the 784 pixels). How many rows? That depends on how many samples we are feeding in, so we set that dimension to `None`.<jupyter_code>x = tf.placeholder(tf.float32, [None, 784])<jupyter_output><empty_output><jupyter_text>Next we set up our array of weights and vector of bias values. Remember, the goal is to produce the equation $\vec{y_i} = \mathbf{\mathit{W}} \vec{x_i} + \vec{b} $.<jupyter_code>W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.nn.softmax(tf.matmul(x, W) + b)<jupyter_output><empty_output><jupyter_text>We also have an array of training answers to compare our predictions against. We can set up a cross entropy equation to measure how well they disagree with each other.<jupyter_code>y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))<jupyter_output><empty_output><jupyter_text>Our goal, then, is to minimize this cross entropy value. We will do this with a gradient descent method, which determines the direction with the steepest reduction in error (`cross_entropy`) and moves in that direction by `0.05`<jupyter_code>train_step = tf.train.GradientDescentOptimizer(0.05).minimize(cross_entropy)<jupyter_output><empty_output><jupyter_text>Now we begin the tensorflow process. First we initialize a new session and all of the variables in it. Then we use small chunks of the data to calculate our gradients to minimize and update our values for W and b.<jupyter_code>sess = tf.InteractiveSession()
tf.global_variables_initializer().run()
for _ in range(1):
    batch_xs, batch_ys = mninst.train.next_batch(100000)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
correct_prediction = tf.equal(tf.argmax(y, 1), tf.argmax(y_, 1))
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
e = sess.run(accuracy, feed_dict={x: mninst.test.images, y_: mninst.test.labels})
e_new = 100.
e_old = 0.
epsilon = 0.0001
while abs(e_new - e_old) > epsilon:
    e_old = e_new
    
    batch_xs, batch_ys = mninst.train.next_batch(1000)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})
    
    e_new = sess.run(accuracy, feed_dict={x: mninst.test.images, y_: mninst.test.labels})
print(e_new)
print(e_old)
e_new - e_old<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10607434270172257, 'fraction_numerical': 0.03173164097914778, 'mean_word_length': 5.713995943204869, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 5, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '214325', 'license': 'MIT', 'n_tokens_mistral': 1246, 'n_tokens_neox': 1153, 'n_words': 316, 'path': 'TF_beginner.ipynb', 'repo_name': 'piovere/LibsAnalysis', 'size': '3309'}