Beginning ML – Variables : KnowDev

In previous post we have seen how tensorflow works. Now let’s understand one of the integral component i.e tensorflow variable. A tensorflow variables are used to represent the weights in neural network !

# create a tensorflow variable

var = tf.Variable(0)

cons = tf.constant(1)

We shall update the value of the variable var and there by understanding the working of tensorflow variable.

sum = tf.add(var, cons)

assign =tf.assign(var, sum)

The construction phase is completed. Let’s start the session.

with tf.Sesstion() as sess:

print ‘var:’,, ‘cons:’,

for _ in range(3):

print ‘updated var:’,

All variables are initialised in the graph by running

output :

var: 0 cons: 1




This is a small post and very specific. As tensorflow variables are very important I wanted to give a clear explanation of their working. Now, We can actually start building our own neural network ! We will using mnist dataset provided by The data is the format that is accepted by tensorflow. Therefore we need not to preprocess any data ! We shall train and test our first neural network in next !



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s