allanj / pytorch_neural_crf

Pytorch implementation of LSTM/BERT-CRF for named entity recognition
359 stars 62 forks source link

AttributeError: 'str' object has no attribute 'size' #22

Closed DICPZhou closed 3 years ago

DICPZhou commented 3 years ago

when I run the command "python transformers_trainer.py --device=cuda:0 --dataset=conll2003_sample --model_folder=saved_models --embedder_type=bert-base-cased" Error output is : AttributeError: 'str' object has no attribute 'size' is it the version of transformers? The version of transformers I used is 4.0.0

allanj commented 3 years ago

Can you paste the complete error stack trace here?

allanj commented 3 years ago

I found out the issue, if you are using the recent version of transformers, you can do the following or simply git pull

Our latest commit c399962 solve this issue. What I did was replacing

self.model = context_models[transformer_model_name]["model"].from_pretrained(transformer_model_name,
                                                              output_hidden_states= output_hidden_states)

with

self.model = context_models[transformer_model_name]["model"].from_pretrained(transformer_model_name,
                                          output_hidden_states= output_hidden_states,
                                             return_dict=False)

Because the recent transformer package will return a dictionary by default.