0

I have a code that converts word to vector. Below is my code:

# word_to_vec_demo.py

from gensim.models import word2vec
import logging

logging.basicConfig(format='%(asctime)s : \
%(levelname)s : %(message)s', level=logging.INFO)

sentences = [['In', 'the', 'beginning', 'Abba','Yahweh', 'created', 'the',
'heaven', 'and', 'the', 'earth.', 'And', 'the', 'earth', 'was',
'without', 'form,', 'and', 'void;', 'and', 'darkness', 'was',
'upon', 'the', 'face', 'of', 'the', 'deep.', 'And', 'the',
'Spirit', 'of', 'Yahweh', 'moved', 'upon', 'the', 'face',  'of',
'the', 'waters.']]

model = word2vec.Word2Vec(sentences, size=10, min_count=1)

print("Vector for \'earth\' is: \n")
print(model.wv['earth'])

print("\nEnd demo")

The output is

Vector for 'earth' is: 

[-0.00402722  0.0034133   0.01583795  0.01997946  0.04112177  0.00291858
-0.03854967  0.01581967 -0.02399057  0.00539708]

Is it possible to encode from array of vector to words? If yes, how will I implement it in Python?

alyssaeliyah
  • 2,214
  • 6
  • 33
  • 80

1 Answers1

2

You can use the similar_by_vector() method from your model to find the top-N most similar words by vector. Hope this helps.

yatu
  • 86,083
  • 12
  • 84
  • 139
  • Thanks , I have one additional question, can I use wordtovector to train my neural network? See my https://stackoverflow.com/questions/52982719/data-encoding-for-training-in-neural-network – alyssaeliyah Nov 12 '18 at 15:27
  • 1
    Yes. If you want to train a deep learning model with text you must feed it with some word embedding or encoding of the input data. – yatu Nov 12 '18 at 15:55
  • Please consider setting the answer as correct. Thank you. – yatu Nov 13 '18 at 08:58