What does tf.nn.embedding_lookup function do?

前端 未结 8 510
深忆病人
深忆病人 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:48

    When the params tensor is in high dimensions, the ids only refers to top dimension. Maybe it's obvious to most of people but I have to run the following code to understand that:

    embeddings = tf.constant([[[1,1],[2,2],[3,3],[4,4]],[[11,11],[12,12],[13,13],[14,14]],
                              [[21,21],[22,22],[23,23],[24,24]]])
    ids=tf.constant([0,2,1])
    embed = tf.nn.embedding_lookup(embeddings, ids, partition_strategy='div')
    
    with tf.Session() as session:
        result = session.run(embed)
        print (result)
    

    Just trying the 'div' strategy and for one tensor, it makes no difference.

    Here is the output:

    [[[ 1  1]
      [ 2  2]
      [ 3  3]
      [ 4  4]]
    
     [[21 21]
      [22 22]
      [23 23]
      [24 24]]
    
     [[11 11]
      [12 12]
      [13 13]
      [14 14]]]
    

提交回复
热议问题