pythongensim

Gensim unable to load word2vec models


I trained a word2vec model using gensim on my local machine and uploaded all files to AWS. I am able to load the model on my local machine but loading on AWS gives

FileNotFoundError: [Errno 2] No such file or directory: 's3://saltsagemaker/models/bilstm_models/word2vec/word2vec_model.wv.vectors.npy'

This works 👇🏻

# LOCAL MACHINE
from gensim.models import Phrases, Word2Vec
WV_MODEL = 'model_train_script/models/bilstm_models/word2vec/word2vec_model'
wv_model = Word2Vec.load(WV_MODEL)

This doesnt works 👇🏻

# AWS CODE
from gensim.models import Phrases, Word2Vec
WV_MODEL = 's3://saltsagemaker/models/bilstm_models/word2vec/word2vec_model'
wv_model = Word2Vec.load(WV_MODEL)

above code gives the following

FileNotFoundError: [Errno 2] No such file or directory: 's3://saltsagemaker/models/bilstm_models/word2vec/word2vec_model.wv.vectors.npy'

Files uploaded on local machine enter image description here

Files uploaded on AWS enter image description here


Solution

  • The numpy code on which Gensim relies to load subsidiary files (like your word2vec_model.wv.vectors.npy) doesn't support remote S3 paths like 's3://saltsagemaker/models/bilstm_models/word2vec/word2vec_model.wv.vectors.npy'. So, it's interpreting it as if it were a local path – & finding nothing.

    You could: