|TensorFlow 1 version||View source on GitHub|
Lookup embedding results, accounting for invalid IDs and empty features.
tf.nn.safe_embedding_lookup_sparse( embedding_weights, sparse_ids, sparse_weights=None, combiner='mean', default_id=None, max_norm=None, name=None )
The partitioned embedding in
embedding_weights must all be the same shape
except for the first dimension. The first dimension is allowed to vary as the
vocabulary size is not necessarily a multiple of num of shards.
Invalid IDs (< 0) are pruned from input IDs and weights, as well as any IDs
with non-positive weight. For an entry with no features, the embedding vector
default_id is returned, or the 0-vector if
default_id is not supplied.
The ids and weights may be multi-dimensional. Embeddings are always aggregated along the last dimension.
len(embedding_weights) > 1, each element
ids is partitioned
between the elements of
embedding_weights according to the "div" partition
strategy, which means we assign ids to partitions in a contiguous manner. For
instance, 13 ids are split across 5 partitions as:
[[0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10], [11, 12]].
If the id space does not evenly divide the number of partitions, each of the
(max_id + 1) % len(embedding_weights) partitions will be assigned one
||A single tensor representing the complete embedding tensor, or a list of tensors all of same shape except for the first dimension, representing sharded embedding tensors following "div" partition strategy.|
||A string specifying how to combine embedding results for each entry. Currently "mean", "sqrtn" and "sum" are supported, with "mean" the default.|
||The id to use for an entry with no features. Defaults to 0-vector.|
||A name for this operation (optional).|
A dense tensor representing the combined embeddings for the
sparse ids. For each row in the dense tensor represented by
In other words, if
For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are