What does tf.nn.embedding_lookup function do?

前端 未结 8 603
深忆病人
深忆病人 2020-12-02 04:18
tf.nn.embedding_lookup(params, ids, partition_strategy=\'mod\', name=None)

I cannot understand the duty of this function. Is it like a lookup table

8条回答
  •  一向
    一向 (楼主)
    2020-12-02 04:49

    Here's an image depicting the process of embedding lookup.

    Image: Embedding lookup process

    Concisely, it gets the corresponding rows of a embedding layer, specified by a list of IDs and provide that as a tensor. It is achieved through the following process.

    1. Define a placeholder lookup_ids = tf.placeholder([10])
    2. Define a embedding layer embeddings = tf.Variable([100,10],...)
    3. Define the tensorflow operation embed_lookup = tf.embedding_lookup(embeddings, lookup_ids)
    4. Get the results by running lookup = session.run(embed_lookup, feed_dict={lookup_ids:[95,4,14]})

提交回复
热议问题