-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinterface.jl
190 lines (182 loc) · 7.65 KB
/
interface.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
"""
word2vec(train, output; size=100, window=5, sample=1e-3, hs=0, negative=5, threads=12, iter=5, min_count=5, alpha=0.025, debug=2, binary=1, cbow=1, save_vocal=Nothing(), read_vocab=Nothing(), verbose=false,)
Parameters for training:
train <file>
Use text data from <file> to train the model
output <file>
Use <file> to save the resulting word vectors / word clusters
size <Int>
Set size of word vectors; default is 100
window <Int>
Set max skip length between words; default is 5
sample <AbstractFloat>
Set threshold for occurrence of words. Those that appear with
higher frequency in the training data will be randomly
down-sampled; default is 1e-5.
hs <Int>
Use Hierarchical Softmax; default is 1 (0 = not used)
negative <Int>
Number of negative examples; default is 0, common values are
5 - 10 (0 = not used)
threads <Int>
Use <Int> threads (default 12)
iter <Int>
Run more training iterations (default 5)
min_count <Int>
This will discard words that appear less than <Int> times; default
is 5
alpha <AbstractFloat>
Set the starting learning rate; default is 0.025
debug <Int>
Set the debug mode (default = 2 = more info during training)
binary <Int>
Save the resulting vectors in binary moded; default is 0 (off)
cbow <Int>
Use the continuous back of words model; default is 1 (skip-gram
model)
save_vocab <file>
The vocabulary will be saved to <file>
read_vocab <file>
The vocabulary will be read from <file>, not constructed from the
training data
verbose <Bool>
Print output from training
"""
function word2vec(train::AbstractString, output::AbstractString;
size::Int=100, window::Int=5, sample::AbstractFloat=1e-3,
hs::Int=0, negative::Int=5, threads::Int=12, iter::Int=5,
min_count::Int=5, alpha::AbstractFloat=0.025,
debug::Int=2, binary::Int=0, cbow::Int=1,
save_vocab=Nothing(), read_vocab=Nothing(),
verbose::Bool=false)
parameters = AbstractString[]
args = ["-train", "-output", "-size", "-window", "-sample", "-hs",
"-negative", "-threads", "-iter", "-min-count", "-alpha",
"-debug", "-binary", "-cbow"]
values = [train, output, size, window, sample, hs, negative, threads,
iter, min_count, alpha, debug, binary, cbow]
for (arg, value) in zip(args, values)
push!(parameters, arg)
push!(parameters, string(value))
end
if save_vocab != Nothing()
push!(parameters, "-save-vocab")
push!(parameters, string(save_vocab))
end
if read_vocab != Nothing()
push!(parameters, "-read-vocab")
push!(parameters, string(read_vocab))
end
Word2Vec_jll.word2vec() do command
run(`$(command) $(parameters)`)
end
end
"""
```
word2clusters(train, output, classes; size=100, window=5, sample=1e-3, hs=0, negative=5, threads=1, iter=5, min_count=5, alpha=0.025, debug=2, binary=1, cbow=1, save_vocal=Nothing(), read_vocab=Nothing(), verbose=false)
```
Parameters for training:
train <file>
Use text data from <file> to train the model
output <file>
Use <file> to save the resulting word vectors / word clusters
size <Int>
Set size of word vectors; default is 100
window <Int>
Set max skip length between words; default is 5
sample <AbstractFloat>
Set threshold for occurrence of words. Those that appear with
higher frequency in the training data will be randomly
down-sampled; default is 0 (off), useful value is 1e-5
hs <Int>
Use Hierarchical Softmax; default is 1 (0 = not used)
negative <Int>
Number of negative examples; default is 0, common values are 5 - 10
(0 = not used)
threads <Int>
Use <Int> threads (default 1)
iter <Int>
Run more training iterations (default 5)
min_count <Int>
This will discard words that appear less than <Int> times
(default 5)
alpha <AbstractFloat>
Set the starting learning rate; default is 0.025
classes <Int>
Number of word classes; if 0, output word classes rather than
word vectors (default 0)
debug <Int>
Set the debug mode (default = 2 = more info during training)
binary <Int>
Save the resulting vectors in binary moded; default is 0 (off)
cbow <Int>
Use the continuous back of words model; default is 1 (0 for skip-gram
model)
save_vocab <file>
The vocabulary will be saved to <file>
read_vocab <file>
The vocabulary will be read from <file>, not constructed from the
training data
verbose <Bool>
Print output from training
"""
function word2clusters(train::AbstractString, output::AbstractString,
classes::Int; size::Int=100, window::Int=5,
sample::AbstractFloat=0., hs::Int=0,
negative::Int=5, threads::Int=1, iter::Int=5,
min_count::Int=5, alpha::AbstractFloat=0.025,
debug::Int=2, binary::Int=0, cbow::Int=1,
save_vocab=Nothing(), read_vocab=Nothing(),
verbose::Bool=false)
parameters = AbstractString[]
args = ["-train", "-output", "-size", "-window", "-sample", "-hs",
"-negative", "-threads", "-iter", "-min-count", "-alpha",
"-debug", "-binary", "-cbow", "-classes"]
values = [train, output, size, window, sample, hs, negative, threads,
iter, min_count, alpha, debug, binary, cbow, classes]
for (arg, value) in zip(args, values)
push!(parameters, arg)
push!(parameters, string(value))
end
if save_vocab != Nothing()
push!(parameters, "-save-vocab")
push!(parameters, string(save_vocab))
end
if read_vocab != Nothing()
push!(parameters, "-read-vocab")
push!(parameters, string(read_vocab))
end
Word2Vec_jll.word2vec() do command
run(`$(command) $(parameters)`)
end
end
"""
word2phrase(train, output; min_count=5, threshold=100, debug=2)
Parameters for training:
train <file>
Use text data from <file> to train the model
output <file>
Use <file> to save the resulting word vectors /
word clusters / phrases
min_count <Int>
This will discard words that appear less than <int> times;
default is 5
threshold <AbstractFloat>
The <AbstractFloat> value represents threshold for
forming the phrases (higher means less phrases); default 100
debug <Int>
Set the debug mode (default = 2 = more info during training)
"""
function word2phrase(train::AbstractString, output::AbstractString;
min_count::Int=5, threshold::Int=100, debug::Int=2)
parameters = AbstractString[]
args = ["-train", "-output", "-min-count", "-threshold", "-debug"]
values = [train, output, min_count, threshold, debug]
for (arg, value) in zip(args, values)
push!(parameters, arg)
push!(parameters, string(value))
end
Word2Vec_jll.word2phrase() do command
run(`$(command) $(parameters)`)
end
end