1) sequence-to-sequence 형태
import tensorflow as tf
import numpy as np
X = []
Y = []
for i in range(6):
lst = list(range(i, i+4))
X.append(list(map(lambda c: [c/10], lst)))
Y.append((i+4)/10)
X = np.array(X)
Y = np.array(Y)
input_shape=[4, 1]
→ timesteps = 4, input_dim = 1units
: SimpleRNN에 존재하는 뉴련의 수return_sequences
는 출력으로 시퀀스 전체를 출력할지 여부model = tf.keras.Sequential([
tf.keras.layers.SimpleRNN(units=10, return_sequences=False, input_shape=[4, 1]),
tf.keras.layers.Dense(1)
])
model.compile(optimizer='adam', loss='mse')
model.summary()
model.fit(X, Y, epochs=100, verbose=0)
model.predict(np.array([[[0.6], [0.7], [0.8], [0.9]]])) # array([[0.8049002]], dtype=float32) 좋지 않다
model = tf.keras.Sequential([
tf.keras.layers.SimpleRNN(units=10, return_sequences=True, input_shape=[4, 1]),
tf.keras.layers.SimpleRNN(units=10, return_sequences=True, input_shape=[4, 1]),
tf.keras.layers.SimpleRNN(units=10, return_sequences=True, input_shape=[4, 1]),
tf.keras.layers.SimpleRNN(units=10, return_sequences=False, input_shape=[4, 1]),
tf.keras.layers.Dense(1)
])
model.compile(optimizer='adam', loss='mse')
model.summary()
model.fit(X, Y, epochs=100, verbose=1)
model.predict(np.array([[[0.6], [0.7], [0.8], [0.9]]])) #array([[0.9570675]], dtype=float32)
Reference
1) 제로베이스 데이터스쿨 강의자료
2) https://wikidocs.net/24996
3) https://ronak-k-bhatia.medium.com/a-primer-on-current-past-deep-learning-methods-for-nlp-c399fe28291d