Coder Social home page Coder Social logo

pyword2vec's Introduction

Overview

Exposes the gensim Word2Vec model via a RESTful interface. Also caches responses. This only exposes the most_similar method, and supports the positive, negative, and ntop requests.

Usage

Note that startup can take several minutes, as the Word2Vec model needs to be loaded into memory. The server exposes a /keepalive method intended for ELB or other monitoring, and the keepalive will trigger warmup of the Word2Vec model. Peak memory usage is around 7GB.

$ docker run -d -p 8080:80 reutersmedia/pyword2vec:latest

$ curl http://localhost:8080/most_similar?positive=hello&topn=5
{
  "most_similar": [
    [
      "hi", 
      0.6548985838890076
    ], 
    [
      "goodbye", 
      0.6399056911468506
    ], 
    [
      "howdy", 
      0.6310961246490479
    ], 
    [
      "goodnight", 
      0.5920579433441162
    ], 
    [
      "greeting", 
      0.5855876803398132
    ]
  ], 
  "negative_unused": [], 
  "positive_unused": []
}

To query for multiple terms:

$ curl "http://localhost:8080/most_similar?positive=hello&positive=world&topn=5"
{
  "most_similar": [
    [
      "g'day", 
      0.5079617500305176
    ], 
    [
      "globe", 
      0.49662062525749207
    ], 
    [
      "OBAMA_Hello", 
      0.4954448640346527
    ], 
    [
      "hi", 
      0.4945191442966461
    ], 
    [
      "guten_tag", 
      0.4936927855014801
    ]
  ], 
  "negative_unused": [], 
  "positive_unused": []
}

If a term is not present in the Word2Vec model, it will be excluded from the response and the exclusion will be noted in either the "positive_unused" or "negative_unused" list.

$ curl "http://localhost:8080/most_similar?positive=hello&positive=world&positive=flibertygibbet&topn=5"
{
  "most_similar": [
    [
      "g'day", 
      0.5079617500305176
    ], 
    [
      "globe", 
      0.49662062525749207
    ], 
    [
      "OBAMA_Hello", 
      0.4954448640346527
    ], 
    [
      "hi", 
      0.4945191442966461
    ], 
    [
      "guten_tag", 
      0.4936927855014801
    ]
  ], 
  "negative_unused": [], 
  "positive_unused": [
    "flibertygibbet"
  ]
}

Building

In order to build a Docker image, you should download the Google pretrained model to GoogleNews-vectors-negative300.bin.gz and place it in the root directory.

Copyright

Copyright (C) 2017 Thomson Reuters

pyword2vec's People

Stargazers

 avatar

Watchers

Tal Giat avatar Kenneth Ellis avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.