Basically, what I want to do is to convert numpy array (in my case weights of Word2vec) into torch weights.
Here is my code:
from gensim.models import KeyedVectors
import torch
model_path = "GoogleNews-vectors-negative300.bin.gz"
word2vec_model = KeyedVectors.load_word2vec_format(model_path, binary=True)
# weights
word_embeddings_weights = []
# select only words, which are in vocabulary
for word in vocab_dict:
if word2vec_model.has_index_for(word):
word_embeddings_weights.append(word2vec_model.get_vector(word))
else:
word_embeddings_weights.append(np.random.uniform(low=-1.0, high=1.0, size=300))
word_embeddings_weights = np.array(word_embeddings_weights)
weights_embed = torch.FloatTensor(word_embeddings_weights)
after the execution of the last line kernel dies:
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.
But strangely, if I convert the whole weights of word2vec into torch, kernel works fine:
weights = torch.FloatTensor(word2vec_model.vectors)
But with much smaller numpy array jupyter notebook crashes. What is the reason of kernel crach and how can I fix it?