# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     name: python3
# ---

from tensorflow.examples.tutorials.mnist import input_data
import tensorflow as tf
print(tf.__version__)

data = input_data.read_data_sets('../data/MNIST', one_hot=True)
batch_size = 100
n_batch = data.train.num_samples // batch_size

x = tf.placeholder(tf.float32, [None, 784])
y = tf.placeholder(tf.float32, [None, 10])

w_1 = tf.Variable(tf.random_normal([784, 10]))
b_1 = tf.Variable(tf.zeros([10]))
o_1 = tf.nn.tanh(tf.matmul(x, w_1) + b_1)
w_2 = tf.Variable(tf.random_normal([10, 1]))
b_2 = tf.Variable(tf.zeros([1]))
pred = tf.nn.softmax(tf.matmul(o_1,w_2)+b_2)

cor = tf.equal(tf.arg_max(y,1),tf.arg_max(pred,1))
acc = tf.reduce_mean(tf.cast(cor, float32))

loss = tf.reduce_mean(tf.square(y-pred))
train = tf.train.AdagradOptimizer(0.1).minimize(loss)
init = tf.global_variables_initializer()

with tf.Session() as sess:
    sess.run(init)
    for i in range(21):
        for b in range(n_batch):
            b_x, b_y = data.train.next_batch(batch_size)
            sess.run(train,feed_dict={x:b_x, y:b_y})
    accp = sess.run(acc,feed_dict={x:test.data.images,y:data.test.labels})
    print(i, accp)

StarcoderdataJupyterScriptsDedupFiltered