생성된 네트워크를 활용하여 모델을 훈련시킵니다(RNNCell과 동일한 코드이지만 결과를 확인하고자 또 한 번 실행합니다).
코드 7-10 모델 훈련
import time
units = 64
epochs = 4
t0 = time.time()
model = RNN_Build(units)
model.compile(optimizer=tf.keras.optimizers.Adam(0.001),
loss=tf.losses.BinaryCrossentropy(),
metrics=['accuracy'],
experimental_run_tf_function=False)
model.fit(train_data, epochs=epochs, validation_data=test_data, validation_freq=2)
다음은 모델 훈련을 실행시킨 결과입니다.
Epoch 1/4
195/195 [==============================] - 12s 61ms/step - loss: 0.5376 - accuracy: 0.7124
Epoch 2/4
195/195 [==============================] - 15s 79ms/step - loss: 0.3508 - accuracy: 0.8511 - val_loss: 0.4648 - val_accuracy: 0.8200
Epoch 3/4
195/195 [==============================] - 12s 63ms/step - loss: 0.2842 - accuracy: 0.8864
Epoch 4/4
195/195 [==============================] - 16s 81ms/step - loss: 0.2370 - accuracy: 0.9079 - val_loss: 0.4664 - val_accuracy: 0.8226
<tensorflow.python.keras.callbacks.History at 0x21fb440f780>