/  Deep Learning Interview questions and answers   /  Elaborate about Constants, Variables, Place holders in TensorFlow?
Tensor Datatype and Ranks 2(i2tutorials)

Elaborate about Constants, Variables, Place holders in TensorFlow?

TensorFlow supports three main type of data types namely ConstantsVariables and Placeholders.


Constant can be created using tf.constant() function.

A constant has the following arguments which can be tweaked as required to get the desired function.

value: A constant value (or list) of output type dtype.

dtype: The type of the elements of the resulting tensor.

shape: Optional dimensions of resulting tensor.

name: Optional name for the tensor.

verify_shape: Boolean that enables verification of a shape of values.


TensorFlow Variable(tf.Variable) is used to store the state of data. We can use tf.Variable for trainable variables such as weights (W) and biases (B) for our model. With Variable we need to provide the initial value. We can use Variables for parameters to learn and also for values which can be derived from training.Variable initialization must be before all other operations of the model. Since first we build a model so we have to run the initializer in the session first. tf.global_variables_initializer() does the job of initializing all the variables.


Placeholders are like the variable with no value on them but later we can place the value on it. tf.Placeholder is used to feed actual training data. The difference between a TensorFlow Variable(tf.Variable) and a placeholder is that while creating Variable , we need to specify the initial value where as in placeholder we don’t need to specify the value while defining placeholder.

Leave a comment