parameters: (
      params, values, dimension=None, sampled_candidates=None, hash_key=None,
      name=None)
docstring: Looks up embeddings using parameter hashing for each value in `values`.
  
    This method looks up selected embedding dimensions if `sampled_candidates` is
    given, otherwise looks up all dimensions.
  
    The i-th embedding component of a value v in `values` is found by retrieving
    the weight whose index is a fingerprint of the pair (v,i).
    The concept is explored as "feature hashing" for model compression in this
    paper: http://arxiv.org/pdf/1504.04788.pdf
  
    Feature hashing has the pleasant effect of allowing us to compute an embedding
    without needing a pre-determined vocabulary, relieving some amount of process
    complexity. It also allows for us to maintain embeddings for possibly
    trillions of features with a fixed amount of memory.
  
    Note that this is superior to out-of-vocabulary shared "hash buckets" in that
    the embedding is extremely likely to be unique for each token as opposed to
    being shared across probably-colliding tokens. The price is that we must
    compute a hash once for each scalar in the token's embedding as opposed to
    once per token.
  
    If `params` is a list, it represents a partition of the embedding parameters.
    Each tensor in the list should have the same length, except for the first ones
    which may have an additional element. For instance 10 parameters can be
    partitioned in 4 tensors with length `[3, 3, 2, 2]`.
  
    Args:
      params: A `Tensor`, `list` of `Tensors`, or `PartitionedVariable`.
        Each tensor must be of rank 1 with fully-defined shape.
      values: `Tensor` of values to be embedded with shape `[d0, ..., dn]`.
      dimension: Embedding dimension. The user must specify either `dimension` or
        `sampled_candidates`.
      sampled_candidates: An optional `Tensor` of slice indices to keep along the
        final dimension with shape `[d0, ..., dn, N]`. If given, `dimension` is
        ignored. If `None`, looks up all candidates.
      hash_key: Specify the hash_key that will be used by the `FingerprintCat64`
        function to combine the crosses fingerprints on SparseFeatureCrossOp
        (optional).
      name: An optional name for this op.
  
    Returns:
      A `Tensor` with shape `[d0, ..., dn, dimension]`.
      If `sampled_candidates` is given, the output shape is `[d0, ..., dn, N]`
  
    Raises:
      ValueError: if dimension is not positive or the partition size is invalid.
docstring_summary: Looks up embeddings using parameter hashing for each value in `values`.
docstring_tokens: Looks up embeddings using parameter hashing for each value in values .
function: def _sampled_scattered_embedding_lookup(
      params, values, dimension=None, sampled_candidates=None, hash_key=None,
      name=None):
    """Looks up embeddings using parameter hashing for each value in `values`.
  
    This method looks up selected embedding dimensions if `sampled_candidates` is
    given, otherwise looks up all dimensions.
  
    The i-th embedding component of a value v in `values` is found by retrieving
    the weight whose index is a fingerprint of the pair (v,i).
    The concept is explored as "feature hashing" for model compression in this
    paper: http://arxiv.org/pdf/1504.04788.pdf
  
    Feature hashing has the pleasant effect of allowing us to compute an embedding
    without needing a pre-determined vocabulary, relieving some amount of process
    complexity. It also allows for us to maintain embeddings for possibly
    trillions of features with a fixed amount of memory.
  
    Note that this is superior to out-of-vocabulary shared "hash buckets" in that
    the embedding is extremely likely to be unique for each token as opposed to
    being shared across probably-colliding tokens. The price is that we must
    compute a hash once for each scalar in the token's embedding as opposed to
    once per token.
  
    If `params` is a list, it represents a partition of the embedding parameters.
    Each tensor in the list should have the same length, except for the first ones
    which may have an additional element. For instance 10 parameters can be
    partitioned in 4 tensors with length `[3, 3, 2, 2]`.
  
    Args:
      params: A `Tensor`, `list` of `Tensors`, or `PartitionedVariable`.
        Each tensor must be of rank 1 with fully-defined shape.
      values: `Tensor` of values to be embedded with shape `[d0, ..., dn]`.
      dimension: Embedding dimension. The user must specify either `dimension` or
        `sampled_candidates`.
      sampled_candidates: An optional `Tensor` of slice indices to keep along the
        final dimension with shape `[d0, ..., dn, N]`. If given, `dimension` is
        ignored. If `None`, looks up all candidates.
      hash_key: Specify the hash_key that will be used by the `FingerprintCat64`
        function to combine the crosses fingerprints on SparseFeatureCrossOp
        (optional).
      name: An optional name for this op.
  
    Returns:
      A `Tensor` with shape `[d0, ..., dn, dimension]`.
      If `sampled_candidates` is given, the output shape is `[d0, ..., dn, N]`
  
    Raises:
      ValueError: if dimension is not positive or the partition size is invalid.
    """
    if isinstance(params, variables.PartitionedVariable):
      params = list(params)
    if not isinstance(params, list):
      params = [params]
  
    with ops.name_scope(name, "scattered_embedding_lookup",
                        params + [dimension, values]):
      # Flatten the values
      values_shape = array_ops.shape(values)
      values = array_ops.reshape(values, [-1, 1])
  
      if sampled_candidates is None:
        if dimension is None:
          raise ValueError(
              "You must specify either dimension or sampled_candidates.")
        if dimension <= 0:
          raise ValueError("Dimension must be >0. Given is %d" % dimension)
        sampled_candidates = array_ops.tile(array_ops.expand_dims(
            math_ops.range(0, dimension), 0), array_ops.shape(values))
      else:
        dimension = array_ops.shape(sampled_candidates)[
            math_ops.subtract(array_ops.rank(sampled_candidates), 1)]
        sampled_candidates_shape = array_ops.shape(sampled_candidates)
        dimension_tensor = array_ops.reshape(dimension, shape=[1,])
        expected_shape = array_ops.concat([values_shape, dimension_tensor], 0)
        with ops.control_dependencies([control_flow_ops.Assert(
            math_ops.reduce_all(math_ops.equal(sampled_candidates_shape,
                                               expected_shape)),
            ["The shape of sampled_candidates: ", sampled_candidates_shape,
             " does not match the shape of values: ", values_shape])]):
          # Flatten sampled_candidates, same way as values are flattened.
          sampled_candidates = array_ops.reshape(sampled_candidates,
                                                 [-1, dimension])
  
      num_partitions = len(params)
      partition_sizes = []
      for p in range(num_partitions):
        shape = params[p].get_shape()
        shape.assert_has_rank(1)
        shape.assert_is_fully_defined()
        partition_sizes.append(shape[0].value)
      num_params = sum(partition_sizes)  # Total number of parameters.
  
      # Assert the size of each partition.
      for p in range(num_partitions):
        expected_size = (num_params - p - 1) // num_partitions + 1
        if partition_sizes[p] != expected_size:
          raise ValueError("Tensor %d in params has size %d, expected %d." %
                           (p, partition_sizes[p], expected_size))
  
      # With two values v1 and v2 and 3 dimensions, we will cross
      # [[0, 1, 2], [0, 1, 2]] with [[v1], [v2]].
      tensors_to_cross = [sampled_candidates, values]
      ids = sparse_feature_cross_op.sparse_feature_cross(
          tensors_to_cross, hashed_output=True, num_buckets=num_params,
          hash_key=hash_key)
      ids = sparse_ops.sparse_tensor_to_dense(ids)
  
      # No need to validate the indices since we have checked the params
      # dimensions and we know the largest id.
      result = embedding_ops.embedding_lookup(
          params, ids, partition_strategy="div")
  
      return array_ops.reshape(result,
                               array_ops.concat([values_shape, [dimension]], 0))
