Created
November 7, 2022 13:29
-
-
Save MohanaRC/1d04639c6eb095a9886caa621e3a0d16 to your computer and use it in GitHub Desktop.
This file contains 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
def tf_gradient_tape2(x): | |
""" | |
Simple implementation to understand the functioning of gradient tape for chain rule | |
Inputs: | |
x: Tensor value | |
Returns: | |
EagerTensor: Derivative of z with respect to input tensor x | |
""" | |
with tf.GradientTape() as t: | |
t.watch(x) | |
y=x*x ## Defining y(x)=x**2 | |
z=y*y ## Defining z(y)=y**2 | |
# Calculating the derivative of z with respect to x | |
dz_dx = t.gradient(z, x) | |
return dz_dx |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment