<jupyter_start><jupyter_text>https://discuss.d2l.ai/t/auto-differentiation/200/5<jupyter_code>import tensorflow as tf
import matplotlib.pyplot as plt
import numpy as np

x = tf.range(-10, 10, 0.1)
x = tf.Variable(x)

with tf.GradientTape() as t:
    y = tf.math.sin(x)
    
x_grad = t.gradient(y, x)

# plotting
x = np.arange(-10, 10, 0.1)
plt.figure(1)
plt.plot(x, np.sin(x), color='r')
plt.plot(x, x_grad.numpy(), color='g')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17987152034261242, 'fraction_numerical': 0.03854389721627409, 'mean_word_length': 4.5058823529411764, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '663823', 'license': 'MIT', 'n_tokens_mistral': 226, 'n_tokens_neox': 207, 'n_words': 40, 'path': 'discuss/Ch02/autograd.ipynb', 'repo_name': 'StevenJokess/d2l-en-read', 'size': '467'}