Last active
December 20, 2017 17:08
-
-
Save ozanarkancan/b55c992c5fa26944142c7fd8fdb2b6ff to your computer and use it in GitHub Desktop.
Use wvec
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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