delip / PyTorchNLPBook

Code and data accompanying Natural Language Processing with PyTorch published by O'Reilly Media https://amzn.to/3JUgR2L
Apache License 2.0
1.96k stars 799 forks source link

No early stopping implemented in Chapter 3 (yelp) #34

Open lisanka93 opened 2 years ago

lisanka93 commented 2 years ago

The early_stopping_best_val never gets updated so the loss is ALWAYS smaller and early stopping never happens this line of code is missing in the if-else statement in update_train_stage function:

train_state['early_stopping_best_val'] = loss_t

Rucious-Aladdin commented 3 months ago

please modify the syntax inside the update_train_state function as follows and ensure that the minimum value is initialized.

def update_train_state(args, model, train_state): """ codes... """     if loss_t < train_state['early_stopping_best_val']:          torch.save(model.state_dict(), train_state['model_filename'])          train_state['early_stopping_best_val'] = loss_t