简体   繁体   English

RNN语言模型(TensorFlow)的输入是什么?

[英]What is the input to an RNN language model (TensorFlow)?

I want to build a recurrent neural network (RNN) in TensorFlow that predicts the next word in a sequence of words. 我想在TensorFlow中建立一个递归神经网络(RNN),以预测单词序列中的下一个单词。 I have looked at several tutorials, eg the one of TensorFlow . 我看过一些教程,例如TensorFlow之一 I know that each word in the training text(s) is mapped to an integer index. 我知道训练文本中的每个单词都映射到一个整数索引。 However there are still a few things about the input that I don't get: 但是,关于输入,还有一些我没有得到的东西:

  1. Networks are trained with batches, eg with 128 examples at the same time. 批量训练网络,例如同时训练128个示例。 Let's say we have 10.000 words in our vocabulary. 假设我们的词汇中有10.000个单词。 Is the input to the network a matrix of size (128, sequence_length) or a one-hot encoded tensor (128, sequence_length, 10.000)? 输入到网络的矩阵是大小为(128,sequence_length)的矩阵还是单点编码的张量(128,sequence_length,10.000)?

  2. How large is the second dimension, ie the sequence length? 第二维(即序列长度)有多大? Do I use one sentence in each row of the batch, padding the sentences that are shorter than others with zeros? 我是否在批处理的每一行中使用一个句子,将比其他句子短的句子填充零?

  3. Or can a row correspond to multiple sentences? 还是一行可以对应多个句子? Eg can a row stand for "This is a test sentence. How are"? 例如,一行可以代表“这是一个测试句子。怎么样?”? If so, where does the second sentence continue? 如果是这样,第二句话在哪里继续? In the next row of the same batch? 在同一批次的下一行中? Or in the same row in the next batch? 还是在下一批的同一行中? How do I guarantee that TensorFlow continues the sentence correctly? 如何保证TensorFlow正确地继续句子?

I wasn't able to find answers to these questions even if they are quite simple. 即使这些问题很简单,我也无法找到答案。 I hope someone can help! 我希望有人能帮帮忙!

  1. Yes. 是。 It's 3-dimensional vector (128, sequence_length, 10.000) 它是3维向量(128,sequence_length,10.000)

  2. Yes. 是。 you should pad your sentences to make them same length. 您应该填充句子以使其长度相同。 AND you can use tf.nn.dynamic_rnn and it can handle sentences of variable length base on tf.while . 并且您可以使用tf.nn.dynamic_rnn并且它可以基于tf.while处理可变长度的tf.while There is great article dealt with this problem. 有一篇很棒的文章讨论了这个问题。 https://danijar.com/variable-sequence-lengths-in-tensorflow/ you can check more detail in Whats the difference between tensorflow dynamic_rnn and rnn? https://danijar.com/variable-sequence-lengths-in-tensorflow/您可以在tensorflow dynamic_rnn和rnn之间有什么区别?

  3. Possible. 可能。 but network doesn't know the sentence is connected or not. 但网络不知道该句子是否已连接。 it just consider one row as one sentence. 它只是将一行视为一句话。 So, the result will be meaningless. 因此,结果将毫无意义。

I hope this answer would help you. 希望这个答案对您有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM