Skip to content

Commit 9d0e700

Browse files
committed
fix
1 parent 3e202f9 commit 9d0e700

File tree

7 files changed

+113
-33
lines changed

7 files changed

+113
-33
lines changed

egs/ami/s5b/local/rnnlm/tuning/run_lstm_tdnn_b.sh

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
# Begin configuration section.
1515
cmd=run.pl
16-
affix=b
16+
dir=exp/rnnlm_lstm_tdnn_b
1717
embedding_dim=200
1818
embedding_l2=0.005 # embedding layer l2 regularize
1919
comp_l2=0.005 # component-level l2 regularize
@@ -22,15 +22,12 @@ epochs=90
2222
mic=sdm1
2323
stage=-10
2424
train_stage=0
25-
alpha=0.0
26-
back_interval=1
2725

2826
. utils/parse_options.sh
2927
train=data/$mic/train/text
3028
dev=data/$mic/dev/text
3129
wordlist=data/lang/words.txt
3230
text_dir=data/rnnlm/text
33-
dir=exp/rnnlm_lstm_tdnn_$affix
3431
mkdir -p $dir/config
3532
set -e
3633

@@ -94,10 +91,9 @@ if [ $stage -le 2 ]; then
9491
fi
9592

9693
if [ $stage -le 3 ]; then
97-
backstitch_opt="--backstitch-scale $alpha --backstitch-interval $back_interval"
9894
rnnlm/train_rnnlm.sh --embedding_l2 $embedding_l2 \
9995
--stage $train_stage \
100-
--num-epochs $epochs --cmd "queue.pl" $backstitch_opt $dir
96+
--num-epochs $epochs --cmd "queue.pl" $dir
10197
fi
10298

10399
exit 0
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
3+
# Copyright 2012 Johns Hopkins University (author: Daniel Povey) Tony Robinson
4+
# 2017 Hainan Xu
5+
# 2017 Ke Li
6+
# 2017 Yiming Wang
7+
8+
# This script is similar to rnnlm_lstm_tdnn_b.sh except for adding backstitch training
9+
10+
# rnnlm/train_rnnlm.sh: best iteration (out of 18) was 17, linking it to final iteration.
11+
# rnnlm/train_rnnlm.sh: train/dev perplexity was 45.6 / 68.7.
12+
# Train objf: -651.50 -4.44 -4.26 -4.15 -4.08 -4.03 -4.00 -3.97 -3.94 -3.92 -3.90 -3.89 -3.88 -3.86 -3.85 -3.84 -3.83 -3.82
13+
# Dev objf: -10.76 -4.68 -4.47 -4.38 -4.33 -4.29 -4.28 -4.27 -4.26 -4.26 -4.25 -4.24 -4.24 -4.24 -4.23 -4.23 -4.23 -4.23
14+
15+
# Begin configuration section.
16+
cmd=run.pl
17+
affix=1a
18+
embedding_dim=200
19+
embedding_l2=0.005 # embedding layer l2 regularize
20+
comp_l2=0.005 # component-level l2 regularize
21+
output_l2=0.005 # output-layer l2 regularize
22+
epochs=90
23+
mic=sdm1
24+
stage=-10
25+
train_stage=0
26+
alpha=0.8
27+
back_interval=1
28+
29+
. utils/parse_options.sh
30+
train=data/$mic/train/text
31+
dev=data/$mic/dev/text
32+
wordlist=data/lang/words.txt
33+
text_dir=data/rnnlm/text
34+
dir=exp/rnnlm_lstm_tdnn_bs_$affix
35+
mkdir -p $dir/config
36+
set -e
37+
38+
for f in $train $dev $wordlist; do
39+
[ ! -f $f ] && \
40+
echo "$0: expected file $f to exist; search for run.sh and utils/prepare_lang.sh in run.sh" && exit 1
41+
done
42+
43+
if [ $stage -le 0 ]; then
44+
mkdir -p $text_dir
45+
cat $train | cut -d ' ' -f2- > $text_dir/ami.txt
46+
cat $dev | cut -d ' ' -f2- > $text_dir/dev.txt
47+
fi
48+
49+
if [ $stage -le 1 ]; then
50+
cp $wordlist $dir/config/
51+
n=`cat $dir/config/words.txt | wc -l`
52+
echo "<brk> $n" >> $dir/config/words.txt
53+
54+
# words that are not present in words.txt but are in the training or dev data, will be
55+
# mapped to <unk> during training.
56+
echo "<unk>" >$dir/config/oov.txt
57+
58+
cat > $dir/config/data_weights.txt <<EOF
59+
ami 1 1.0
60+
EOF
61+
62+
rnnlm/get_unigram_probs.py --vocab-file=$dir/config/words.txt \
63+
--unk-word="<unk>" \
64+
--data-weights-file=$dir/config/data_weights.txt \
65+
$text_dir | awk 'NF==2' >$dir/config/unigram_probs.txt
66+
67+
# choose features
68+
rnnlm/choose_features.py --unigram-probs=$dir/config/unigram_probs.txt \
69+
--use-constant-feature=true \
70+
--top-word-features 10000 \
71+
--min-frequency 1.0e-03 \
72+
--special-words='<s>,</s>,<brk>,<unk>,[noise],[laughter]' \
73+
$dir/config/words.txt > $dir/config/features.txt
74+
75+
lstm_opts="l2-regularize=$comp_l2"
76+
tdnn_opts="l2-regularize=$comp_l2"
77+
output_opts="l2-regularize=$output_l2"
78+
79+
cat >$dir/config/xconfig <<EOF
80+
input dim=$embedding_dim name=input
81+
lstm-layer name=lstm1 cell-dim=$embedding_dim $lstm_opts
82+
relu-renorm-layer name=tdnn dim=$embedding_dim $tdnn_opts input=Append(0, IfDefined(-1))
83+
lstm-layer name=lstm2 cell-dim=$embedding_dim $lstm_opts
84+
output-layer name=output $output_opts include-log-softmax=false dim=$embedding_dim
85+
EOF
86+
rnnlm/validate_config_dir.sh $text_dir $dir/config
87+
fi
88+
89+
if [ $stage -le 2 ]; then
90+
# the --unigram-factor option is set larger than the default (100)
91+
# in order to reduce the size of the sampling LM, because rnnlm-get-egs
92+
# was taking up too much CPU (as much as 10 cores).
93+
rnnlm/prepare_rnnlm_dir.sh --unigram-factor 200 \
94+
$text_dir $dir/config $dir
95+
fi
96+
97+
if [ $stage -le 3 ]; then
98+
backstitch_opt="--rnnlm.backstitch-scale $alpha --rnnlm.backstitch-interval $back_interval --embedding.backstitch-scale $alpha --embedding.backstitch-interval $back_interval"
99+
rnnlm/train_rnnlm.sh --embedding_l2 $embedding_l2 \
100+
--stage $train_stage \
101+
--num-epochs $epochs --cmd "queue.pl" $backstitch_opt $dir
102+
fi
103+
104+
exit 0

src/rnnlm/rnnlm-core-training.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ void RnnlmCoreTrainer::Train(
166166
ProvideInput(minibatch, derived, word_embedding, &computer);
167167
computer.Run(); // This is the forward pass.
168168

169-
ProcessOutput(true, minibatch, derived, word_embedding,
169+
bool is_backstitch_step1 = true;
170+
ProcessOutput(is_backstitch_step1, minibatch, derived, word_embedding,
170171
&computer, word_embedding_deriv);
171172

172173
computer.Run(); // This is the backward pass.

src/rnnlm/rnnlm-core-training.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,12 @@ struct RnnlmCoreTrainerOptions {
7575
"related to parallelization by model averaging.");
7676
opts->Register("backstitch-training-scale", &backstitch_training_scale,
7777
"backstitch training factor. "
78-
"if 0 then in the normal training mode. It is referred as "
78+
"if 0 then in the normal training mode. It is referred to as "
7979
"'\\alpha' in our publications.");
8080
opts->Register("backstitch-training-interval",
8181
&backstitch_training_interval,
8282
"do backstitch training with the specified interval of "
83-
"minibatches. It is referred as 'n' in our publications.");
83+
"minibatches. It is referred to as 'n' in our publications.");
8484
}
8585
};
8686

