Word2Vec使用字符代替单词

问题描述 投票:0回答:1

我已经标记了我的字符串,并在其中创建了一个Pandas列,如果我打印列df['word_splits'],它看起来像这样。

0    ['explanation', 'why', 'the', 'edits', 'made',...
1    ["d'aww", '!', 'he', 'matches', 'this', 'backg...
2    ['hey', 'man', ',', "i'm", 'really', 'not', 't...
3    ['more', 'i', "can't", 'make', 'any', 'real', ...
4    ['you', ',', 'sir', ',', 'are', 'my', 'hero', ...
Name: word_splits, dtype: object

接下来,我正在运行Word2Vec

model = gensim.models.Word2Vec(sentences=df["word_splits"])

当我打印出词汇时,使用

words = list(model.wv.vocab)
print(words)

我得到的是字符,而不是一长串单词(词汇)。

['[', "'", 'e', 'x', 'p', 'l', 'a', 'n', 't', 'i', 'o', ',', ' ', 'w', 'h', 'y', 'd', 's', 'm', 'u', 'r', 'c', 'f', 'v', '?', '"', 'j', 'g', 'k', '.', ']', '!', 'b', '-', 'q', 'z']

不确定我在做什么错。

python pandas nlp gensim
1个回答
0
投票

潜在问题:句子应该是列表的列表。

潜在的解决方案:

#Invoke library
from gensim.models import Word2Vec

#Change the sentences into a list of lists.
s = [['explanation', 'why', 'the', 'edits', 'made'], ['hey', 'man', ',', "i'm", 'really', 'not']]

#Build model
model = Word2Vec(s, size=10, window=5, min_count=1, workers=4)

#Inspect the vocabulary
list(model.wv.vocab)

#['made', 'explanation', 'hey', ',', 'why', 'edits', 'not', "i'm", 'man', 'the', 'really']
© www.soinside.com 2019 - 2024. All rights reserved.