Search code examples
pythonpytorchchatbot

Load the ,trained model save, in pytorch for chatbots


I ran the code of this tutorial (link) and after a while learning the model was completed and I chatted with the trained model. After exit the program, in the save directory next to the program file, 8 files with a tar extension were created. I guess they are trained model saved files, what should I do to load those files and reuse them?


Solution

  • In "Run the Model", they describe what you should do. More specifically, there is this code in their snippet:

    # Set checkpoint to load from; set to None if starting from scratch
    loadFilename = None
    checkpoint_iter = 4000
    #loadFilename = os.path.join(save_dir, model_name, corpus_name,
    #                            '{}-{}_{}'.format(encoder_n_layers, decoder_n_layers, hidden_size),
    #                            '{}_checkpoint.tar'.format(checkpoint_iter))
    

    And you basically need to uncomment the #loadFilename and set the checkpoint_iter to the iteration you want. After that, you can skip the training part, because you already ran it, and run the evaluation code again.