What are the parameters of TensorFlow's dynamic_rnn for this simple data set?

﹥>﹥吖頭↗ 提交于 2019-12-12 05:43:44

问题


I want to train an RNN language model using TensorFlow.

My training data is a sequence of 5 tokens represented with integers like so

 x = [0, 1, 2, 3, 4]

I want the unrolled length of the RNN to be 4, and the training batch size to be 2. (I chose these values in order to require padding.)

Each token has an embedding of length 3 like so

 0 -> [0, 0 ,0]
 1 -> [10, 10, 10]
 2 -> [20, 20, 20]
 3 -> [30, 30, 30]
 4 -> [40, 40, 40]

What should I pass as parameters to tf.nn.dynamic_rnn?

This is mostly a repost of "How is the input tensor for TensorFlow's tf.nn.dynamic_rnn operator structured?". That was helpfully answered by Eugene Brevdo. However he slightly misunderstood my question because I didn't have enough TensorFlow knowledge to ask it clearly. (Specifically he thought I meant the batch size to be 1.) Rather than risk additional confusion by editing the original question, I think it is clearest if I just rephrase it here.


I'm trying to figure this out for myself by writing an Example TensorFlow RNN Language Model.


回答1:


most rnn cells require floating point inputs, so you should first do an embedding lookup on your integer tensor to go from the Categorical values to floating point vectors in your dictionary/embedding. i believe the function is tf.nn.embedding_lookup. the output of that should be a 3-tensor shaped batch x time x embedding_depth (in your case, embedding depth is 3)

you can feed embedding_lookup an integer tensor shaped batch_size x time.



来源:https://stackoverflow.com/questions/38493468/what-are-the-parameters-of-tensorflows-dynamic-rnn-for-this-simple-data-set

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!