Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
320 views
in Technique[技术] by (71.8m points)

machine learning - return_sequences in LSTM

In Keras, model.add(LTSM(units=xx, return_sequences = yy, input_shape=zz), When setting the return_sequences to true, does it mean to have/enable the arrow circled in blue, and not have/disable the arrow circled in red? and vice versa when return_sequences set to false? Note the picture comes from this page: https://www.analyticsvidhya.com/blog/2017/12/fundamentals-of-deep-learning-introduction-to-lstm/ under '4. Architecture of LSTMs'enter image description here

question from:https://stackoverflow.com/questions/65648957/return-sequences-in-lstm

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

First, the circle in blue is the essence of LSTM and it will never be disabled or you will not have a rnn/lstm at all. That arrow means that whatever the value you get from the last rnn/lstm cell, you will pass it to the next rnn/lstm cell and it will be processed together with the next input. The only difference between rnn and lstm is just that a simple rnn does not have that blue-circled arrow, only the black arrow below while lstm has that arrow as a gate for short/long term memory.

Second, for return_sequences, it is typically used for stacked rnn/lstm, meaning that you stack one layer of rnn/lstm on top of another layer VERTICALLY, not horizontally. Horizontal rnn/lstm cells represent processing across time, while vertical rnn/lsm cells means stacking one layer across another layer.

When you set it to false, it means that only the last cell (horizontally) will have that red_circled arrow while all other cells (in the same layer) will have that red_circled arrow disabled so you will only pass one piece of information from all that horizontal layer (that is the information passed by the last cell in that layer).

Conversely, when you set it to true, all cells from that horizontal layer will have that red-circled arrow abled, and will pass information to the layer stacked top of it. It means that if you want to stack one rnn/lstm layers on top of another, you need to set it to true.

Lastly, for more information you can refer to this book. It has great explanation for this return_sequences option: https://www.oreilly.com/library/view/hands-on-machine-learning/9781492032632/


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...