I am training word2vec model in gensim using the sentences in a csv file as follows:
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())
I get the following result: (['b', 'u', 'm', 'h', 'e', 'n', 'r', 'v', 'i', 'a', 't', 's', 'k', 'w', 'o', 'l'])
The result I am get is not words but the characters. Where is the program going wrong?