-
Notifications
You must be signed in to change notification settings - Fork 44
AdaGram is written almost entirely in Julia (some performance-critical parts are implemented in C with Julia wrappers provided). This page describes how one can use a trained AgaGram model from Julia.
This section describes types defined in the package. Normally, you don't have to create instances of these types by yourself, only load/save them by predefined functions (unless you want to train a model from Julia, in this case please refer to train.jl)
type Dictionary
word2id::Dict{String, Int32}
id2word::Array{String}
end
-
word2idmaps aStringrepresentation of a word to itsInt32identifier -
id2wordis a reverse mapping
type VectorModel
frequencies::DenseArray{Int64}
code::DenseArray{Int8, 2}
path::DenseArray{Int32, 2}
In::DenseArray{Float32, 3}
Out::DenseArray{Float32, 2}
alpha::Float64
d::Float64
counts::DenseArray{Float32, 2}
end
This type represents an AdaGram model. DenseArrays are usually SharedArrays.
-
frequencies- number of occurrences for each word -
code[:, w]- binary code in hierarchical softmax (AdaGram uses Huffman tree similarly to SkipGram) for the wordw -
path[:, w]- path (sequence of node numbers) in hierarchical softmax for the wordw -
In[:, k, w]- input representation for the prototypekof wordw, this is what you normally want as word features -
Out[:, n]- output representation for the nodenin hierarchical softmax -
alpha- concentration parameter for Dirichlet Process (assumed to be the same for all words) -
d- parameter for Pitman-Yor process -
counts[k, w]- number of occurrences assigned to the prototypekof wordwand hence the posterior parameter.sum(counts, 1) = frequencies
load_model(path::String) → (vm::VectorModel, dict::Dictionary)
Loads and returns saved VectorModel and Dictionary in a tuple.
save_model(path::String, vm::VectorModel, dict::Dictionary, min_prob=1e-5)
Saves VectorModel and Dictionary at path ignoring prototypes with prior probability less than min_prob in order to save disk space.
expected_pi{Tw <: Integer}(vm::VectorModel, w::Tw, min_prob=1e-3) → pi::Array{Float64}
Returns prior probability of each word prototype, optionally setting probabilities below min_prob to zero.
disambiguate{Tw <: Integer}(vm::VectorModel, x::Tw, context::AbstractArray{Tw, 1}, use_prior::Bool=true, min_prob::Float64=1e-3) → pi::Array{Float64}
Returns posterior probability of each word prototype given context words. By setting use_prior to false, uniform prior will be used instead of expected_pi (to which min_prob is passed).
log_skip_gram{T1 <: Integer, T2 <: Integer}(vm::VectorModel, w::T1, s::T2, v::T1) → Float32
Returns log probability of a context word v given input word w and its prototype s