How to save RoBERTA sequence classifier model

After finishing the training phase, I want to save the RoBERTa classifier model for later evaluation purpose.

I am getting this error.

AttributeError Traceback (most recent call last)
1 out_model = “src_classifier_final_ICWSM_10e”
----> 2 src_classifier.save_model(f’models/{out_model}_final’)

~/.local/lib/python3.8/site-packages/torch/nn/modules/ in getattr(self, name)
945 if name in modules:
946 return modules[name]
→ 947 raise AttributeError("’{}’ object has no attribute ‘{}’".format(
948 type(self).name, name))

AttributeError: ‘RobertaForSequenceClassification’ object has no attribute ‘save_model’

I’m not sure where you have gotten that save_model method but Transformers model don’t have it. They use save_pretrained.

1 Like

how can load the saved model?

You can use the from_pretrained method.

You can find more about model sharing in Model sharing and uploading — transformers 4.7.0 documentation.