我正在使用一個CSV文件中的句子如下訓練word2vec模型gensim:Gensim word2vec在線培訓
import string
import gensim
import csv
import nltk
path = '/home/neel/Desktop/csci544_proj/test/sample.csv'
translator = str.maketrans({key: None for key in string.punctuation})
class gen(object):
def __init__(self, path):
self.path = path
def __iter__(self):
with open(path) as infile:
reader = csv.reader(infile)
for row in reader:
rev = row[4]
l = nltk.sent_tokenize(rev)
for sent in l:
sent = sent.translate(translator)
yield sent.lower().split()
sentences = [path]
for p in gen(path):
model = gensim.models.Word2Vec(p, min_count=1, iter=1)
print(model.vocab.keys())
我得到以下結果: ([ 'B', 'U',「M ','h','e','n','r','v','i','a','t','s','k','w','o', 'l'])
我得到的結果不是單詞而是字符。程序出錯了?
的可能的複製[更新gensim word2vec模型(http://stackoverflow.com/questions/22121028/update-gensim-word2vec-model ) – ksindi