모델을 훈련시킵니다.
코드 10-37 모델 훈련
EPOCHS = 10
for epoch in range(EPOCHS):
start = time.time()
enc_hidden = encoder.initialize_hidden_state()
total_loss = 0
for (batch, (inp, targ)) in enumerate(dataset.take(steps_per_epoch)):
batch_loss = train_step(inp, targ, enc_hidden)
total_loss += batch_loss
if batch % 100 == 0:
print('Epoch {} Batch {} Loss {:.4f}'.format(epoch+1,
batch,
batch_loss.numpy()))
if (epoch+1) % 2 == 0: ------ 2 에포크마다 모델을 체크포인트에 저장
checkpoint.save(file_prefix=checkpoint_prefix)
print('Epoch {} Loss {:.4f}'.format(epoch+1,
total_loss/steps_per_epoch))
print('Time taken for 1 epoch {} sec\n'.format(time.time()-start))