code: def soft_embedding_lookup(embedding, soft_ids):
      r"""Transforms soft ids (e.g., probability distribution over ids) into
      embeddings, by mixing the embedding vectors with the soft weights.
  
      Args:
          embedding: A Tensor of shape ``[num_classes] + embedding-dim``
              containing the embedding vectors. Embedding can have
              dimensionality > 1, i.e., :attr:`embedding` can be of shape
              ``[num_classes, emb_dim_1, emb_dim_2, ...]``
          soft_ids: A Tensor of weights (probabilities) used to mix the
              embedding vectors.
  
      Returns:
          A Tensor of shape ``shape(soft_ids)[:-1] + shape(embedding)[1:]``. For
          example, if ``shape(soft_ids) = [batch_size, max_time, vocab_size]``
          and ``shape(embedding) = [vocab_size, emb_dim]``, then the return tensor
          has shape ``[batch_size, max_time, emb_dim]``.
  
      Example::
  
          decoder_outputs, ... = decoder(...)
          soft_seq_emb = soft_embedding_lookup(
              embedding, tf.nn.softmax(decoder_outputs.logits))
      """
      return tf.tensordot(
          tf.cast(soft_ids, tf.float32), embedding, [-1, 0]
      )
  
imports: import tensorflow
  from texar.tf.hyperparams import HParams
  from texar.tf.core import layers
label_desc: Use image node_id 3 for calling a global function with example usage: soft_embedding_lookup(embedding, soft_ids) and returns: tf