MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / embedding_lookup_sparse

Function embedding_lookup_sparse

tensorflow/python/ops/embedding_ops.py:484–665  ·  view source on GitHub ↗

Computes embeddings for the given ids and weights. This op assumes that there is at least one id for each row in the dense tensor represented by sp_ids (i.e. there are no rows with empty features), and that all the indices of sp_ids are in canonical row-major order. It also assumes that all

(params,
                            sp_ids,
                            sp_weights,
                            partition_strategy="mod",
                            name=None,
                            combiner=None,
                            max_norm=None,
                            blocknums=None)

Source from the content-addressed store, hash-verified

482
483@tf_export(v1=["nn.embedding_lookup_sparse"])
484def embedding_lookup_sparse(params,
485 sp_ids,
486 sp_weights,
487 partition_strategy="mod",
488 name=None,
489 combiner=None,
490 max_norm=None,
491 blocknums=None):
492 """Computes embeddings for the given ids and weights.
493 This op assumes that there is at least one id for each row in the dense tensor
494 represented by sp_ids (i.e. there are no rows with empty features), and that
495 all the indices of sp_ids are in canonical row-major order.
496 It also assumes that all id values lie in the range [0, p0), where p0
497 is the sum of the size of params along dimension 0.
498 Args:
499 params: A single tensor representing the complete embedding tensor, or a
500 list of P tensors all of same shape except for the first dimension,
501 representing sharded embedding tensors. Alternatively, a
502 `PartitionedVariable`, created by partitioning along dimension 0. Each
503 element must be appropriately sized for the given `partition_strategy`.
504 sp_ids: N x M `SparseTensor` of int64 ids where N is typically batch size
505 and M is arbitrary.
506 sp_weights: either a `SparseTensor` of float / double weights, or `None` to
507 indicate all weights should be taken to be 1. If specified, `sp_weights`
508 must have exactly the same shape and indices as `sp_ids`.
509 partition_strategy: A string specifying the partitioning strategy, relevant
510 if `len(params) > 1`. Currently `"div"` and `"mod"` are supported. Default
511 is `"mod"`. See `tf.nn.embedding_lookup` for more details.
512 name: Optional name for the op.
513 combiner: A string specifying the reduction op. Currently "mean", "sqrtn",
514 "tile" and "sum" are supported. "sum" computes the weighted sum of the
515 embedding results for each row. "mean" is the weighted sum divided by the
516 total weight. "sqrtn" is the weighted sum divided by the square root of the
517 sum of the squares of the weights.
518 max_norm: If not `None`, each embedding is clipped if its l2-norm is larger
519 than this value, before combining.
520 Returns:
521 A dense tensor representing the combined embeddings for the
522 sparse ids. For each row in the dense tensor represented by `sp_ids`, the op
523 looks up the embeddings for all ids in that row, multiplies them by the
524 corresponding weight, and combines these embeddings as specified.
525 In other words, if
526 `shape(combined params) = [p0, p1, ..., pm]`
527 and
528 `shape(sp_ids) = shape(sp_weights) = [d0, d1, ..., dn]`
529 then
530 `shape(output) = [d0, d1, ..., dn-1, p1, ..., pm]`.
531 For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are
532 ```python
533 [0, 0]: id 1, weight 2.0
534 [0, 1]: id 3, weight 0.5
535 [1, 0]: id 0, weight 1.0
536 [2, 3]: id 1, weight 3.0
537 ```
538 with `combiner`="mean", then the output will be a 3x20 matrix where
539 ```python
540 output[0, :] = (params[1, :] * 2.0 + params[3, :] * 0.5) / (2.0 + 0.5)
541 output[1, :] = (params[0, :] * 1.0) / 1.0

Callers 3

Calls 15

need_countsMethod · 0.80
fillMethod · 0.80
reshapeMethod · 0.80
divMethod · 0.80
add_to_collectionsMethod · 0.80
embedding_lookupFunction · 0.70
rangeFunction · 0.70
_tile_combine_embeddingFunction · 0.70
get_shapeMethod · 0.45
name_scopeMethod · 0.45
castMethod · 0.45

Tested by

no test coverage detected