title: TensorFlow Embedding Lookup
body: <p>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 <a href="https://www.tensorflow.org/versions/master/tutorials/recurrent/index.html" rel="noreferrer">TF-RNN</a></p>
  
  <p>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 <code>tf.nn.embedding_lookup</code> actually does, until I actually encountered the same function being used with two dimensional array in <a href="https://www.tensorflow.org/versions/master/tutorials/recurrent/index.html" rel="noreferrer">TF-RNN</a> <code>ptb_word_lm.py</code>, when it did not make sense any more.</p>
  
  <h3>what I though <code>tf.nn.embedding_lookup</code> does:</h3>
  
  <p>Given a 2-d array <code>params</code>, and a 1-d array <code>ids</code>, function <code>tf.nn.embedding_lookup</code> fetches rows from params, corresponding to the indices given in <code>ids</code>, which holds with the dimension of output it is returning.</p>
  
  <h3>What I am confused about:</h3>
  
  <p>When tried with same params, and 2-d array <code>ids</code>, <code>tf.nn.embedding_lookup</code> returns 3-d array, instead of 2-d which I do not understand why.</p>
  
  <p>I looked up the manual for <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/nn.html#embedding_lookup" rel="noreferrer">Embedding Lookup</a>, 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 <code>tf.nn.embedding_lookup</code> and it appears that it returns different values each time. Is this behaviour due to the randomness involved in partitioning ?</p>
  
  <p>Please help me understand how <code>tf.nn.embedding_lookup</code> works, and why is used in both <code>word2vec_basic.py</code>, and <code>ptb_word_lm.py</code> i.e., what is the purpose of even using them ?</p>