Python - вектор кодирования данных в слово - PullRequest
0 голосов
/ 12 ноября 2018

У меня есть код, который преобразует слово в вектор. Ниже мой код:

# 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")

Выход

Vector for 'earth' is: 

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

Можно ли кодировать из массива векторов в слова? Если да, как я буду реализовывать это в Python?

1 Ответ

0 голосов
/ 12 ноября 2018

Вы можете использовать метод Similar_by_vector () из вашей модели, чтобы найти N наиболее популярных слов по вектору. Надеюсь, это поможет.

...