gensim中word2vec和其他一些向量的使用

本文通过代码展示了在gensim库中使用word2vec进行词向量训练的过程,并详细解释了相关参数。同时,提到了word2vec模型的其他用途,以及在加载自定义.txt文件时需要注意的第一行内容,该行包含单词数和维度信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

直接上代码吧,word2vec

# test
from gensim.models.word2vec import Word2Vec
txt_file = open('data.txt')
sentences = []
line = txt_file.readline()
while line:
    sentence = line.split(' ')
    sentences.append(sentence)
    line = txt_file.readline()
model = Word2Vec(sentences, size=100, window=5, min_count=5, workers=1)
model.save('model_word2vec.model')
model_use = Word2Vec.load('model_word2vec.model')
xx = model_use.wv.vocab
# print(model_use.wv.vocab)
print('hel')
print(model_use.most_similar('nice'))
print(model_use.wv.similarity('nice', 'great'))

各种参数详解:

https://www.cnblogs.com/pinard/p/7278324.html

模型的一些其他使用:

https://blog.youkuaiyun.com/qq_19707521/article/details/79169826

自己在使用中:

from gensim.models import W
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值