From c854c1df8db4284eaafa8660bae800b57cdb6911 Mon Sep 17 00:00:00 2001 From: jayanth Date: Thu, 20 Feb 2020 22:23:54 -0800 Subject: [PATCH 1/2] Fix hyperlink to tf.Tensor guide. Add brief intro of eager and graph modes. --- tensorflow/python/framework/ops.py | 37 ++++++++++++++++-------------- 1 file changed, 20 insertions(+), 17 deletions(-) diff --git a/tensorflow/python/framework/ops.py b/tensorflow/python/framework/ops.py index f716dfa33dd..41fc82d84e3 100644 --- a/tensorflow/python/framework/ops.py +++ b/tensorflow/python/framework/ops.py @@ -291,22 +291,23 @@ def disable_tensor_equality(): @tf_export("Tensor") class Tensor(_TensorLike): - """A tensor represents a rectangular array of data. + """A tensor is a multidimensional array of elements represented by a + `tf.Tensor` object. All elements are of a single known data type. - When writing a TensorFlow program, the main object you manipulate and pass - around is the `tf.Tensor`. A `tf.Tensor` object represents a rectangular array - of arbitrary dimension, filled with data of a specific data type. + When writing a TensorFlow program, the main object that is + manipulated and passed around is the `tf.Tensor`. A `tf.Tensor` has the following properties: - * a data type (float32, int32, or string, for example) + * a single data type (float32, int32, or string, for example) * a shape - Each element in the Tensor has the same data type, and the data type is always - known. + TensorFlow supports two execution modes: eager and graph. In eager + mode, operations are evaluated immediately. In graph mode, a + computational graph is constructed for later evaluation. - In eager execution, which is the default mode in TensorFlow, results are - calculated immediately. + Eager mode is the default mode in TensorFlow. In the example below, + the matrix multiplication results are calculated immediately. >>> # Compute some values using a Tensor >>> c = tf.constant([[1.0, 2.0], [3.0, 4.0]]) @@ -317,7 +318,6 @@ class Tensor(_TensorLike): [[1. 3.] [3. 7.]], shape=(2, 2), dtype=float32) - Note that during eager execution, you may discover your `Tensors` are actually of type `EagerTensor`. This is an internal detail, but it does give you access to a useful function, `numpy`: @@ -328,19 +328,22 @@ class Tensor(_TensorLike): [[1. 3.] [3. 7.]] - TensorFlow can define computations without immediately executing them, most - commonly inside `tf.function`s, as well as in (legacy) Graph mode. In those - cases, the shape (that is, the rank of the Tensor and the size of - each dimension) might be only partially known. + In TensorFlow, `tf.function`s are a common way to define graph execution. + + A Tensor's shape (that is, the rank of the Tensor and the size of + each dimension) may not always be fully known. In `tf.function` + definitions, the shape may only be partially known. Most operations produce tensors of fully-known shapes if the shapes of their inputs are also fully known, but in some cases it's only possible to find the shape of a tensor at execution time. - There are specialized tensors; for these, see `tf.Variable`, `tf.constant`, - `tf.placeholder`, `tf.SparseTensor`, and `tf.RaggedTensor`. + A number of specialized tensors are available: see `tf.Variable`, + `tf.constant`, `tf.placeholder`, `tf.SparseTensor`, and + `tf.RaggedTensor`. + + For more on Tensors, see the [guide](https://tensorflow.org/guide/tensor). - For more on Tensors, see the [guide](https://tensorflow.org/guide/tensor`). """ # List of Python operators that we allow to override. From 15105513e97178818f4c46ab57a7a46cb6768552 Mon Sep 17 00:00:00 2001 From: jayanth Date: Thu, 5 Mar 2020 15:48:53 -0800 Subject: [PATCH 2/2] Address reviewer comments --- tensorflow/python/framework/ops.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/tensorflow/python/framework/ops.py b/tensorflow/python/framework/ops.py index 41fc82d84e3..6056aadd162 100644 --- a/tensorflow/python/framework/ops.py +++ b/tensorflow/python/framework/ops.py @@ -302,12 +302,13 @@ class Tensor(_TensorLike): * a single data type (float32, int32, or string, for example) * a shape - TensorFlow supports two execution modes: eager and graph. In eager - mode, operations are evaluated immediately. In graph mode, a - computational graph is constructed for later evaluation. + TensorFlow supports eager execution and graph execution. In eager + execution, operations are evaluated immediately. In graph + execution, a computational graph is constructed for later + evaluation. - Eager mode is the default mode in TensorFlow. In the example below, - the matrix multiplication results are calculated immediately. + TensorFlow defaults to eager execution. In the example below, the + matrix multiplication results are calculated immediately. >>> # Compute some values using a Tensor >>> c = tf.constant([[1.0, 2.0], [3.0, 4.0]])