Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
LWserenic opened this issue Jul 8, 2024 · 3 comments

Comments

@LWserenic
Copy link

LWserenic commented Jul 8, 2024

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
Copy link
Owner

I think you should degrade your gensim version

@LWserenic
Copy link
Author

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

@GanjinZero
Copy link
Owner

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

I think it is same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants