Skip to content

Instantly share code, notes, and snippets.

@susanli2016
Created September 25, 2018 03:24
Show Gist options
  • Save susanli2016/7d42db7f099eb81f62c17756952e4080 to your computer and use it in GitHub Desktop.
Save susanli2016/7d42db7f099eb81f62c17756952e4080 to your computer and use it in GitHub Desktop.
def get_vectors(model, corpus_size, vectors_size, vectors_type):
"""
Get vectors from trained doc2vec model
:param doc2vec_model: Trained Doc2Vec model
:param corpus_size: Size of the data
:param vectors_size: Size of the embedding vectors
:param vectors_type: Training or Testing vectors
:return: list of vectors
"""
vectors = np.zeros((corpus_size, vectors_size))
for i in range(0, corpus_size):
prefix = vectors_type + '_' + str(i)
vectors[i] = model.docvecs[prefix]
return vectors
train_vectors_dbow = get_vectors(model_dbow, len(X_train), 300, 'Train')
test_vectors_dbow = get_vectors(model_dbow, len(X_test), 300, 'Test')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment