gensim - word2vec: AttributeError: 'Word2Vec' object has no attribute 'most_common'
gensim - word2vec: AttributeError: 'Word2Vec' object has no attribute 'most_common'
PAD = 0
UNK = 1
START = 2
END = 3
def make_vocab(wc, vocab_size):
word2id, id2word = {}, {}
word2id['<pad>'] = PAD
word2id['<unk>'] = UNK
word2id['<start>'] = START
word2id['<end>'] = END
for i, (w, _) in enumerate(wc.most_common(vocab_size), 4):
word2id[w] = i
return word2id
调用此函数时出现错误“AttributeError: 'Word2Vec' object has no attribute 'most_common'”。我尝试使用不同版本的 gensim。你能给我一些提示来解决这个问题吗?
Gensim 的 Word2Vec 不包含 most_common
方法。
如果出于某种原因您必须从模型中提取 word,frequency
对,您可以使用
[(word, wc.w2v.vocab[word]) for word in wc.wv.vocab]
并对结果列表进行排序。然而,这是一个非常奇怪的用例。
PAD = 0
UNK = 1
START = 2
END = 3
def make_vocab(wc, vocab_size):
word2id, id2word = {}, {}
word2id['<pad>'] = PAD
word2id['<unk>'] = UNK
word2id['<start>'] = START
word2id['<end>'] = END
for i, (w, _) in enumerate(wc.most_common(vocab_size), 4):
word2id[w] = i
return word2id
调用此函数时出现错误“AttributeError: 'Word2Vec' object has no attribute 'most_common'”。我尝试使用不同版本的 gensim。你能给我一些提示来解决这个问题吗?
Gensim 的 Word2Vec 不包含 most_common
方法。
如果出于某种原因您必须从模型中提取 word,frequency
对,您可以使用
[(word, wc.w2v.vocab[word]) for word in wc.wv.vocab]
并对结果列表进行排序。然而,这是一个非常奇怪的用例。