Skip to content

Instantly share code, notes, and snippets.

@MohanaRC
Created November 7, 2022 11:59
Show Gist options
  • Save MohanaRC/d19b4d8f348d2834b8569fc077ce15f3 to your computer and use it in GitHub Desktop.
Save MohanaRC/d19b4d8f348d2834b8569fc077ce15f3 to your computer and use it in GitHub Desktop.
def tf_gradient_tape(x):
"""
Simple implementation to understand the functioning of gradient tape
Inputs:
x: Tensor value
Returns:
EagerTensor: Derivative of y with respect to input tensor x
"""
with tf.GradientTape() as t:
t.watch(x)
y = x**3 ## Defining f(x)=x**2
# Calculating the derivative of y with respect to x
dy_dx = t.gradient(y, x)
return dy_dx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment