for epoch in range(1, epochs + 1):
epoch_start_time = time.time()
train()
val_loss = evaluate(model, val_data)
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),
After Change
// equal to the length of the vocab object.
//
ntokens = len(vocab.stoi) // the size of vocabulary
emsize = 200 // embedding dimension
nhid = 200 // the dimension of the feedforward network model in nn.TransformerEncoder
nlayers = 2 // the number of nn.TransformerEncoderLayer in nn.TransformerEncoder
nhead = 2 // the number of heads in the multiheadattention models
dropout = 0.2 // the dropout value
model = TransformerModel(ntokens, emsize, nhead, nhid, nlayers, dropout).to(device)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Run the model