Using word2vec in production

437 views
Skip to first unread message

Manya Wadhwa

unread,
Apr 6, 2017, 3:14:40 AM4/6/17
to gensim
Hi,

I am trying to use the word2vec model in production. I have a python script which uses gensim to load the google pre-trained model into the memory. The main issue I'm having is that this python script will be called multiple times and in parallel. Which means, the script will try to load the model everytime

Is there a work around this problem?
Can I load the model just once and use some memory mapping to call it again in some other program?


Any help will be appreciated. 


Thanks,
Manya

Gordon Mohr

unread,
Apr 6, 2017, 3:37:22 AM4/6/17
to gensim
Yes! I recently wrote up a possible approach in a StackOverflow answer:


I haven't tested all the steps, so it's possible something is overlooked, but the general approach should work. Let me know how it goes!

- Gordon

Manya Wadhwa

unread,
Apr 6, 2017, 3:43:54 AM4/6/17
to gensim
Will do. 


Thanks!

Andrey Kutuzov

unread,
Apr 6, 2017, 4:32:31 AM4/6/17
to gen...@googlegroups.com
Hi Manya,

I think the most flexible solution is to load the model with a separate
script, which then starts listening to requests from other applications
via sockets.
This is how http://vectors.nlpl.eu/explore/embeddings/ service works.

You can find the actual code of this 'server script' here and then adapt
it to your needs:
https://github.com/akutuzov/webvectors/blob/master/word2vec_server.py
> --
> You received this message because you are subscribed to the Google
> Groups "gensim" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to gensim+un...@googlegroups.com
> <mailto:gensim+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Solve et coagula!
Andrey

Radim Řehůřek

unread,
Apr 6, 2017, 5:26:40 AM4/6/17
to gensim
Let me add that we run such a word2vec HTTP service ourselves too, with some additional functionality: https://rare-technologies.com/word2vec-tutorial/#bonus_app

In case you're curious about how to write a web service like that, its (tiny) code is freely available at https://github.com/RaRe-Technologies/w2v_server_googlenews , including the "typing suggestions" functionality.

HTH,
Radim

Manya Wadhwa

unread,
Apr 10, 2017, 1:17:51 AM4/10/17
to gensim
Was hoping for such a solution only. This worked. Thanks!
Reply all
Reply to author
Forward
0 new messages