GradientTape - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

DeepLearning

 create gradient tape object

 Calling Sequence GradientTape( opts )

Parameters

 opts - (optional) options as described below

Options

 • persistent = truefalse
 Specifies whether a persistent gradient tape is created.
 When true, the data is retained until Reset is called or the GradientTape object is garbage-collected.
 • When false (the default), the data is automatically collected after Gradient or Jacobian is called.

Description

 • GradientTape builds a gradient tape object to track one or more Tensors or Variables for the purposes of computing gradients.
 • This function is part of the DeepLearning package, so it can be used in the short form GradientTape(..) only after executing the command with(DeepLearning). However, it can always be accessed through the long form of the command by using DeepLearning[GradientTape](..).

 • The following functions can be performed with a GradientTape.

Details

 • The implementation of GradientTape uses the tf.GradientTape command from the TensorFlow Python API. Consult the TensorFlow Python API documentation for tf.GradientTape for more information on random number generation during TensorFlow computations.

Examples

Compute a simple gradient of a constant Tensor.

 > $\mathrm{with}\left(\mathrm{DeepLearning}\right):$
 > $x≔\mathrm{Constant}\left(\left[3.0,5.0\right]\right)$
 ${x}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (1)
 > $\mathrm{tape}≔\mathrm{GradientTape}\left(\right)$
 ${\mathrm{tape}}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning GradientTape}}\\ {\mathrm{}}\end{array}\right]$ (2)
 > $\mathrm{Enter}\left(\mathrm{tape}\right)$
 $\left[\begin{array}{c}{\mathrm{DeepLearning GradientTape}}\\ {\mathrm{}}\end{array}\right]$ (3)
 > $\mathrm{tape}:-\mathrm{Watch}\left(x\right)$
 > $y≔{x}^{2}$
 ${y}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (4)
 > $\mathrm{Exit}\left(\mathrm{tape}\right)$
 > $\mathrm{grad}≔\mathrm{tape}:-\mathrm{Gradient}\left(y,x\right)$
 ${\mathrm{grad}}{≔}\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (5)
 > ${\mathrm{grad}}_{[]}$
 $\left[\begin{array}{c}{\mathrm{DeepLearning Tensor}}\\ {\mathrm{Shape: \left[2\right]}}\\ {\mathrm{Data Type: float\left[4\right]}}\end{array}\right]$ (6)

Compatibility

 • The DeepLearning[GradientTape] command was introduced in Maple 2022.
 • For more information on Maple 2022 changes, see Updates in Maple 2022.