Search code examples
allennlp

Save model after each epoch - AllenNLP


Is there a parameter that I can set in the config file (maybe for the trainer?) that would save the model (archive) after each epoch or after a specific number of steps? I'm using seq2seq dataloader and "composed_seq2seq" as my model. This is how my trainer looks like currently:

"trainer": {
"num_epochs": 50,
"cuda_device": 0,
"optimizer": {
  "type": "adamw",
  "lr": 0.0005
}

Solution

  • Can you explain a little more about what you're trying to do with a model from every epoch/some number of steps? I think it already archives the model every time it gets a new best score, so I'm wondering what you want to do that can't be accomplished with that.

    Edit:

    It looks like AllenNLP already saves a model every epoch, but it only keeps a maximum of 2 by default. I believe you can change that by adding a checkpointer to your training config, e.g.:

      "trainer": {
        "checkpointer": {
          "num_serialized_models_to_keep": num_epochs
        },
      }