TensorFlow 2.0 Beta is available Learn more


TensorFlow 2.0 version View source on GitHub

Computes embeddings for the given ids and weights.


  • tf.compat.v1.nn.embedding_lookup_sparse




  • params: A single tensor representing the complete embedding tensor, or a list of P tensors all of same shape except for the first dimension, 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 where N is typically batch size and M is arbitrary.
  • 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.
  • name: Optional name for the op.
  • max_norm: If not None, each embedding is clipped if its l2-norm is larger than this value, before combining.



In other words, if



shape(sp_ids) = shape(sp_weights) = [d0, d1, ..., dn]


shape(output) = [d0, d1, ..., dn-1, p1, ..., pm].


[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


output[1, :] = (params[0, :] * 1.0) / 1.0
output[2, :] = (params[1, :] * 3.0) / 3.0


  • 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"}.