<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Training Data Sample
Step1:  Testing Data Sample
Step2:  Main Code
Declare parameters
Step3:  reduce_sum 
Step4:  softmax_cross_entropy_with_logits(logits, labels, dim=-1, name=None) 
Step5:  Train
This is called stochastic gradient descent method.
<ASSISTANT_TASK:>
Python Code:
plt.imshow(reshaped_sample, cmap = 'gray')
Explanation: Training Data Sample
End of explanation
test_sample = mnist.test.images[0]
print(test_sample.shape)
reshaped_test_sample = test_sample.reshape((28,28))
print(reshaped_sample.shape)
plt.imshow(reshaped_test_sample, cmap = 'gray')
Explanation: Testing Data Sample
End of explanation
import tensorflow as tf
x = tf.placeholder(tf.float32, [None, 784])
W = tf.Variable(tf.zeros([784, 10]))
b = tf.Variable(tf.zeros([10]))
y = tf.matmul(x,W) + b
Explanation: Main Code
Declare parameters
End of explanation
y_ = tf.placeholder(tf.float32, [None, 10])
Explanation: reduce_sum : adds the elements in the second dimension of y
reduce_mean : computes the mean over all the examples in the batch
GradientDescentOptimizer
End of explanation
learning_rate = 0.5
cross_entropy = tf.reduce_mean(tf.nn.softmax_cross_entropy_with_logits(y, y_))
train_step = tf.train.GradientDescentOptimizer(learning_rate).minimize(cross_entropy)
init = tf.global_variables_initializer()
sess = tf.Session()
sess.run(init)
Explanation: softmax_cross_entropy_with_logits(logits, labels, dim=-1, name=None) : computes softmax cross entropy between logits and labels.
Many classification operations : https://www.tensorflow.org/api_docs/python/nn/classification
End of explanation
for _ in range(1000):
    batch_xs, batch_ys = mnist.train.next_batch(100)
    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))
print(sess.run(accuracy, feed_dict={x: mnist.test.images, y_: mnist.test.labels}))
Explanation: Train
This is called stochastic gradient descent method.
End of explanation
<END_TASK>