View source on GitHub |
Lookup embedding results, accounting for invalid IDs and empty features.
tf.compat.v1.nn.safe_embedding_lookup_sparse(
embedding_weights,
sparse_ids,
sparse_weights=None,
combiner='mean',
default_id=None,
name=None,
partition_strategy='div',
max_norm=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 P
. embedding_weights
may be a PartitionedVariable
as returned by using
tf.compat.v1.get_variable()
with a
partitioner.
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
for 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.
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
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
and
then
For instance, if params is a 10x20 matrix, and sp_ids / sp_weights are
with
|
Raises | |
---|---|
ValueError
|
if embedding_weights is empty.
|