Skip to content

Commit

Permalink
Merge pull request 3Top#2 from emmjaykay/master
Browse files Browse the repository at this point in the history
fix some typos
  • Loading branch information
lechatpito committed May 20, 2015
2 parents 8fc195c + 6ddc080 commit 7e52756
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ python word2vec-api --model path/to/the/model [--host host --port 1234]

* Example calls
```
curl http://127.0.0.1:5000/wor2vec/n_similarity?ws1=Sushi&ws1=Shop&ws2=Japanese&ws2=Restaurant
curl http://127.0.0.1:5000/wor2vec/similarity?w1=Sushi&w2=Japanese
curl http://127.0.0.1:5000/wor2vec/most_similar?positive=indian&positive=food[&negative=][&topn=]
curl http://127.0.0.1:5000/wor2vec/model?word=restaurant
curl http://127.0.0.1:5000/word2vec/n_similarity?ws1=Sushi&ws1=Shop&ws2=Japanese&ws2=Restaurant
curl http://127.0.0.1:5000/word2vec/similarity?w1=Sushi&w2=Japanese
curl http://127.0.0.1:5000/word2vec/most_similar?positive=indian&positive=food[&negative=][&topn=]
curl http://127.0.0.1:5000/word2vec/model?word=restaurant
```

Note: The "model" method returns a base64 encoding of the Word2Vec vector.
10 changes: 6 additions & 4 deletions word2vec-api.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from gensim.models.word2vec import Word2Vec as w
from gensim import utils, matutils
from numpy import exp, dot, zeros, outer, random, dtype, get_include, float32 as REAL,\
uint32, seterr, array, uint8, vstack, argsort, fromstring, sqrt, newaxis, ndarray, empty, sum as np_sum
uint32, seterr, array, uint8, vstack, argsort, fromstring, sqrt, newaxis, ndarray, empty, sum as np_sum
import argparse
import base64
import sys
Expand All @@ -20,6 +20,8 @@


def filter_words(words):
if words is None:
return
return [word for word in words if word in model.vocab]


Expand Down Expand Up @@ -94,20 +96,20 @@ def raiseError(error):

if __name__ == '__main__':
global model

#----------- Parsing Arguments ---------------
p = argparse.ArgumentParser()
p.add_argument("--model", help="Path to the trained model")
p.add_argument("--binary", help="Specifies the loaded model is binary")
p.add_argument("--host", help="Host name (default: localhost)")
p.add_argument("--port", help="Port (default: 5000)")
args = p.parse_args()

model_path = args.model if args.model else "./model.bin.gz"
binary = True if args.binary else False
host = args.host if args.host else "localhost"
port = int(args.port) if args.port else 5000
if not args.model:
print "Usage: wor2vec-apy.py --model path/to/the/model [--host host --port 1234]"
print "Usage: word2vec-apy.py --model path/to/the/model [--host host --port 1234]"
model = w.load_word2vec_format(model_path, binary=binary)
app.run(host=host, port=port)

0 comments on commit 7e52756

Please sign in to comment.