How do I get the gradient of the loss at a TensorFlow variable? -


the feature i'm after able tell gradient of given variable respect error function given data.

one way see how variable has changed after call train, can vary massively based on learning algorithm (for example impossible tell rprop) , isn't clean.

thanks in advance.

the tf.gradients() function allows compute symbolic gradient of 1 tensor respect 1 or more other tensors—including variables. consider following simple example:

data = tf.placeholder(tf.float32) var = tf.variable(...)              # must tf.float32 or tf.float64 variable. loss = some_function_of(var, data)  # some_function_of() returns `tensor`.  var_grad = tf.gradients(loss, [var])[0] 

you can use symbolic gradient compute numerical gradient particular data:

sess = tf.session()  var_grad_val = sess.run(var_grad, feed_dict={data: ...}) 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -