GanjinZero / ICD-MSMN

Code Synonyms Do Matter: Multiple Synonyms Matching Network for Automatic ICD Coding [ACL 2022]
https://arxiv.org/abs/2203.01515
50 stars 8 forks source link

AttributeError: 'Word2Vec' has no attribute '__getattr__'. Did you mean '__setattr__'? #15

Open LWserenic opened 4 months ago

LWserenic commented 4 months ago

Hello author @GanjinZero, first of all I am interested with your research and I'd like to implement it to MIMIC-IV dataset. I use gensim 4.3.2 and now I'm getting error as in title. The error show in line 449, or the load_embeddings function where there is a function new_W.append(model.__getattr__(id2word[i])). The complete error is shown below.

`During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/main.py", line 248, in main() File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/main.py", line 245, in main run(args) File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/main.py", line 55, in run model = generate_model(args, train_dataset).to(accelerator.device) File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/train_utils.py", line 206, in generate_model model = IcdModel(word_config, combine_config, File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/model/icd_model.py", line 39, in init self.encoder = TextEncoder(word_config, combine_config) File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/model/text_encoder.py", line 16, in init self.word_encoder = Word_Encoder(self.word_config) File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/model/word_encoder.py", line 21, in init W = torch.Tensor(load_embeddings(self.word_embedding_path)) File "/media/noel-hito/Main/JOBS/Serenic.ai/MSM-Network/ICD-MSMN/data_util.py", line 449, in load_embeddings new_W.append(model.getattr(id2word[i])) AttributeError: 'Word2Vec' object has no attribute ' getattr ' . Did you mean: ' setattr '?`

Hopefully you have an inkling as to why is this happen. Thank you.

GanjinZero commented 4 months ago

I think you should degrade your gensim version

LWserenic commented 4 months ago

What gensim did you use? Is it the same as using model.wv[id2word[i]] ?

GanjinZero commented 4 months ago

What gensim did you use? Is it the same as using model.wv[id2word[i]] ?

I think it is same.