Get word rank from fastText model?

121 views
Skip to first unread message

Adam M B

unread,
Jul 25, 2017, 10:53:57 AM7/25/17
to gensim
Words are sorted in the model, so we can load with limited=n, and then 'apple' in model implies that 'apple' is in the top n words.

Is there a straightforward way to get the exact rank explicitly?

Gordon Mohr

unread,
Jul 25, 2017, 1:49:15 PM7/25/17
to gensim
As with other KeyedVectors, there's a property `vocab` that's a dictionary of word-keys to `Vocab` object values. The `index` property of the Vocab tells which int-index in the full array holds that word's vector. In the usual case, those slot indexes also match the order the words were read, which also (by convention but not necessarily guaranteed) is usually from most-frequent to least-frequent. 

(There's also the `index2word` property – a list of words in their slot order.) 

- Gordon

Adam Mathias Bittlingmayer

unread,
Jul 26, 2017, 4:25:11 AM7/26/17
to gen...@googlegroups.com
Thank you

For others: model.vocab['apple'].index

And to get the word at an index: model.index2word[42]

--
You received this message because you are subscribed to a topic in the Google Groups "gensim" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gensim/hE8jr0hKYa0/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gensim+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages