This is a simple network service that serves the Gensim's KeyedVectors
via Pyro4.
$ ./server.py
usage: server.py [--id ID] [--no-sims] [-h HOST] [-p PORT] w2v
The only mandatory parameter, w2v
, specifies the path to the word vectors in the word2vec format. By default, the server listens to any network interface on the port 9090.
For instance, the following pre-trained vectors are available:
- English: Google News, GloVe, fastText;
- Russian: Russian Distributional Thesaurus, RusVectōrēs.
The image is designed under the assumption that the vectors are mounted as /usr/src/app/w2v.bin
.
import Pyro4
Pyro4.config.SERIALIZER = 'pickle' # see the Disclaimer
w2v = Pyro4.Proxy('PYRO:w2v@localhost:9090')
w2v.word_vec('cat') # => array([…], dtype=float32)
Note that this service should be running in a trusted environment since it uses the pickle
serializer to handle the NumPy arrays. This makes the system extremely vulnerable and even allows arbitrary code execution, which is not recommended by the Pyro4 developers.
Copyright (c) 2017–2021 Dmitry Ustalov. See LICENSE for details.