function_tokens: def _sampled_scattered_embedding_lookup ( params , values , dimension = None , sampled_candidates = None , hash_key = None , name = None ) : if isinstance ( params , variables . PartitionedVariable ) : params = list ( params ) if not isinstance ( params , list ) : params = [ params ] with ops . name_scope ( name , "scattered_embedding_lookup" , params + [ dimension , values ] ) : # Flatten the values values_shape = array_ops . shape ( values ) values = array_ops . reshape ( values , [ - 1 , 1 ] ) if sampled_candidates is None : if dimension is None : raise ValueError ( "You must specify either dimension or sampled_candidates." ) if dimension <= 0 : raise ValueError ( "Dimension must be >0. Given is %d" % dimension ) sampled_candidates = array_ops . tile ( array_ops . expand_dims ( math_ops . range ( 0 , dimension ) , 0 ) , array_ops . shape ( values ) ) else : dimension = array_ops . shape ( sampled_candidates ) [ math_ops . subtract ( array_ops . rank ( sampled_candidates ) , 1 ) ] sampled_candidates_shape = array_ops . shape ( sampled_candidates ) dimension_tensor = array_ops . reshape ( dimension , shape = [ 1 , ] ) expected_shape = array_ops . concat ( [ values_shape , dimension_tensor ] , 0 ) with ops . control_dependencies ( [ control_flow_ops . Assert ( math_ops . reduce_all ( math_ops . equal ( sampled_candidates_shape , expected_shape ) ) , [ "The shape of sampled_candidates: " , sampled_candidates_shape , " does not match the shape of values: " , values_shape ] ) ] ) : # Flatten sampled_candidates, same way as values are flattened. sampled_candidates = array_ops . reshape ( sampled_candidates , [ - 1 , dimension ] ) num_partitions = len ( params ) partition_sizes = [ ] for p in range ( num_partitions ) : shape = params [ p ] . get_shape ( ) shape . assert_has_rank ( 1 ) shape . assert_is_fully_defined ( ) partition_sizes . append ( shape [ 0 ] . value ) num_params = sum ( partition_sizes ) # Total number of parameters. # Assert the size of each partition. for p in range ( num_partitions ) : expected_size = ( num_params - p - 1 ) // num_partitions + 1 if partition_sizes [ p ] != expected_size : raise ValueError ( "Tensor %d in params has size %d, expected %d." % ( p , partition_sizes [ p ] , expected_size ) ) # With two values v1 and v2 and 3 dimensions, we will cross # [[0, 1, 2], [0, 1, 2]] with [[v1], [v2]]. tensors_to_cross = [ sampled_candidates , values ] ids = sparse_feature_cross_op . sparse_feature_cross ( tensors_to_cross , hashed_output = True , num_buckets = num_params , hash_key = hash_key ) ids = sparse_ops . sparse_tensor_to_dense ( ids ) # No need to validate the indices since we have checked the params # dimensions and we know the largest id. result = embedding_ops . embedding_lookup ( params , ids , partition_strategy = "div" ) return array_ops . reshape ( result , array_ops . concat ( [ values_shape , [ dimension ] ] , 0 ) )