bert-extractive-summarizer: Error when using custom BERT models.

When trying to use a custom model specifying the path, the class throws an error at the line: /summarizer/BertParent.py, line 41. The error is AttributeError: 'NoneType' object has no attribute 'from_pretrained'.

I think that the line:

base_model, base_tokenizer = self.MODELS.get(model, (None, None))

should become something like:

base_model, base_tokenizer = self.MODELS.get(model, (model, model))

when model specify the path to the custom bert model.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 2
  • Comments: 17 (9 by maintainers)

Most upvoted comments

You should be able to load a custom (Transformers based) model using the library. Here is an example from the readme, let me know if it you are still having issues.

from transformers import *

# Load model, model config and tokenizer via Transformers
custom_config = AutoConfig.from_pretrained('allenai/scibert_scivocab_uncased')
custom_config.output_hidden_states=True
custom_tokenizer = AutoTokenizer.from_pretrained('allenai/scibert_scivocab_uncased')
custom_model = AutoModel.from_pretrained('allenai/scibert_scivocab_uncased', config=custom_config)

from summarizer import Summarizer

body = 'Text body that you want to summarize with BERT'
body2 = 'Something else you want to summarize with BERT'
model = Summarizer(custom_model=custom_model, custom_tokenizer=custom_tokenizer)
model(body)
model(body2)

Whoops, looks like I fixed one part, but need to fix the summarizer contract. I will get to that this weekend.

I am having the same issue: I am trying to load trained model using: ext_model = Summarizer(model="../models/CNN_DailyMail_Extractive/bertext_cnndm_transformer.pt") I also tried to use ext_model = Summarizer(custom_model="../models/CNN_DailyMail_Extractive/bertext_cnndm_transformer.pt") However, I have the following error: File "/usr/local/lib/python3.6/dist-packages/summarizer/BertParent.py", line 38, in __init__ self.model = base_model.from_pretrained(model, output_hidden_states=True) AttributeError: 'NoneType' object has no attribute 'from_pretrained'

Sorry, I actually fixed this last night, and forgot to commit. I will update when I get home this evening.