How can I count word frequencies in Word2Vec's training model?

前端 未结 1 1582
一向
一向 2021-01-28 03:30

I need to count the frequency of each word in word2vec\'s training model. I want to have output that looks like this:

term    count
apple   123004
         


        
1条回答
  •  闹比i
    闹比i (楼主)
    2021-01-28 03:52

    Which word2vec implementation are you using?

    In the popular gensim library, after a Word2Vec model has its vocabulary established (either by doing its full training, or after build_vocab() has been called), the model's wv property contains a KeyedVectors-type object, which as a property vocab which is a dict of Vocab-type objects, which have a count property of the word's frequency in the scanned corpus.

    So you could get roughly what you seek with something like:

    w2v_model = Word2Vec(your_corpus, ...)
    for word in w2v_model.wv.vocab:
        print((word, w2v_model.wv.vocab[word].count))
    

    Plain sets of word-vectors (such as those loaded via gensim's load_word2vec_format() method) won't have accurate counts, but are by convention usually internally ordered from most-frequent to least-frequent.

    0 讨论(0)
提交回复
热议问题