0
点赞
收藏
分享

微信扫一扫

Python Wordvector (二)

洛茄 2023-01-13 阅读 154


​​Python Wordvector (二)​​



import jieba
import pandas as pd
txt = open("hlm.txt", "r", encoding="gb18030").read()

from gensim.models.word2vec import Word2Vec

sentences =txt


tt=txt
jieba.enable_parallel(2)
s1 = [x for x in jieba.cut_for_search(tt) if len(x) >= 2]
jieba.disable_parallel()
from gensim.test.utils import common_texts, get_tmpfile
from gensim.models import Word2Vec

path = get_tmpfile("word2vec.model")

model = Word2Vec(s1, size=100, window=5, min_count=1, workers=4)
model.save("word2vec.model")

model = Word2Vec.load("word2vec.model")
'''
model.train([["hello", "world"]], total_examples=1, epochs=1)
'''
#(0, 2)

vector = model.wv['礼义'] # numpy vector of a word

print('#'*100)

print(vector)







举报

相关推荐

python基础(二)

python函数二

python selenium (二)

Python 模块(二)

Python基础(二)

Python基础(二)

0 条评论