【问题标题】:Word2Vec Giving Characters instead of WordsWord2Vec 给出字符而不是单词
【发布时间】:2020-05-06 00:22:50
【问题描述】:

我已经标记了我的字符串并用它们制作了一个 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】:

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

    可能的解决方案:

    #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']
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-13
      • 2015-08-15
      • 2019-01-02
      • 1970-01-01
      • 1970-01-01
      • 2010-12-12
      • 2021-11-23
      相关资源
      最近更新 更多