Merge pull request #26066 from aweers:patch-1

PiperOrigin-RevId: 235579145
This commit is contained in:
TensorFlower Gardener 2019-02-25 12:41:04 -08:00
commit 06f414573f

View File

@ -974,12 +974,14 @@ class GradientTape(object):
Example usage: Example usage:
```python
with tf.GradientTape() as g: with tf.GradientTape() as g:
x = tf.constant([1.0, 2.0]) x = tf.constant([1.0, 2.0])
g.watch(x) g.watch(x)
y = x * x y = x * x
jacobian = g.jacobian(y, x) jacobian = g.jacobian(y, x)
# jacobian value is [[2., 0.], [0., 4.]] # jacobian value is [[2., 0.], [0., 4.]]
```
Args: Args:
target: Tensor to be differentiated. target: Tensor to be differentiated.
@ -1082,12 +1084,14 @@ class GradientTape(object):
result in the jacobian computation given the independence assumption. result in the jacobian computation given the independence assumption.
Example usage: Example usage:
```python
with tf.GradientTape() as g: with tf.GradientTape() as g:
x = tf.constant([[1, 2], [3, 4]], dtype=tf.float32) x = tf.constant([[1, 2], [3, 4]], dtype=tf.float32)
g.watch(x) g.watch(x)
y = x * x y = x * x
batch_jacobian = g.batch_jacobian(y, x) batch_jacobian = g.batch_jacobian(y, x)
# batch_jacobian is [[[2, 0], [0, 4]], [[6, 0], [0, 8]]] # batch_jacobian is [[[2, 0], [0, 4]], [[6, 0], [0, 8]]]
```
Args: Args:
target: A tensor with rank 2 or higher and with shape [b, y1, ..., y_n]. target: A tensor with rank 2 or higher and with shape [b, y1, ..., y_n].