aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/python/ops/embedding_ops.py
diff options
context:
space:
mode:
authorGravatar Yifei Feng <yifeif@google.com>2018-04-23 21:19:14 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-04-23 21:21:38 -0700
commit22f3a97b8b089202f60bb0c7697feb0c8e0713cc (patch)
treed16f95826e4be15bbb3b0f22bed0ca25d3eb5897 /tensorflow/python/ops/embedding_ops.py
parent24b7c9a800ab5086d45a7d83ebcd6218424dc9e3 (diff)
Merge changes from github.
PiperOrigin-RevId: 194031845
Diffstat (limited to 'tensorflow/python/ops/embedding_ops.py')
-rw-r--r--tensorflow/python/ops/embedding_ops.py26
1 files changed, 15 insertions, 11 deletions
diff --git a/tensorflow/python/ops/embedding_ops.py b/tensorflow/python/ops/embedding_ops.py
index f0120f2957..9e46739bc1 100644
--- a/tensorflow/python/ops/embedding_ops.py
+++ b/tensorflow/python/ops/embedding_ops.py
@@ -331,11 +331,11 @@ def embedding_lookup_sparse(params,
representing sharded embedding tensors. Alternatively, a
`PartitionedVariable`, created by partitioning along dimension 0. Each
element must be appropriately sized for the given `partition_strategy`.
- sp_ids: N x M SparseTensor of int64 ids (typically from FeatureValueToId),
+ sp_ids: N x M `SparseTensor` of int64 ids (typically from FeatureValueToId),
where N is typically batch size and M is arbitrary.
- sp_weights: either a SparseTensor of float / double weights, or None to
- indicate all weights should be taken to be 1. If specified, sp_weights
- must have exactly the same shape and indices as sp_ids.
+ sp_weights: either a `SparseTensor` of float / double weights, or `None` to
+ indicate all weights should be taken to be 1. If specified, `sp_weights`
+ must have exactly the same shape and indices as `sp_ids`.
partition_strategy: A string specifying the partitioning strategy, relevant
if `len(params) > 1`. Currently `"div"` and `"mod"` are supported. Default
is `"mod"`. See `tf.nn.embedding_lookup` for more details.
@@ -351,39 +351,43 @@ def embedding_lookup_sparse(params,
Returns:
A dense tensor representing the combined embeddings for the
- sparse ids. For each row in the dense tensor represented by sp_ids, the op
+ sparse ids. For each row in the dense tensor represented by `sp_ids`, the op
looks up the embeddings for all ids in that row, multiplies them by the
corresponding weight, and combines these embeddings as specified.
In other words, if
- shape(combined params) = [p0, p1, ..., pm]
+ `shape(combined params) = [p0, p1, ..., pm]`
and
- shape(sp_ids) = shape(sp_weights) = [d0, d1, ..., dn]
+ `shape(sp_ids) = shape(sp_weights) = [d0, d1, ..., dn]`
then
- shape(output) = [d0, d1, ..., dn-1, p1, ..., pm].
+ `shape(output) = [d0, d1, ..., dn-1, p1, ..., pm]`.
For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are
+ ```python
[0, 0]: id 1, weight 2.0
[0, 1]: id 3, weight 0.5
[1, 0]: id 0, weight 1.0
[2, 3]: id 1, weight 3.0
+ ```
with `combiner`="mean", then the output will be a 3x20 matrix where
+ ```python
output[0, :] = (params[1, :] * 2.0 + params[3, :] * 0.5) / (2.0 + 0.5)
output[1, :] = (params[0, :] * 1.0) / 1.0
output[2, :] = (params[1, :] * 3.0) / 3.0
+ ```
Raises:
- TypeError: If sp_ids is not a SparseTensor, or if sp_weights is neither
- None nor SparseTensor.
- ValueError: If combiner is not one of {"mean", "sqrtn", "sum"}.
+ TypeError: If `sp_ids` is not a `SparseTensor`, or if `sp_weights` is
+ neither `None` nor `SparseTensor`.
+ ValueError: If `combiner` is not one of {"mean", "sqrtn", "sum"}.
"""
if combiner is None:
logging.warn("The default value of combiner will change from \"mean\" "