Created
July 3, 2020 07:00
-
-
Save mtsokol/d22adf0637e34a32727f312b9bd8df89 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
from tensorflow.keras.backend import placeholder | |
print(tf.__version__) | |
print(tf.executing_eagerly()) | |
x = placeholder(shape=(1, 1), dtype=tf.float32, name='x') | |
t = placeholder(shape=(1, 1), dtype=tf.float32, name='t') | |
W0 = tf.Variable(tf.random.normal((1,20)), dtype=tf.float32) | |
W1 = tf.Variable(tf.random.normal((2,20)), dtype=tf.float32) | |
W2 = tf.Variable(tf.random.normal((20,1)), dtype=tf.float32) | |
# Working basic version | |
with tf.GradientTape() as g: | |
g.watch(x) | |
inpt = x | |
print(inpt) | |
ur = tf.sigmoid(tf.matmul(inpt, W0)) | |
ur = tf.sigmoid(tf.matmul(ur, W2)) | |
u_t = g.gradient(ur, x) | |
print(u_t) | |
# Not working version | |
with tf.GradientTape() as g: | |
g.watch(x) | |
g.watch(t) | |
inpt = tf.concat([x,t], 1) | |
print(inpt) | |
ur = tf.sigmoid(tf.matmul(inpt, W1)) | |
ur = tf.sigmoid(tf.matmul(ur, W2)) | |
u_t = g.gradient(ur, x) | |
print(u_t) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment