-
Notifications
You must be signed in to change notification settings - Fork 0
/
model.rb
92 lines (76 loc) · 1.88 KB
/
model.rb
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
#!/usr/bin/ruby -Ku
# rubyhtk by Takuya Nishimoto
class Model
@@count = 0
def self.new_dir
@@count += 1
"_hmm/#{@@count}"
end
def self.proto
Model.new.proto
end
def self.first_train(data, label)
proto = Model.proto
m0 = Model.new.compv(proto, data)
Model.new.erest(m0, data, label)
end
attr_reader :dir
attr_reader :num_mixes
def initialize(dir = nil)
if dir == nil
@dir = Model.new_dir
FileUtils.mkdir_p @dir
else
@dir = dir
end
end
def to_s
"Model in #{@dir}"
end
def sh(s)
puts(s)
system(s)
end
def proto
num_states = 20
vec_size = 39
protohmm(@dir, WORDS, num_states, vec_size)
@num_mixes = 1
self
end
def compv(input, data)
WORDS.each do |w|
sh "HCompV -m -M #{@dir} -S #{data} #{input.dir}/#{w}"
end
@num_mixes = input.num_mixes
self
end
def erest(input, data, label)
sh "HERest -L #{label} -S #{data} -d #{input.dir} -M #{@dir} -C config/config.herest -s #{@dir}/stats config/models"
# output : #{@dir}/{newMacros,stats}
@num_mixes = input.num_mixes
self
end
def mixup1(input)
File.open("_script/mixup.hed", "w") do |f|
f.puts "LS #{input.dir}/stats"
f.puts "MU +1 {*.state[2-19].mix}"
end
sh "HHEd -H #{input.dir}/newMacros -M #{@dir} _script/mixup.hed config/models"
@num_mixes = input.num_mixes + 1
self
end
def mixup2(input, data, label)
sh "HERest -L #{label} -S #{data} -H #{input.dir}/newMacros -M #{@dir} -C config/config.herest -s #{@dir}/stats config/models"
@num_mixes = input.num_mixes
self
end
# returns new instance
def mixup_train(data, label)
m2 = Model.new.mixup1(self)
Model.new.mixup2(m2, data, label)
end
def vite(data, recout)
sh "HVite -H #{@dir}/newMacros -S #{data} -w _script/wdnet -i #{recout} config/dict config/models"
end
end