<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 TensorFlow Basics
Step1:  Constants
Step2:  Operations
Step3:  Placeholders
Instead of using a constant, we can define a placeholder that allows us to provide the value at the time of execution just like function parameters.
Step4:  Variables
A variable is a tensor that can change during program execution.
Step5:  Classification using the MNIST dataset
Step6:  The MNIST dataset contain 55,000 images. The dimensions of each image is 28-by-28. Each vector has 784 elements because 28*28=784.
Step7:  Before we begin, we specify three parameters
Step8:  Network parameters
Step9:  def multi
<ASSISTANT_TASK:>
Python Code:
import tensorflow as tf
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
tf.__version__
Explanation: TensorFlow Basics
End of explanation
h = tf.constant('Hello World')
h
h.graph is tf.get_default_graph()
x = tf.constant(100)
x
# Create Session object in which we can run operations.
# A session object encapsulates the environment in which
# operations are executed. Tensor objects are evaluated
# by operations.
session = tf.Session()
session.run(h)
session.run(x)
type(session.run(x))
type(session.run(h))
Explanation: Constants
End of explanation
a = tf.constant(2)
b = tf.constant(3)
with tf.Session() as session:
    print('Addition: {}'.format(session.run(a + b)))
    print('Subtraction: {}'.format(session.run(a - b)))
    print('Multiplication: {}'.format(session.run(a * b)))
    print('Division: {}'.format(session.run(a / b)))
e = np.array([[5., 5.]])
f = np.array([[2.], [2.]])
e
f
# Convert numpy arrays to TensorFlow objects
ec = tf.constant(e)
fc = tf.constant(f)
matrix_mult_op = tf.matmul(ec, fc)
with tf.Session() as session:
    print('Matrix Multiplication: {}'.format(session.run(matrix_mult_op)))
Explanation: Operations
End of explanation
c = tf.placeholder(tf.int32)
d = tf.placeholder(tf.int32)
add_op = tf.add(c, d)
sub_op = tf.subtract(c, d)
mult_op = tf.multiply(c, d)
div_op = tf.divide(c, d)
with tf.Session() as session:
    input_dict = {c: 11, d: 10}
    print('Addition: {}'.format(session.run(add_op, feed_dict=input_dict)))
    print('Subtraction: {}'.format(session.run(sub_op, feed_dict=input_dict)))
    print('Multiplication: {}'.format(session.run(mult_op, feed_dict=input_dict)))
    print('Division: {}'.format(session.run(div_op, feed_dict={c:11, d:11})))
Explanation: Placeholders
Instead of using a constant, we can define a placeholder that allows us to provide the value at the time of execution just like function parameters.
End of explanation
var2 = tf.get_variable('var2', [2])
var2
Explanation: Variables
A variable is a tensor that can change during program execution.
End of explanation
from tensorflow.examples.tutorials.mnist import input_data
mnist = input_data.read_data_sets('data', one_hot=True)
type(mnist)
mnist.train.images
mnist.train.images.shape
Explanation: Classification using the MNIST dataset
End of explanation
# Convert the vector to a 28x28 matrix
sample_img = mnist.train.images[0].reshape(28, 28)
# Show the picture
plt.imshow(sample_img, cmap='Greys')
Explanation: The MNIST dataset contain 55,000 images. The dimensions of each image is 28-by-28. Each vector has 784 elements because 28*28=784.
End of explanation
learning_rate = 0.001
training_epochs = 15
batch_size = 100
Explanation: Before we begin, we specify three parameters:
- the learning rate $\alpha$: how quickly should the cost function be adjusted.
- training epoch: number of training cycles
- batch size: batches of training data
End of explanation
# Number of classes is 10 because we have 10 digits
n_classes = 10
# Number of training examples
n_samples = mnist.train.num_examples
# The flatten array of the 28x28 image matrix contains 784 elements
n_input = 784
# Number of neurons in the hidden layers. For image data, 256 neurons
# is common because we have 256 intensity values (8-bit).
# In this example, we only use 2 hidden layers. The more hidden
# layers, we use the longer it takes for the model to run but
# more layers has the possibility of being more accurate.
n_hidden_1 = 256
n_hidden_2 = 256
Explanation: Network parameters
End of explanation
def multilayer_perceptron(x, weights, biases):
    '''
    x: Placeholder for the data input
    weights: Dictionary of weights
    biases: Dictionary of bias values
    '''
    
    # First hidden layer with RELU activation
    layer_1 = tf.add(tf.matmul(x, weights['h1']), biases['b1'])
    layer_1 = tf.nn.relu(layer_1)
    
    # Second hidden layer with RELU activation
    layer_2 = tf.add(tf.matmul(layer_1, weights['h2']), biases['b2'])
    layer_2 = tf.nn.relu(layer_2)
    
    # Output layer
    layer_out = tf.add(tf.matmul(layer_2, weights['out']), biases['out'])
    return layer_out
weights = {
    'h1': tf.Variable(tf.random_normal(shape=[n_input, n_hidden_1])),
    'h2': tf.Variable(tf.random_normal(shape=[n_hidden_1, n_hidden_2])),
    'out': tf.Variable(tf.random_normal(shape=[n_hidden_2, n_classes]))
}
tf.random_normal(shape=(n_input, n_hidden_1))
#tf.Session().run(weights['h1'])
Explanation: def multi
End of explanation
<END_TASK>