TensorFlow嵌入查询 [英] TensorFlow Embedding Lookup
问题描述
我正在尝试学习如何使用TensorFlow构建用于语音识别的RNN.首先,我想尝试一些在TensorFlow页面上放置的示例模型 TF-RNN
I am trying to learn how to build RNN for Speech Recognition using TensorFlow. As a start, I wanted to try out some example models put up on TensorFlow page TF-RNN
根据建议,我花了一些时间通过研究word2vec模型代码的基本版本来理解单词ID如何嵌入到密集表示(向量表示)中.我了解了tf.nn.embedding_lookup
的实际作用,直到我实际上遇到了
As per what was advised, I had taken some time to understand how word IDs are embedded into a dense representation (Vector Representation) by working through the basic version of word2vec model code. I had an understanding of what tf.nn.embedding_lookup
actually does, until I actually encountered the same function being used with two dimensional array in TF-RNN ptb_word_lm.py
, when it did not make sense any more.
给定一个二维数组params
和一个一维数组ids
,函数tf.nn.embedding_lookup
从参数中获取行,与ids
中给定的索引相对应,并保留其输出维数正在返回.
Given a 2-d array params
, and a 1-d array ids
, function tf.nn.embedding_lookup
fetches rows from params, corresponding to the indices given in ids
, which holds with the dimension of output it is returning.
当尝试使用相同的参数和2-d数组ids
时,tf.nn.embedding_lookup
返回3-d数组,而不是我不明白为什么的2-d数组.
When tried with same params, and 2-d array ids
, tf.nn.embedding_lookup
returns 3-d array, instead of 2-d which I do not understand why.
我查阅了嵌入查询的手册,但是我仍然很难理解分区的工作原理以及返回的结果.我最近用tf.nn.embedding_lookup
尝试了一个简单的示例,似乎每次都返回不同的值.这是由于分区涉及的随机性吗?
I looked up the manual for Embedding Lookup, but I still find it difficult to understand how the partitioning works, and the result that is returned. I recently tried some simple example with tf.nn.embedding_lookup
and it appears that it returns different values each time. Is this behaviour due to the randomness involved in partitioning ?
请帮助我了解tf.nn.embedding_lookup
的工作原理,以及为什么同时在word2vec_basic.py
和ptb_word_lm.py
中使用tf.nn.embedding_lookup
的原因,即使用它们的目的是什么?
Please help me understand how tf.nn.embedding_lookup
works, and why is used in both word2vec_basic.py
, and ptb_word_lm.py
i.e., what is the purpose of even using them ?