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

AttributeError: can't set attribute when using pre-trained extractive summariser #46

Closed bmanczak closed 3 years ago

bmanczak commented 3 years ago

Hi,

Great work on the repo. I followed the Getting Started page and tried to run mobilebert-uncased-ext-sum model. Here is a simple code snippet I used:

import os
import sys

sys.path.insert(0, os.path.abspath("./src"))
from extractive import ExtractiveSummarizer

model = ExtractiveSummarizer.load_from_checkpoint("mobilebert-uncased-ext-sum.ckpt")

text_to_summarize = "my long text."

model.predict(text_to_summarize) 

However, I get the following traceback

Traceback (most recent call last):
  File "/Users/blazejmanczak/Desktop/Projects/Artemos/ext_summarization/transformersum/testing_extractive.py", line 8, in <module>
    model = ExtractiveSummarizer.load_from_checkpoint("mobilebert-uncased-ext-sum.ckpt")
  File "/opt/miniconda3/envs/transformersum/lib/python3.9/site-packages/pytorch_lightning/core/saving.py", line 157, in load_from_checkpoint
    model = cls._load_model_state(checkpoint, strict=strict, **kwargs)
  File "/opt/miniconda3/envs/transformersum/lib/python3.9/site-packages/pytorch_lightning/core/saving.py", line 199, in _load_model_state
    model = cls(**_cls_kwargs)
  File "/Users/blazejmanczak/Desktop/Projects/Artemos/ext_summarization/transformersum/src/extractive.py", line 109, in __init__
    self.hparams = hparams
  File "/opt/miniconda3/envs/transformersum/lib/python3.9/site-packages/torch/nn/modules/module.py", line 995, in __setattr__
    object.__setattr__(self, name, value)
AttributeError: can't set attribute

Any tips on how to solve that?

HHousen commented 3 years ago

I've narrowed the problem down to this commit in pytorch-lightning https://github.com/PyTorchLightning/pytorch-lightning/pull/6207. Try running after installing the previous version of pytorch-lightning with pip install -U pytorch_lightning==1.2.10. I'm working on fixing the code to work with the latest version of pytorch-lightning.

HHousen commented 3 years ago

For reference, I found an open issue with this exact problem: https://github.com/PyTorchLightning/pytorch-lightning/issues/7443#issuecomment-836983666

HHousen commented 3 years ago

By the way, you're going to need to set strict=False when calling load_from_checkpoint with that model.

HHousen commented 3 years ago

Solved in e36e0331f34427973403b4c340cc364fcf9fe26b

bmanczak commented 3 years ago

Thank you for a swift patch!

To make it work I had to do one small thing: In src/extractive.py change nlp.add_pipe(sentencizer) to nlp.add_pipe("sentencizer").