You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
619 B
28 lines
619 B
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
@Time : 2023/3/14 19:01
|
|
@Author :
|
|
@FileName:
|
|
@Software:
|
|
@Describe:
|
|
"""
|
|
from gensim.models.word2vec import LineSentence
|
|
import numpy as np
|
|
from tqdm import tqdm
|
|
|
|
path = "word2vec_model/word2vec.txt"
|
|
def iter_word(word, txt_path):
|
|
"""迭代器方法获取词向量"""
|
|
vec = 0
|
|
iter1 = LineSentence(open(txt_path, 'r', encoding='utf-8'))
|
|
for i,v in tqdm(enumerate(iter1)):
|
|
if i == 0:
|
|
continue
|
|
if word == v[:1]:
|
|
vec = np.array([float(j) for j in v[1:]])
|
|
break
|
|
return vec
|
|
|
|
word = "公共"
|
|
print(iter_word(word,path))
|