<jupyter_start><jupyter_text>TF ML TRAINING (MNIST DATA - SOFTMAX ALGORITHM)  Importing the dataset<jupyter_code>from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets("MNIST_data/", one_hot=True)<jupyter_output>Successfully downloaded train-images-idx3-ubyte.gz 9912422 bytes.
Extracting MNIST_data/train-images-idx3-ubyte.gz
Successfully downloaded train-labels-idx1-ubyte.gz 28881 bytes.
Extracting MNIST_data/train-labels-idx1-ubyte.gz
Successfully downloaded t10k-images-idx3-ubyte.gz 1648877 bytes.
Extracting MNIST_data/t10k-images-idx3-ubyte.gz
Successfully downloaded t10k-labels-idx1-ubyte.gz 4542 bytes.
Extracting MNIST_data/t10k-labels-idx1-ubyte.gz<jupyter_text>Importing TF library<jupyter_code>import tensorflow as tf<jupyter_output><empty_output><jupyter_text>Implementing the regression<jupyter_code># Creating a Placeholder for the inputs
x = tf.placeholder(tf.float32, [None, 784]) # float type, None = any size, 784 for each image converted
# Creating Variables
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
# Implementing Softmax model
y = tf.nn.softmax(tf.matmul(x, W) + b) # Check that x and W are flipped from the original equation<jupyter_output><empty_output><jupyter_text>Training<jupyter_code># Implementing Cross-Entropy
# y is our predicted probability distribution, and y_ is the true distribution
y_ = tf.placeholder(tf.float32, [None, 10])
cross_entropy = tf.reduce_mean(-tf.reduce_sum(y_ * tf.log(y), reduction_indices=[1]))
# Minimize cross_entropy using the gradient descent algorithm with a learning rate of 0.5.
train_step = tf.train.GradientDescentOptimizer(0.5).minimize(cross_entropy)
# Initizalize Variables
init = tf.initialize_all_variables()
# Launch the model in a session
sess = tf.Session()
sess.run(init)
# Let's train
# Training 1000 times getting a "batch" of one hundred random data points from our training set.
for i in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    sess.run(train_step, feed_dict={x: batch_xs, y_: batch_ys})<jupyter_output><empty_output><jupyter_text>Evaluating the model<jupyter_code># Checking if argmax of y one-hot array is equal to argmax of y_
correct_prediction = tf.equal(tf.argmax(y,1), tf.argmax(y_,1)) # (i.e [True, False, True, True] => [1,0,1,1])
# Taking the mean of correct_prediction array to know the accuracy
accuracy = tf.reduce_mean(tf.cast(correct_prediction, tf.float32))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))<jupyter_output>0.9197
{'fraction_non_alphanumeric': 0.107981220657277, 'fraction_numerical': 0.03403755868544601, 'mean_word_length': 6.41159420289855, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '274948', 'license': 'Apache-2.0', 'n_tokens_mistral': 980, 'n_tokens_neox': 907, 'n_words': 217, 'path': 'previous_training/tf-training/mnist-basic-training.ipynb', 'repo_name': 'archelogos/smart-live-camera', 'size': '2556'}