This works:
train_now = “nyes”
if train_now == “yes”:
hidden_size = 256
print(“input_lang.n_words”,input_lang.n_words)
print(“input_lang.n_words”,input_lang.n_words)
encoder1 = EncoderRNN(input_lang.n_words, hidden_size).to(device)
attn_decoder1 = AttnDecoderRNN(hidden_size, output_lang.n_words, dropout_p=0.1).to(device)
trainIters(encoder1, attn_decoder1, 500, print_every=50)
evaluateRandomly(encoder1, attn_decoder1)
torch.save(encoder1, “encoder1.pt”)
torch.save(attn_decoder1, “attn_decoder1.pt”)
else:
encoder1 = torch.load(“encoder1.pt”)
encoder1.eval()
attn_decoder1 = torch.load(“attn_decoder1.pt”)
attn_decoder1.eval()
#load models
evaluateRandomly(encoder1, attn_decoder1)
######################################################################