[TensorFlow] RNN 2

RNN layer에는 중요한 두가지 option이 있습니다. return_sequencesreturn_state입니다. 각각 True 또는 False로 setting할 수 있습니다. 아무것도 안쓰면 기본 setting은 모두 False입니다.

There are two important options for the RNN layer. These are return_sequences and return_state. Each can be set to True or False. If nothing is used, the default setting is all False.

h_dim = 10rnn_1 = tf.keras.layers.SimpleRNN(h_dim, return_sequences=False, return_state=False)rnn_2 = tf.keras.layers.SimpleRNN(h_dim, return_sequences=False, return_state=True)rnn_3 = tf.keras.layers.SimpleRNN(h_dim, return_sequences=True, return_state=False)rnn_4 = tf.keras.layers.SimpleRNN(h_dim, return_sequences=True, return_state=True)

rnn_1은 h_n (output)만 돌려줍니다.

rnn_2는 h_n (output)과 또 다시 h_n(state)을 돌려줍니다.

rnn_3는 h_1부터 h_n (sequences, 모든 state)까지 모두 돌려줍니다.

rnn_4는 h_1부터 h_n (sequences, 모든 state)과 h_n(state)을 돌려줍니다.

rnn_1 only returns h_n (output).
rnn_2 returns h_n (output) and again h_n (state).
rnn_3 returns everything from h_1 to h_n (sequences, all states).
rnn_4 returns h_n (sequences, all states) and h_n (state) from h_1.

헷갈리는 이유는 동일한 것을 어떤 때는 output이라고 부르고, 어떤 때는 state라고 부르기 때문입니다.

SimpleRNN과 GRU에서는 output과 state가 같습니다. 다만, LSTM은 state가 두가지 종류가 있어서, 그 중 하나만을 output이라고 부릅니다.

The confusing reason is that the same thing is sometimes called the output and sometimes the state.

In SimpleRNN and GRU, output and state are the same. However, LSTM has two types of states, so only one of them is called output.




Ydobon is nobody.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium


Tree-based Machine Learning Models for Handling Imbalanced Datasets

The 10th IEEE International Workshop on the Analysis and Modeling of Faces and Gestures

Curious Case of Hyperbolic Embeddings (Part - I )

Kidney Disease Prediction Using Machine Learning

How to Make Your First Contribution to Saving Privacy?

The Purpose Of Activation Functions

Step 7: Semester recap

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
A Ydobon

A Ydobon

Ydobon is nobody.

More from Medium

Malaria Detection using Deep Learning

Lobe: Machine learning Model with no-code

Objective Metrics and Gradient Descent Algorithms for Adversarial Examples in Machine Learning…

Can phones successfully replace one of our natural senses?

myfinder response to image analysis, a swan swimming in a lake