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
I got this error "AttributeError: 'Word2Vec' object has no attribute 'most_common'" when calling this function. I tried with different version of gensim. Could you give me some hints to solve this.
most_common()method in Gensim. (Why did you think there was?) But also, what are you trying to do with thisword2iddict and why? (If those tokens are in your training data, they'll get their own positions which should be just as good as 0-3. If they're not in your training data, reserving them positions could make other things broken/nonsensical/fragile.) - gojomo