I have trained a model, how do I load it up?

Hi, I have managed to train a model using trainer. I evaluated some results whilst the model was still on the disk using ‘trainer.predict()’. I then used trainer.save_model() and now want to load it up for usage again. By saving, I got three files in my drive;

  1. pytorch_model.bin
  2. config.json
  3. training_args.json

I am assuming the model is pytorch_model.bin but I am unsure how do I load it up? I trained a classification model so do I call again;

model = AutoModelForSequenceClassification.from_pretrained(**filepath**, 
                                                           output_attentions = False, #
                                                           output_hidden_states = False

where filepath is the path to pytorch_model.bin? do I then call again a trainer and send the model to that to again use trainer.predict() for new predictions?

You can do it in pytorch or tf like you would with any other model, or you can use Pipelines — transformers 4.3.0 documentation

1 Like

Thank you, just to double check, would it be like this (Im most unsure about how if this is how we call the model);

pipeline('sentiment-analysis', model='some_file_path/pytorch_model.bin',

Looks good to me, if sentiment-analysis is what you want to do.