Can I use next level output as the current Keras input layer?

In a text generation mission, we usually use the last output of the model as the current input to generate the next word. More generalized, I want to reach a neural network that considers the hidden status of the next layer as the current layer. Like the following (which confuses me part of the decoder):

encoder-decoder

But I read the Keras document and did not find any features to achieve it.

Can I reach this Keras structure? How?

+5
source share
2 answers

What you ask are auto-coders, you can find similar structures in Keras.

But there are some details that you must understand on your own. Including a filling strategy and preprocessing of your input and output. Your input cannot get dynamic input size, so you need to have a fixed length for input and output. I don’t know what you mean by arrows that join the same circle, but I think you can take a look at Merge Layer in Keras (basically adding, concatenating, etc.)

You will probably need 4 sequential and one final model , which are a combined structure.

One more thing: installing an LSTM decoder (language model) is not dynamic in design. In defining a model, you basically enter fixed inputs and outputs for it. Then you prepare the training correctly, so you do not need anything dynamic. Then, during the test, you can predict each decoded word in a loop by running the model after predicting the next output step and running it again for the next time step and so on.

+2
source

The structure you showed is a custom structure. Therefore, Keras does not provide any class or wrapper for the direct assembly of such a structure. But YES , you can build such a structure in Keras.

So it looks like you need the LSTM model in the opposite direction. I did not understand the other part, which is probably similar to including the previous attachment of sentences as input for the next input of the time step of the LSTM block.

I rather recommend that you first work with simple language modeling using LSTM. You can then tweak the architecture later to build the architecture shown.

Example:

+6
source

Source: https://habr.com/ru/post/1265053/


All Articles