Skip to content

Instantly share code, notes, and snippets.

@daskol
Created April 26, 2016 17:53
Show Gist options
  • Save daskol/56f6dfa2e38c075d04ae863b2a859ef3 to your computer and use it in GitHub Desktop.
Save daskol/56f6dfa2e38c075d04ae863b2a859ef3 to your computer and use it in GitHub Desktop.
from operator import itemgetter
from collections import OrderedDict
def word2index(model):
"""Extract word2index mapping from Word2Vec model.
"""
word2index = OrderedDict((v, k) for k, v in sorted(model.index2word, key=itemgetter(1)))
return word2index
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment