@@ -35,7 +35,6 @@ accepted by [`tf.convert_to_tensor`](framework.md#convert_to_tensor).
35
35
* [ tf.nn.softmax_cross_entropy_with_logits(logits, labels, name=None)] ( #softmax_cross_entropy_with_logits )
36
36
* [ Embeddings] ( #AUTOGENERATED-embeddings )
37
37
* [ tf.nn.embedding_lookup(params, ids, name=None)] ( #embedding_lookup )
38
- * [ tf.nn.embedding_lookup_sparse(params, sp_ids, sp_weights, name=None, combiner='mean')] ( #embedding_lookup_sparse )
39
38
* [ Evaluation] ( #AUTOGENERATED-evaluation )
40
39
* [ tf.nn.top_k(input, k, name=None)] ( #top_k )
41
40
* [ tf.nn.in_top_k(predictions, targets, k, name=None)] ( #in_top_k )
@@ -130,17 +129,18 @@ sum is unchanged.
130
129
By default, each element is kept or dropped independently. If ` noise_shape `
131
130
is specified, it must be
132
131
[ broadcastable] ( http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html )
133
- to the shape of ` x ` , and only dimensions with ` noise_shape[i] == x. shape[i] `
134
- will make independent decisions. For example, if ` x. shape = [b, x, y, c] ` and
135
- ` noise_shape = [b , 1, 1, c ] ` , each batch and channel component will be
132
+ to the shape of ` x ` , and only dimensions with ` noise_shape[i] == shape(x) [i] `
133
+ will make independent decisions. For example, if ` shape(x) = [k, l, m, n] `
134
+ and ` noise_shape = [k , 1, 1, n ] ` , each batch and channel component will be
136
135
kept independently and each row and column will be kept or not kept together.
137
136
138
137
##### Args:
139
138
140
139
141
140
* <b >x</b >: A tensor.
142
- * <b >keep_prob</b >: Float probability that each element is kept.
143
- * <b >noise_shape</b >: Shape for randomly generated keep/drop flags.
141
+ * <b >keep_prob</b >: A Python float. The probability that each element is kept.
142
+ * <b >noise_shape</b >: A 1-D ` Tensor ` of type ` int32 ` , representing the
143
+ shape for randomly generated keep/drop flags.
144
144
* <b >seed</b >: A Python integer. Used to create a random seed.
145
145
See [ ` set_random_seed ` ] ( constant_op.md#set_random_seed ) for behavior.
146
146
* <b >name</b >: A name for this operation (optional).
@@ -247,10 +247,10 @@ are as follows. If the 4-D `input` has shape
247
247
` [batch, in_height, in_width, ...] ` and the 4-D ` filter ` has shape
248
248
` [filter_height, filter_width, ...] ` , then
249
249
250
- output. shape = [batch,
251
- (in_height - filter_height + 1) / strides[1],
252
- (in_width - filter_width + 1) / strides[2],
253
- ...]
250
+ shape(output) = [batch,
251
+ (in_height - filter_height + 1) / strides[1],
252
+ (in_width - filter_width + 1) / strides[2],
253
+ ...]
254
254
255
255
output[b, i, j, :] =
256
256
sum_{di, dj} input[b, strides[1] * i + di, strides[2] * j + dj, ...] *
@@ -262,7 +262,7 @@ vectors. For `depthwise_conv_2d`, each scalar component `input[b, i, j, k]`
262
262
is multiplied by a vector ` filter[di, dj, k] ` , and all the vectors are
263
263
concatenated.
264
264
265
- In the formula for ` output. shape` , the rounding direction depends on padding:
265
+ In the formula for ` shape(output) ` , the rounding direction depends on padding:
266
266
267
267
* ` padding = 'SAME' ` : Round down (only full size windows are considered).
268
268
* ` padding = 'VALID' ` : Round up (partial windows are included).
@@ -411,7 +411,7 @@ In detail, the output is
411
411
412
412
for each tuple of indices ` i ` . The output shape is
413
413
414
- output. shape = (value. shape - ksize + 1) / strides
414
+ shape(output) = (shape(value) - ksize + 1) / strides
415
415
416
416
where the rounding direction depends on padding:
417
417
@@ -722,103 +722,43 @@ and the same dtype (either `float32` or `float64`).
722
722
723
723
## Embeddings <div class =" md-anchor " id =" AUTOGENERATED-embeddings " >{#AUTOGENERATED-embeddings}</div >
724
724
725
- TensorFlow provides several operations that help you compute embeddings.
725
+ TensorFlow provides library support for looking up values in embedding
726
+ tensors.
726
727
727
728
- - -
728
729
729
730
### tf.nn.embedding_lookup(params, ids, name=None) <div class =" md-anchor " id =" embedding_lookup " >{#embedding_lookup}</div >
730
731
731
- Return a tensor of embedding values by looking up "ids" in "params" .
732
+ Looks up ` ids ` in a list of embedding tensors .
732
733
733
- ##### Args:
734
-
735
-
736
- * <b >params</b >: List of tensors of the same shape. A single tensor is
737
- treated as a singleton list.
738
- * <b >ids</b >: Tensor of integers containing the ids to be looked up in
739
- 'params'. Let P be len(params). If P > 1, then the ids are
740
- partitioned by id % P, and we do separate lookups in params[ p]
741
- for 0 <= p < P, and then stitch the results back together into
742
- a single result tensor.
743
- * <b >name</b >: Optional name for the op.
744
-
745
- ##### Returns:
746
-
747
- A tensor of shape ids.shape + params[ 0] .shape[ 1:] containing the
748
- values params[ i % P] [ i ] for each i in ids.
749
-
750
- ##### Raises:
751
-
752
-
753
- * <b >ValueError</b >: if some parameters are invalid.
734
+ This function is used to perform parallel lookups on the list of
735
+ tensors in ` params ` . It is a generalization of
736
+ [ ` tf.gather() ` ] ( array_ops.md#gather ) , where ` params ` is interpreted
737
+ as a partition of a larger embedding tensor.
754
738
739
+ If ` len(params) > 1 ` , each element ` id ` of ` ids ` is partitioned between
740
+ the elements of ` params ` by computing ` p = id % len(params) ` , and is
741
+ then used to look up the slice ` params[p][id // len(params), ...] ` .
755
742
756
- - - -
757
-
758
- ### tf.nn.embedding_lookup_sparse(params, sp_ids, sp_weights, name=None, combiner='mean') <div class =" md-anchor " id =" embedding_lookup_sparse " >{#embedding_lookup_sparse}</div >
759
-
760
- Computes embeddings for the given ids and weights.
761
-
762
- This op assumes that there is at least one id for each row in the dense tensor
763
- represented by sp_ids (i.e. there are no rows with empty features), and that
764
- all the indices of sp_ids are in canonical row-major order.
765
-
766
- It also assumes that all id values lie in the range [ 0, p0), where p0
767
- is the sum of the size of params along dimension 0.
743
+ The results of the lookup are then concatenated into a dense
744
+ tensor. The returned tensor has shape ` shape(ids) + shape(params)[1:] ` .
768
745
769
746
##### Args:
770
747
771
748
772
- * <b >params</b >: A single tensor representing the complete embedding tensor,
773
- or a list of P tensors all of same shape except for the first dimension,
774
- representing sharded embedding tensors. In the latter case, the ids are
775
- partitioned by id % P, and we do separate lookups in params[ p] for
776
- 0 <= p < P, and then stitch the results back together into a single
777
- result tensor. The first dimension is allowed to vary as the vocab
778
- size is not necessarily a multiple of P.
779
- * <b >sp_ids</b >: N x M SparseTensor of int64 ids (typically from FeatureValueToId),
780
- where N is typically batch size and M is arbitrary.
781
- * <b >sp_weights</b >: either a SparseTensor of float / double weights, or None to
782
- indicate all weights should be taken to be 1. If specified, sp_weights
783
- must have exactly the same shape and indices as sp_ids.
784
- * <b >name</b >: Optional name for the op.
785
- * <b >combiner</b >: A string specifying the reduction op. Currently "mean" and "sum"
786
- are supported.
787
- "sum" computes the weighted sum of the embedding results for each row.
788
- "mean" is the weighted sum divided by the total weight.
749
+ * <b >params</b >: A list of tensors with the same shape and type.
750
+ * <b >ids</b >: A ` Tensor ` with type ` int32 ` containing the ids to be looked
751
+ up in ` params ` .
752
+ * <b >name</b >: A name for the operation (optional).
789
753
790
754
##### Returns:
791
755
792
- A dense tensor representing the combined embeddings for the
793
- sparse ids. For each row in the dense tensor represented by sp_ids, the op
794
- looks up the embeddings for all ids in that row, multiplies them by the
795
- corresponding weight, and combines these embeddings as specified.
796
-
797
- In other words, if
798
- shape(combined params) = [ p0, p1, ..., pm]
799
- and
800
- shape(sp_ids) = shape(sp_weights) = [ d0, d1, ..., dn]
801
- then
802
- shape(output) = [ d0, d1, ..., dn-1, p1, ..., pm] .
803
-
804
- For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are
805
-
806
- [0, 0]: id 1, weight 2.0
807
- [0, 1]: id 3, weight 0.5
808
- [1, 0]: id 0, weight 1.0
809
- [2, 3]: id 1, weight 3.0
810
-
811
- with combiner="mean", then the output will be a 3x20 matrix where
812
- output[ 0, :] = (params[ 1, :] * 2.0 + params[ 3, :] * 0.5) / (2.0 + 0.5)
813
- output[ 1, :] = params[ 0, :] * 1.0
814
- output[ 2, :] = params[ 1, :] * 3.0
756
+ A ` Tensor ` with the same type as the tensors in ` params ` .
815
757
816
758
##### Raises:
817
759
818
760
819
- * <b >TypeError</b >: If sp_ids is not a SparseTensor, or if sp_weights is neither
820
- None nor SparseTensor.
821
- * <b >ValueError</b >: If combiner is not one of {"mean", "sum"}.
761
+ * <b >ValueError</b >: If ` params ` is empty.
822
762
823
763
824
764
0 commit comments