【发布时间】:2016-03-03 13:42:00
【问题描述】:
我知道已经有人问过这个问题,但我仍然无法找到解决方案。
我想在自定义数据集上使用 gensim 的 word2vec,但现在我仍在弄清楚数据集必须采用什么格式。我查看了this post,其中输入基本上是一个列表列表(一个包含其他列表的大列表,这些列表是来自 NLTK Brown 语料库的标记化句子)。所以我认为这是我必须用于命令word2vec.Word2Vec() 的输入格式。但是,它不适用于我的小测试集,我不明白为什么。
我尝试过的:
成功了:
from gensim.models import word2vec
from nltk.corpus import brown
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)
brown_vecs = word2vec.Word2Vec(brown.sents())
这不起作用:
sentences = [ "the quick brown fox jumps over the lazy dogs","yoyoyo you go home now to sleep"]
vocab = [s.encode('utf-8').split() for s in sentences]
voc_vec = word2vec.Word2Vec(vocab)
我不明白为什么它不适用于“模拟”数据,即使它与布朗语料库中的句子具有相同的数据结构:
词汇:
[['the', 'quick', 'brown', 'fox', 'jumps', 'over', 'the', 'lazy', 'dogs'], ['yoyoyo', 'you', 'go', 'home', 'now', 'to', 'sleep']]
brown.sents():(它的开头)
[['The', 'Fulton', 'County', 'Grand', 'Jury', 'said', 'Friday', 'an', 'investigation', 'of', "Atlanta's", 'recent', 'primary', 'election', 'produced', '``', 'no', 'evidence', "''", 'that', 'any', 'irregularities', 'took', 'place', '.'], ['The', 'jury', 'further', 'said', 'in', 'term-end', 'presentments', 'that', 'the', 'City', 'Executive', 'Committee', ',', 'which', 'had', 'over-all', 'charge', 'of', 'the', 'election', ',', '``', 'deserves', 'the', 'praise', 'and', 'thanks', 'of', 'the', 'City', 'of', 'Atlanta', "''", 'for', 'the', 'manner', 'in', 'which', 'the', 'election', 'was', 'conducted', '.'], ...]
谁能告诉我我做错了什么?
【问题讨论】: