8. Train the network using the training set's data. Use the validation sets to measure performance. To do this, save the loss and the accuracy for both the training and validation sets in each epoch.
2. Change the definition of the **transform** variable so that it includes, in addition to normalizing and converting the data into tensors, the following transformations:
2. Change the definition of the **transform** variable so that it includes, in addition to normalizing and converting the data into tensors, the following transformations:
6. This output consists of a vector of the target vocabulary’s length, with a prediction for each word within the vocabulary. We take the **argmax** function to identify the actual word that is predicted by the model.
12. On every iteration, we also make sure we print our progress so far, keeping track of how many iterations we have completed and what our loss was for each epoch:
如果迭代%print_every == 0:
如果迭代% print_every == 0:
print_loss_avg = print_loss / print_every
print(“迭代:{};完成百分比:{:.1f}%; \
print(“迭代:{};完成百分比:{:.1f}% ; \
平均损失:{:. 4f}“。format(迭代,
...
...
@@ -891,7 +891,7 @@ corpus_name = "movie_corpus"
13. For the sake of completion, we also need to save our model state after every few epochs. This allows us to revisit any historical models we have trained; for example, if our model were to begin overfitting, we could revert back to an earlier iteration: