Where can I find a reliable word2vec model trained on some English articles?

I need a word2vec black box, where I, for example, can pass a sentence as array: ["London", "is", "the", "capital", "of", "Great", "Britain"]

and receive: [some_vector_of_floats1, some_vector_of_floats2, some_vector_of_floats3, some_vector_of_floats4, some_vector_of_floats5, some_vector_of_floats6, some_vector_of_floats7]


In Python, you can use Gensim

import gensim
model = gensim.models.Word2Vec.load_word2vec_format('path-to-vectors.txt', binary=False)
# if you vector file is in binary format, change to binary=True
sentence = ["London", "is", "the", "capital", "of", "Great", "Britain"]
vectors = [model[w] for w in sentence]

These vectors should give you better performance than the pre-trained ones you'd get with word2vec.

  • $\begingroup$ thank you very much. it probably works, but I receive the error KeyError: 'of' $\endgroup$ – Dmytro Nalyvaiko Mar 13 '17 at 14:05
  • $\begingroup$ That means of is not in your model's vocabulary. Which vectors are you using? $\endgroup$ – Alexandre Mar 13 '17 at 14:06
  • $\begingroup$ GoogleNews-vectors-negative300.bin $\endgroup$ – Dmytro Nalyvaiko Mar 13 '17 at 14:06
  • $\begingroup$ I use that model in node-word2vec and it works there with sentence about London $\endgroup$ – Dmytro Nalyvaiko Mar 13 '17 at 14:09
  • $\begingroup$ Did you change binary=True to binary=False as noted? The pre-trained Google vectors are in binary format. $\endgroup$ – Alexandre Mar 13 '17 at 14:16

I slightly modified the code - for my purposes

vocab = model.vocab.keys()
sentence = ["London", "is", "the", "capital", "of", "Great", "Britain"]
for w in sentence:
    if w in vocab:
        print("Word {} not in vocab".format(w))

You could also use a try/catch - your call.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.