Code Monkey home page Code Monkey logo

python-adagram's Introduction

Python-AdaGram

Python-AdaGram is an implementation of AdaGram (adaptive skip-gram) for Python. It borrows a lot of C code from the original AdaGram implementation in Julia (https://github.com/sbos/AdaGram.jl). AdaGram was introduced in a paper by Sergey Bartunov, Dmitry Kondrashkin, Anton Osokin and Dmitry Vetrov at http://arxiv.org/abs/1502.07257.

Note: this is a work in progress: it lacks tests and disambiguation, and produces incorrect results when using more than one worker. If you have a more mature implementation or want to help, please get in touch.

Install

$ pip install python-adagram

Usage

Train a model from command line:

$ adagram-train tokenized.txt out.pkl

Input corpus must be already tokenized, with tokens (usually words) separated by spaces. There are many options available, see adagram-train --help.

Load model:

>>> import adagram
>>> vm = adagram.VectorModel.load('out.pkl')

Get sense probabilities for some word:

>>> vm.word_sense_probs('apple')
[0.341832, 0.658164]

Get sense neighbors:

>>> vm.sense_neighbors('apple', 0)
[('almond', 0, 0.70396507),
 ('cherry', 1, 0.69193166),
 ('plum', 0, 0.690269),
 ('apricot', 0, 0.6882005),
 ('orange', 3, 0.6739181),
 ('pecan', 0, 0.6662803),
 ('pomegranate', 0, 0.6580653)
 ('blueberry', 0, 0.6509351),
 ('pear', 0, 0.6484747),
 ('peach', 0, 0.6313036)]

>>> vm.sense_neighbors('apple',  1)
[('macintosh', 0, 0.79053026),
 ('iifx', 0, 0.71349466),
 ('iigs', 0, 0.7030192),
 ('computers', 0, 0.6952761),
 ('kaypro', 0, 0.6938647),
 ('ipad', 0, 0.6914306),
 ('pc', 3, 0.6801078),
 ('ibm', 0, 0.66797054),
 ('powerpc-based', 0, 0.66319686),
 ('ibm-compatible', 0, 0.66120595)]

Get sense vector:

>>> vm.sense_vector('apple', 1)
array([...], dtype=float32)

Converting models built with AdaGram.jl

First, install AdaGram.jl as described here https://github.com/sbos/AdaGram.jl. Install JSON package:

$ julia
julia> Pkg.add("JSON")

Run the script that converts a julia model to JSON:

$ julia adagram/dump_julia.jl julia-model out-directory

This will save two JSON files to out-directory.

Next, to convert model to python format, run:

$ ./adagram/load_julia.py out-directory model.joblib

python-adagram's People

Contributors

lopuhin avatar

Watchers

 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.