我已经训练了翻译模型:
step % 1000 == 0
时,我会评估验证时的损失。完成训练后,我加载了模型,损失很大。
if step % 1000 ==0:
model.eval()
val_loss = eval(model,val_loader)
print("epoch:",epoch,"step:",step,"loss:",loss,"val_loss:",val_loss)
if val_loss.item() < best_loss:
best_loss = val_loss.item()
best_epoch = epoch
torch.save(model.state_dict(),'best_1.m')
当我完成训练后,损失约为0.665,但是当我加载相同的模型时,损失约为300。
model.load_state_dict(torch.load('best_1.m'))
model.eval()
val_loss = eval(model,val_loader)
print('val_loss:',val_loss)