Tensorflow Placeholders and Optimizers
Tensorflow Placeholders and Optimizers
Optimizers
Placeholders
• TensorFlow, however, has designated built-in
structures for feeding input values. These
structures are called placeholders.
• Placeholders can be thought of as empty Variables
that will be filled with data later on.
• We use them by first constructing our graph and
only when it is executed feeding them with the
input data.
• Placeholders have an optional shape argument.
• If a shape is not fed or is passed as None, then the
placeholder can be fed with data of any size.
• It is common to use None for the dimension of
a matrix that corresponds to the number of
samples (usually rows), while having the length
of the features (usually columns) fixed:
• ph = tf.placeholder(tf.float32,shape=(None,10))
• Whenever we define a placeholder, we must
feed it with some input values or else an
exception will be thrown. The input data is
passed to the session.run() method as a
dictionary, where each key corresponds to a
placeholder variable name, and the matching
values are the data values given in the form of
a list or a NumPy array:
• sess.run(s,feed_dict={x: X_data,w: w_data})
import tensorflow.compat.v1 as tf
from tensorflow import *
import numpy as np
x_data = np.random.randn(5,10)
w_data = np.random.randn(10,1)
with tf.Graph().as_default():
x = tf.placeholder(tf.float32,shape=(5,10))
w = tf.placeholder(tf.float32,shape=(10,1))
b = tf.fill((5,1),-1.)
xw = tf.matmul(x,w)
xwb = xw + b
s = tf.reduce_max(xwb)
with tf.Session() as sess:
• Start Tensorboard:
%tensorboard --logdir logs
• # Control TensorBoard display. If no port is pro
vided, the most recently launched TensorBoar
d is used
notebook.display(port=6006, height=1000)
QUIZ
• Let us assume we implement an AND function to a single neuron. Below is a
tabular representation of an AND function. What would be the weights and bias?