February 2018
Intermediate to advanced
262 pages
6h 59m
English
We train the model for multiple epochs and validate it using the following code:
# Loop over epochs.best_val_loss = Noneepochs = 40for epoch in range(1, epochs+1): epoch_start_time = time.time() trainf() val_loss = evaluate(valid_iter) print('-' * 89) print('| end of epoch {:3d} | time: {:5.2f}s | valid loss {:5.2f} | ' 'valid ppl {:8.2f}'.format(epoch, (time.time() - epoch_start_time), val_loss, math.exp(val_loss))) print('-' * 89) if not best_val_loss or val_loss < best_val_loss: best_val_loss = val_loss else: # Anneal the learning rate if no improvement has been seen in the validation dataset. lr /= 4.0
The previous code is training the model for 40 epochs, and we start with a high-learning rate of 20 and reduce it further ...