HHousen / TransformerSum

Models to perform neural summarization (extractive and abstractive) using machine learning transformers and a tool to convert abstractive summarization datasets to the extractive task.
https://transformersum.rtfd.io
GNU General Public License v3.0
429 stars 58 forks source link

RuntimeError: Error(s) in loading state_dict for ExtractiveSummarizer? #54

Closed Alla-Abdella closed 3 years ago

Alla-Abdella commented 3 years ago

I'm getting this error when I give it the model checkpoint.

Code: model = ExtractiveSummarizer.load_from_checkpoint(path)

error: 2 frames /usr/local/lib/python3.7/dist-packages/torch/nn/modules/module.py in load_state_dict(self, state_dict, strict) 1405 if len(error_msgs) > 0: 1406 raise RuntimeError('Error(s) in loading state_dict for {}:\n\t{}'.format( -> 1407 self.class.name, "\n\t".join(error_msgs))) 1408 return _IncompatibleKeys(missing_keys, unexpected_keys) 1409

RuntimeError: Error(s) in loading state_dict for ExtractiveSummarizer: Missing key(s) in state_dict: "word_embedding_model.embeddings.position_ids".

HHousen commented 3 years ago

When using the main.py script, you can specify the --no_strict argument. That should fix it. When using main.py and encountering this error, you should be presented with this message explaining the solution. Since you're not using main.py, try setting strict=False like so: model = ExtractiveSummarizer.load_from_checkpoint("../distilroberta-base-ext-sum.ckpt", strict=False).

Alla-Abdella commented 3 years ago

Thank you very much HHousen, the code works for me.