0

我是 python 语言、自然语言处理、深度学习、神经网络的初学者。我想执行一个程序,通过在 python 中使用 word2vec 将文本文件转换为矢量。有人请帮助我

import math 
import nltk file = "/home/stephy/Demo/textfile.txt" 
import numpy as np 

def loadGloveModel(gloveFile): 
    with open(gloveFile, encoding="utf8" ) as f: 
        content = f.readlines() 
    model = {} for line in content: 
        splitLine = line.split() 
        word = splitLine[0] 
    embedding = np.array([float(val) for val in splitLine[1:]])  
    model[word] = embedding 
    print ("Done.",len(model)," words loaded!") 
    return model 

model= loadGloveModel(file) 
print (model['file']) 
4

0 回答 0