Skip to content

Commit b4b42cc

Browse files
committed
Merge branch 'master' of github.com:kaldi-asr/kaldi
2 parents d1ba027 + a5561c3 commit b4b42cc

File tree

17 files changed

+246
-1757
lines changed

17 files changed

+246
-1757
lines changed

egs/wsj/s5/steps/info/chain_dir_info.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ sub get_combine_info {
137137
if (m/Combining nnets, objective function changed from (\S+) to (\S+)/) {
138138
close(F);
139139
return sprintf(" combine=%.3f->%.3f", $1, $2);
140+
} elsif (m/Combining (\S+) nnets, objective function changed from (\S+) to (\S+)/) {
141+
close(F);
142+
return sprintf(" combine=%.3f->%.3f (over %d)", $2, $3, $1);
140143
}
141144
}
142145
}

egs/wsj/s5/steps/info/nnet3_dir_info.pl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,9 @@ sub get_combine_info {
137137
if (m/Combining nnets, objective function changed from (\S+) to (\S+)/) {
138138
close(F);
139139
return sprintf(" combine=%.2f->%.2f", $1, $2);
140+
} elsif (m/Combining (\S+) nnets, objective function changed from (\S+) to (\S+)/) {
141+
close(F);
142+
return sprintf(" combine=%.2f->%.2f (over %d)", $2, $3, $1);
140143
}
141144
}
142145
}

egs/wsj/s5/steps/libs/nnet3/train/chain_objf/acoustic_model.py

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def compute_progress(dir, iter, run_opts):
492492
def combine_models(dir, num_iters, models_to_combine, num_chunk_per_minibatch_str,
493493
egs_dir, leaky_hmm_coefficient, l2_regularize,
494494
xent_regularize, run_opts,
495-
sum_to_one_penalty=0.0):
495+
max_objective_evaluations=30):
496496
""" Function to do model combination
497497
498498
In the nnet3 setup, the logic
@@ -505,9 +505,6 @@ def combine_models(dir, num_iters, models_to_combine, num_chunk_per_minibatch_st
505505

506506
models_to_combine.add(num_iters)
507507

508-
# TODO: if it turns out the sum-to-one-penalty code is not useful,
509-
# remove support for it.
510-
511508
for iter in sorted(models_to_combine):
512509
model_file = '{0}/{1}.mdl'.format(dir, iter)
513510
if os.path.exists(model_file):
@@ -528,12 +525,9 @@ def combine_models(dir, num_iters, models_to_combine, num_chunk_per_minibatch_st
528525

529526
common_lib.execute_command(
530527
"""{command} {combine_queue_opt} {dir}/log/combine.log \
531-
nnet3-chain-combine --num-iters={opt_iters} \
528+
nnet3-chain-combine \
529+
--max-objective-evaluations={max_objective_evaluations} \
532530
--l2-regularize={l2} --leaky-hmm-coefficient={leaky} \
533-
--separate-weights-per-component={separate_weights} \
534-
--enforce-sum-to-one={hard_enforce} \
535-
--sum-to-one-penalty={penalty} \
536-
--enforce-positive-weights=true \
537531
--verbose=3 {dir}/den.fst {raw_models} \
538532
"ark,bg:nnet3-chain-copy-egs ark:{egs_dir}/combine.cegs ark:- | \
539533
nnet3-chain-merge-egs --minibatch-size={num_chunk_per_mb} \
@@ -542,12 +536,9 @@ def combine_models(dir, num_iters, models_to_combine, num_chunk_per_minibatch_st
542536
{dir}/final.mdl""".format(
543537
command=run_opts.command,
544538
combine_queue_opt=run_opts.combine_queue_opt,
545-
opt_iters=(20 if sum_to_one_penalty <= 0 else 80),
546-
separate_weights=(sum_to_one_penalty > 0),
539+
max_objective_evaluations=max_objective_evaluations,
547540
l2=l2_regularize, leaky=leaky_hmm_coefficient,
548541
dir=dir, raw_models=" ".join(raw_model_strings),
549-
hard_enforce=(sum_to_one_penalty <= 0),
550-
penalty=sum_to_one_penalty,
551542
num_chunk_per_mb=num_chunk_per_minibatch_str,
552543
num_iters=num_iters,
553544
egs_dir=egs_dir))

egs/wsj/s5/steps/libs/nnet3/train/common.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -852,6 +852,16 @@ def __init__(self,
852852
the final model combination stage. These
853853
models will themselves be averages of
854854
iteration-number ranges""")
855+
self.parser.add_argument("--trainer.optimization.max-objective-evaluations",
856+
"--trainer.max-objective-evaluations",
857+
type=int, dest='max_objective_evaluations',
858+
default=30,
859+
help="""The maximum number of objective
860+
evaluations in order to figure out the
861+
best number of models to combine. It helps to
862+
speedup if the number of models provided to the
863+
model combination binary is quite large (e.g.
864+
several hundred).""")
855865
self.parser.add_argument("--trainer.optimization.do-final-combination",
856866
dest='do_final_combination', type=str,
857867
action=common_lib.StrToBoolAction,
@@ -861,9 +871,7 @@ def __init__(self,
861871
last-numbered model as the final.mdl).""")
862872
self.parser.add_argument("--trainer.optimization.combine-sum-to-one-penalty",
863873
type=float, dest='combine_sum_to_one_penalty', default=0.0,
864-
help="""If > 0, activates 'soft' enforcement of the
865-
sum-to-one penalty in combination (may be helpful
866-
if using dropout). E.g. 1.0e-03.""")
874+
help="""This option is deprecated and does nothing.""")
867875
self.parser.add_argument("--trainer.optimization.momentum", type=float,
868876
dest='momentum', default=0.0,
869877
help="""Momentum used in update computation.

egs/wsj/s5/steps/libs/nnet3/train/frame_level_objf/common.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ def combine_models(dir, num_iters, models_to_combine, egs_dir,
452452
minibatch_size_str,
453453
run_opts,
454454
chunk_width=None, get_raw_nnet_from_am=True,
455-
sum_to_one_penalty=0.0,
455+
max_objective_evaluations=30,
456456
use_multitask_egs=False,
457457
compute_per_dim_accuracy=False):
458458
""" Function to do model combination
@@ -501,10 +501,8 @@ def combine_models(dir, num_iters, models_to_combine, egs_dir,
501501
use_multitask_egs=use_multitask_egs)
502502
common_lib.execute_command(
503503
"""{command} {combine_queue_opt} {dir}/log/combine.log \
504-
nnet3-combine --num-iters=80 \
505-
--enforce-sum-to-one={hard_enforce} \
506-
--sum-to-one-penalty={penalty} \
507-
--enforce-positive-weights=true \
504+
nnet3-combine \
505+
--max-objective-evaluations={max_objective_evaluations} \
508506
--verbose=3 {raw_models} \
509507
"ark,bg:nnet3-copy-egs {multitask_egs_opts} \
510508
{egs_rspecifier} ark:- | \
@@ -513,9 +511,8 @@ def combine_models(dir, num_iters, models_to_combine, egs_dir,
513511
""".format(command=run_opts.command,
514512
combine_queue_opt=run_opts.combine_queue_opt,
515513
dir=dir, raw_models=" ".join(raw_model_strings),
514+
max_objective_evaluations=max_objective_evaluations,
516515
egs_rspecifier=egs_rspecifier,
517-
hard_enforce=(sum_to_one_penalty <= 0),
518-
penalty=sum_to_one_penalty,
519516
mbsize=minibatch_size_str,
520517
out_model=out_model,
521518
multitask_egs_opts=multitask_egs_opts))

egs/wsj/s5/steps/nnet3/chain/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ def train(args, run_opts):
554554
l2_regularize=args.l2_regularize,
555555
xent_regularize=args.xent_regularize,
556556
run_opts=run_opts,
557-
sum_to_one_penalty=args.combine_sum_to_one_penalty)
557+
max_objective_evaluations=args.max_objective_evaluations)
558558
else:
559559
logger.info("Copying the last-numbered model to final.mdl")
560560
common_lib.force_symlink("{0}.mdl".format(num_iters),

egs/wsj/s5/steps/nnet3/train_dnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ def train(args, run_opts):
364364
models_to_combine=models_to_combine,
365365
egs_dir=egs_dir,
366366
minibatch_size_str=args.minibatch_size, run_opts=run_opts,
367-
sum_to_one_penalty=args.combine_sum_to_one_penalty)
367+
max_objective_evaluations=args.max_objective_evaluations)
368368

369369
if args.stage <= num_iters + 1:
370370
logger.info("Getting average posterior for purposes of "

egs/wsj/s5/steps/nnet3/train_raw_dnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def train(args, run_opts):
398398
models_to_combine=models_to_combine, egs_dir=egs_dir,
399399
minibatch_size_str=args.minibatch_size, run_opts=run_opts,
400400
get_raw_nnet_from_am=False,
401-
sum_to_one_penalty=args.combine_sum_to_one_penalty,
401+
max_objective_evaluations=args.max_objective_evaluations,
402402
use_multitask_egs=use_multitask_egs)
403403
else:
404404
common_lib.force_symlink("{0}.raw".format(num_iters),

egs/wsj/s5/steps/nnet3/train_raw_rnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ def train(args, run_opts):
475475
run_opts=run_opts, chunk_width=args.chunk_width,
476476
get_raw_nnet_from_am=False,
477477
compute_per_dim_accuracy=args.compute_per_dim_accuracy,
478-
sum_to_one_penalty=args.combine_sum_to_one_penalty)
478+
max_objective_evaluations=args.max_objective_evaluations)
479479
else:
480480
common_lib.force_symlink("{0}.raw".format(num_iters),
481481
"{0}/final.raw".format(args.dir))

egs/wsj/s5/steps/nnet3/train_rnn.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ def train(args, run_opts):
451451
run_opts=run_opts,
452452
minibatch_size_str=args.num_chunk_per_minibatch,
453453
chunk_width=args.chunk_width,
454-
sum_to_one_penalty=args.combine_sum_to_one_penalty,
454+
max_objective_evaluations=args.max_objective_evaluations,
455455
compute_per_dim_accuracy=args.compute_per_dim_accuracy)
456456

457457
if args.stage <= num_iters + 1:

0 commit comments

Comments
 (0)