[TensorFlow] RNN 2

A Ydobon
2 min readMay 26, 2021

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.

--

--