# How to correctly pass Word2Vec vectors as input to an LSTM

I am trying to build a text classifier using lstm which, in its first layer, has weights get by a Word2Vecmodel.

In order to build a matrix containing the indexes of each word for each sentence, I have tried: (as mentioned here)

X_tr_word2vec = np.array(X_tr_word2vec)
y_tr_word2vec = np.array(y_tr_word2vec)

train_x = np.zeros([X_tr_word2vec.shape[0], max_sentence_length], dtype=np.int32)
train_y = np.zeros([y_tr_word2vec.shape[0]], dtype=np.int32)

for i, sentence in enumerate(X_tr_word2vec):
for j, word in enumerate(sentence[:-1]):
train_x[i,j] = model_word2vec.wv.vocab[word].index


but, when I run the code, I get this error:KeyError: 'enquiringly', what does it mean? I suppose that it is about a wrong train_xdimension.

Update:

I have trained Word2Vec model before, with the entire training set:

model_word2vec = models.Word2Vec(X_tr_word2vec, size=150, window=9)


That means your word 'enquiringly' is not in your word embedding vocabulary vocab.
For out-of-vocabulary(OOV) words, there is usually a embedding vector dedicated to them. Try to find that special symbol in the vocab and use that corresponding embedding vector.