Python – 数据编码向量到词

我有一段将词转换为向量的代码。以下是我的代码:

# word_to_vec_demo.pyfrom gensim.models import word2vecimport logginglogging.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中实现?


回答:

你可以使用模型中的similar_by_vector()方法来查找与向量最相似的前N个词。希望这对你有帮助。

Related Posts

为什么我们在K-means聚类方法中使用kmeans.fit函数?

我在一个视频中使用K-means聚类技术,但我不明白为…

如何获取Keras中ImageDataGenerator的.flow_from_directory函数扫描的类名?

我想制作一个用户友好的GUI图像分类器,用户只需指向数…

如何查看每个词的tf-idf得分

我试图了解文档中每个词的tf-idf得分。然而,它只返…

如何修复 ‘ValueError: Found input variables with inconsistent numbers of samples: [32979, 21602]’?

我在制作一个用于情感分析的逻辑回归模型时遇到了这个问题…

如何向神经网络输入两个不同大小的输入?

我想向神经网络输入两个数据集。第一个数据集(元素)具有…

逻辑回归与机器学习有何关联

我们正在开会讨论聘请一位我们信任的顾问来做机器学习。一…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注