parameters: (
      params,
      sp_ids,
      sp_weights,
      partition_strategy="mod",
      name=None,
      combiner=None,
      max_norm=None)
docstring: Computes embeddings for the given ids and weights.
  
    Embeddings belonging to same param are aggregated on that device first. This
    op is intended to decrease data transmission and improve parallelism. See
    `tf.nn.embedding_lookup_sparse` for the functionality and example of this op.
  
    Args:
      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 (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.
      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.
      combiner: A string specifying the reduction op. Currently "mean", "sqrtn"
        and "sum" are supported.
        "sum" computes the weighted sum of the embedding results for each row.
        "mean" is the weighted sum divided by the total weight.
        "sqrtn" is the weighted sum divided by the square root of the sum of the
        squares of the weights.
      max_norm: If not None, each embedding is normalized to have l2 norm equal
        to max_norm before combining.
  
    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.
  
    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"}.
docstring_summary: Computes embeddings for the given ids and weights.
docstring_tokens: Computes embeddings for the given ids and weights .
function: def embedding_lookup_sparse_with_distributed_aggregation(
      params,
      sp_ids,
      sp_weights,
      partition_strategy="mod",
      name=None,
      combiner=None,
      max_norm=None):
    """Computes embeddings for the given ids and weights.
  
    Embeddings belonging to same param are aggregated on that device first. This
    op is intended to decrease data transmission and improve parallelism. See
    `tf.nn.embedding_lookup_sparse` for the functionality and example of this op.
  
    Args:
      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 (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.
      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.
      combiner: A string specifying the reduction op. Currently "mean", "sqrtn"
        and "sum" are supported.
        "sum" computes the weighted sum of the embedding results for each row.
        "mean" is the weighted sum divided by the total weight.
        "sqrtn" is the weighted sum divided by the square root of the sum of the
        squares of the weights.
      max_norm: If not None, each embedding is normalized to have l2 norm equal
        to max_norm before combining.
  
    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.
  
    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"}.
    """
    if combiner is None:
      logging.warn("The default value of combiner will change from \"mean\" "
                   "to \"sqrtn\" after 2016/11/01.")
      combiner = "mean"
    if combiner not in ("mean", "sqrtn", "sum"):
      raise ValueError("combiner must be one of 'mean', 'sqrtn' or 'sum'")
    if isinstance(params, variables.PartitionedVariable):
      params = list(params)  # Iterate to get the underlying Variables.
    if not isinstance(params, list):
      params = [params]
    if not isinstance(sp_ids, sparse_tensor.SparseTensor):
      raise TypeError("sp_ids must be SparseTensor")
    ignore_weights = sp_weights is None
    if not ignore_weights:
      if not isinstance(sp_weights, sparse_tensor.SparseTensor):
        raise TypeError("sp_weights must be either None or SparseTensor")
      sp_ids.values.get_shape().assert_is_compatible_with(
          sp_weights.values.get_shape())
      sp_ids.indices.get_shape().assert_is_compatible_with(
          sp_weights.indices.get_shape())
      sp_ids.dense_shape.get_shape().assert_is_compatible_with(
          sp_weights.dense_shape.get_shape())
      # TODO(yleon): Add enhanced node assertions to verify that sp_ids and
      # sp_weights have equal indices and shapes.
  
    with ops.name_scope(name, "embedding_lookup_sparse",
                        params + [sp_ids]) as name:
      segment_ids = sp_ids.indices[:, 0]
      if segment_ids.dtype != dtypes.int32:
        segment_ids = math_ops.cast(segment_ids, dtypes.int32)
  
      ids = sp_ids.values
      if ignore_weights:
        ids, idx = array_ops.unique(ids)
      else:
        idx = None
  
      weights = None if ignore_weights else sp_weights.values
      embeddings = _embedding_lookup_with_distributed_aggregation(
          params,
          ids,
          partition_strategy=partition_strategy,
          max_norm=max_norm,
          weights=weights,
          idx=idx,
          segment_ids=segment_ids)
      # Set weights to all one if ignore weights.
      if ignore_weights:
        weights = array_ops.fill([array_ops.shape(segment_ids)[0]], 1)
      if weights.dtype != embeddings.dtype:
        weights = math_ops.cast(weights, embeddings.dtype)
      # Reshape weights.
      ones = array_ops.fill(
          array_ops.expand_dims(array_ops.rank(embeddings) - 1, 0), 1)
      bcast_weights_shape = array_ops.concat([array_ops.shape(weights), ones], 0)
      orig_weights_shape = weights.get_shape()
      weights = array_ops.reshape(weights, bcast_weights_shape)
      if embeddings.get_shape().ndims is not None:
        weights.set_shape(
            orig_weights_shape.concatenate(
                [1 for _ in range(embeddings.get_shape().ndims - 1)]))
  
      if combiner == "mean":
        weight_sum = math_ops.segment_sum(weights, segment_ids)
        embeddings = math_ops.div(embeddings, weight_sum)
      elif combiner == "sqrtn":
        weights_squared = math_ops.pow(weights, 2)
        weight_sum = math_ops.segment_sum(weights_squared, segment_ids)
        weight_sum_sqrt = math_ops.sqrt(weight_sum)
        embeddings = math_ops.div(embeddings, weight_sum_sqrt)
      elif combiner != "sum":
        assert False, "Unrecognized combiner"
      return embeddings
function_tokens: def embedding_lookup_sparse_with_distributed_aggregation ( params , sp_ids , sp_weights , partition_strategy = "mod" , name = None , combiner = None , max_norm = None ) : if combiner is None : logging . warn ( "The default value of combiner will change from \"mean\" " "to \"sqrtn\" after 2016/11/01." ) combiner = "mean" if combiner not in ( "mean" , "sqrtn" , "sum" ) : raise ValueError ( "combiner must be one of 'mean', 'sqrtn' or 'sum'" ) if isinstance ( params , variables . PartitionedVariable ) : params = list ( params ) # Iterate to get the underlying Variables. if not isinstance ( params , list ) : params = [ params ] if not isinstance ( sp_ids , sparse_tensor . SparseTensor ) : raise TypeError ( "sp_ids must be SparseTensor" ) ignore_weights = sp_weights is None if not ignore_weights : if not isinstance ( sp_weights , sparse_tensor . SparseTensor ) : raise TypeError ( "sp_weights must be either None or SparseTensor" ) sp_ids . values . get_shape ( ) . assert_is_compatible_with ( sp_weights . values . get_shape ( ) ) sp_ids . indices . get_shape ( ) . assert_is_compatible_with ( sp_weights . indices . get_shape ( ) ) sp_ids . dense_shape . get_shape ( ) . assert_is_compatible_with ( sp_weights . dense_shape . get_shape ( ) ) # TODO(yleon): Add enhanced node assertions to verify that sp_ids and # sp_weights have equal indices and shapes. with ops . name_scope ( name , "embedding_lookup_sparse" , params + [ sp_ids ] ) as name : segment_ids = sp_ids . indices [ : , 0 ] if segment_ids . dtype != dtypes . int32 : segment_ids = math_ops . cast ( segment_ids , dtypes . int32 ) ids = sp_ids . values if ignore_weights : ids , idx = array_ops . unique ( ids ) else : idx = None weights = None if ignore_weights else sp_weights . values embeddings = _embedding_lookup_with_distributed_aggregation ( params , ids , partition_strategy = partition_strategy , max_norm = max_norm , weights = weights , idx = idx , segment_ids = segment_ids ) # Set weights to all one if ignore weights. if ignore_weights : weights = array_ops . fill ( [ array_ops . shape ( segment_ids ) [ 0 ] ] , 1 ) if weights . dtype != embeddings . dtype : weights = math_ops . cast ( weights , embeddings . dtype ) # Reshape weights. ones = array_ops . fill ( array_ops . expand_dims ( array_ops . rank ( embeddings ) - 1 , 0 ) , 1 ) bcast_weights_shape = array_ops . concat ( [ array_ops . shape ( weights ) , ones ] , 0 ) orig_weights_shape = weights . get_shape ( ) weights = array_ops . reshape ( weights , bcast_weights_shape ) if embeddings . get_shape ( ) . ndims is not None : weights . set_shape ( orig_weights_shape . concatenate ( [ 1 for _ in range ( embeddings . get_shape ( ) . ndims - 1 ) ] ) ) if combiner == "mean" : weight_sum = math_ops . segment_sum ( weights , segment_ids ) embeddings = math_ops . div ( embeddings , weight_sum ) elif combiner == "sqrtn" : weights_squared = math_ops . pow ( weights , 2 ) weight_sum = math_ops . segment_sum ( weights_squared , segment_ids ) weight_sum_sqrt = math_ops . sqrt ( weight_sum ) embeddings = math_ops . div ( embeddings , weight_sum_sqrt ) elif combiner != "sum" : assert False , "Unrecognized combiner" return embeddings