我可以使用下一层的输出作为Keras的当前图层输入吗?

awe*_*ght 5 nlp neural-network lstm keras

在文本生成任务中,我们通常使用模型的最后输出作为当前输入来生成下一个单词.更一般化,我想实现一个神经网络,将下一层的最终隐藏状态视为当前层的输入.就像下面这样(令我困惑的是解码器部分):

编码器 - 解码

但是我已经阅读了Keras文档并且没有找到任何实现它的功能.

我可以通过Keras实现这种结构吗?怎么样?

Was*_*mad 6

您展示的结构是一个自定义结构.因此,Keras没有提供任何类或包装来直接构建这样的结构.不过,你可以建立这种结构的Keras.

因此,看起来你需要向后方向的LSTM模型.我不明白其他部分可能看起来像将前一句嵌入作为输入结合到LSTM单元的下一个时间步输入.

我宁愿鼓励您首先使用LSTM进行简单的语言建模.然后,您可以稍后调整架构以构建图中所示的架构.

例:


Meh*_*hdi 2

您要求的是自动编码器,您可以在 Keras 中找到类似的结构。

But there are certain details that you should figure it out on your own. Including the padding strategy and preprocessing your input and output data. Your input cannot get dynamic input size, so you need to have a fixed length for input and outputs. I don't know what do you mean by arrows who join in one circle but I guess you can take a look at Merge layer in Keras (basically adding, concatenating, and etc.)

You probably need 4 sequential model and one final model that represent the combined structure.

One more thing, the decoder setup of LSTM (The Language Model) is not dynamic in design. In your model definition, you basically introduce a fixed inputs and outputs for it. Then you prepare the training correctly, so you don't need anything dynamic. Then during the test, you can predict each decoded word in a loop by running the model once predict the next output step and run it again for next time step and so on.