src/rnnlm/rnnlm-embedding-training.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ struct RnnlmEmbeddingTrainerOptions {
9292
"training the word-embedding matrix.");
9393
opts->Register("backstitch-training-scale", &backstitch_training_scale,
9494
"backstitch training factor. "
95-
"if 0 then in the normal training mode. It is referred as "
95+
"if 0 then in the normal training mode. It is referred to as "
9696
"'\\alpha' in our publications.");
9797
opts->Register("backstitch-training-interval",
9898
&backstitch_training_interval,
9999
"do backstitch training with the specified interval of "
100-
"minibatches. It is referred as 'n' in our publications.");
100+
"minibatches. It is referred to as 'n' in our publications.");
101101
opts->Register("use-natural-gradient", &use_natural_gradient,
102102
"True if you want to use natural gradient to update the "
103103
"embedding matrix");

src/rnnlm/rnnlm-training.cc

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -230,14 +230,9 @@ void RnnlmTrainer::TrainInternal() {
230230
GetWordEmbedding(&word_embedding_storage, &word_embedding);
231231

232232
CuMatrix<BaseFloat> word_embedding_deriv;
233-
if (train_embedding_) {
234-
KALDI_ASSERT(core_config_.backstitch_training_scale ==
235-
embedding_config_.backstitch_training_scale &&
236-
core_config_.backstitch_training_interval ==
237-
embedding_config_.backstitch_training_interval);
233+
if (train_embedding_)
238234
word_embedding_deriv.Resize(word_embedding->NumRows(),
239235
word_embedding->NumCols());
240-
}
241236

242237
if (core_config_.backstitch_training_scale > 0.0 &&
243238
num_minibatches_processed_ % core_config_.backstitch_training_interval ==

src/rnnlmbin/rnnlm-train.cc

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,6 @@ int main(int argc, char *argv[]) {
4242
std::string embedding_rxfilename;
4343
std::string embedding_wxfilename;
4444
std::string word_features_rxfilename;
45-
// backstitch options
46-
BaseFloat backstitch_training_scale = 0.0;
47-
int32 backstitch_training_interval = 1;
4845
// binary mode for writing output.
4946
bool binary = true;
5047

@@ -91,14 +88,6 @@ int main(int argc, char *argv[]) {
9188
"letters and other hand-built features; it's not trainable."
9289
" If present, the embedding matrix read via --read-embedding "
9390
"will be interpreted as a feature-embedding matrix.");
94-
po.Register("backstitch-training-scale", &backstitch_training_scale,
95-
"backstitch training factor. "
96-
"if 0 then in the normal training mode. It is referred as "
97-
"'\\alpha' in our publications.");
98-
po.Register("backstitch-training-interval",
99-
&backstitch_training_interval,
100-
"do backstitch training with the specified interval of "
101-
"minibatches. It is referred as 'n' in our publications.");
10291
po.Register("binary", &binary,
10392
"If true, write outputs in binary form.");
10493

@@ -121,11 +110,6 @@ int main(int argc, char *argv[]) {
121110

122111
po.Read(argc, argv);
123112

124-
core_config.backstitch_training_scale = backstitch_training_scale;
125-
core_config.backstitch_training_interval = backstitch_training_interval;
126-
embedding_config.backstitch_training_scale = backstitch_training_scale;
127-
embedding_config.backstitch_training_interval = backstitch_training_interval;
128-
129113
if (po.NumArgs() != 1) {
130114
po.PrintUsage();
131115
exit(1);

0 commit comments

Comments
 (0)