Project 6: Gradient Tape Derivative Demo
ML Engineer
Builds on these lessons
Current Task
Objective
tf.GradientTape() records operations on watched variables so TensorFlow can automatically compute derivatives — the mechanism training itself is built on.
Task: compute the derivative of x squared with respect to x using GradientTape, and print it.
index.py
import tensorflow as tf
x = tf.Variable(3.0)
with tf.GradientTape() as tape:
y = x ** 2
dy_dx = tape.gradient(y, x)
print(dy_dx.numpy())
* Hint: Correct characters turn green, incorrect ones turn red.
Live Preview
🖼️
Verify your code to see the preview