Skip to content

Instantly share code, notes, and snippets.

@MohanaRC
Created November 7, 2022 13:29
Show Gist options
  • Save MohanaRC/1d04639c6eb095a9886caa621e3a0d16 to your computer and use it in GitHub Desktop.
Save MohanaRC/1d04639c6eb095a9886caa621e3a0d16 to your computer and use it in GitHub Desktop.
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