对于这个简单的数据集,TensorFlow 的 dynamic_rnn 的参数是什么? [英] What are the parameters of TensorFlow's dynamic_rnn for this simple data set?

查看:44
本文介绍了对于这个简单的数据集,TensorFlow 的 dynamic_rnn 的参数是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用 TensorFlow 训练一个 RNN 语言模型.

I want to train an RNN language model using TensorFlow.

我的训练数据是一个由 5 个标记组成的序列,用整数表示

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

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

我希望 RNN 的展开长度为 4,训练批次大小为 2.(我选择这些值是为了需要填充.)

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.)

每个令牌都有一个长度为 3 的嵌入,就像这样

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]

我应该将什么作为参数传递给 tf.nn.dynamic_rnn?

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

这主要是TensorFlow 的 tf.nn.dynamic_rnn 运算符的输入张量是如何构造的?".Eugene Brevdo 对此做出了有益的回答.但是他稍微误解了我的问题,因为我没有足够的 TensorFlow 知识来问清楚.(特别是他认为我的意思是批量大小为 1.)与其通过编辑原始问题来冒额外的混乱,我认为如果我在这里重新表述它是最清楚的.

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.

我试图通过编写 示例 TensorFlow RNN 语言模型来为自己解决这个问题.

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

推荐答案

大多数 rnn 单元格需要浮点输入,因此您应该首先对整数张量进行嵌入查找,以便从分类值到字典中的浮点向量/嵌入.我相信这个函数是 tf.nn.embedding_lookup.其输出应该是一个 3 张量形状的批次 x 时间 x embedding_depth(在您的情况下,嵌入深度为 3)

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)

你可以为 embedding_lookup 提供一个整数张量形状的 batch_size x 时间.

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

这篇关于对于这个简单的数据集,TensorFlow 的 dynamic_rnn 的参数是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