Skip to content

Instantly share code, notes, and snippets.

@ozanarkancan
Last active December 20, 2017 17:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozanarkancan/b55c992c5fa26944142c7fd8fdb2b6ff to your computer and use it in GitHub Desktop.
Save ozanarkancan/b55c992c5fa26944142c7fd8fdb2b6ff to your computer and use it in GitHub Desktop.
Use wvec
module WordVec
using PyCall
global const word2vec = PyCall.pywrap(PyCall.pyimport("gensim.models.word2vec"))
type Wvec
model
end
function Wvec(fname::String; bin=true)
Wvec(word2vec.Word2Vec["load_word2vec_format"](fname, binary=bin))
end
function getvec(m::Wvec, word::AbstractString)
vec = nothing
try
vec = m.model["__getitem__"](word)
catch
vec = m.model["__getitem__"]("unk")
end
return vec
end
export Wvec;
export getvec;
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment