Skip to content

Commit 60fa225

Browse files
Apply suggestions from code review
Adding suggestions from code review. Co-authored-by: Cy 'kkm' Katsnelson <[email protected]>
1 parent f184046 commit 60fa225

File tree

3 files changed

+38
-29
lines changed

3 files changed

+38
-29
lines changed

egs/wsj/s5/steps/nnet3/decode_compose.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ echo "$0 $@" # Print the command line for logging
4848
if [ $# -ne 3 ]; then
4949
echo "Usage: $0 [options] <graph-dir> <data-dir> <decode-dir>"
5050
echo "e.g.: steps/nnet3/decode.sh --nj 8 \\"
51-
echo "--online-ivector-dir exp/nnet2_online/ivectors_test_eval92 \\"
51+
echo " --online-ivector-dir exp/nnet2_online/ivectors_test_eval92 \\"
5252
echo " exp/tri4b/graph_bg data/test_eval92_hires $dir/decode_bg_eval92"
5353
echo "main options (for others, see top of script file)"
5454
echo " --config <config-file> # config containing options"
@@ -67,7 +67,7 @@ fi
6767
graphdir=$1
6868
data=$2
6969
dir=$3
70-
srcdir=`dirname $dir`; # Assume model directory one level up from decoding directory.
70+
srcdir=$(dirname $dir) # Assume model directory one level up from decoding directory.
7171
model=$srcdir/$iter.mdl
7272

7373
[ -z "$boosting_graphs" ] && echo "Error, \$boosting_graphs have to be set !" && exit 1

src/latbin/lattice-compose-fsts.cc

+17-11
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ int main(int argc, char *argv[]) {
4747

4848
bool write_compact = true;
4949
int32 num_states_cache = 50000;
50-
int32 phi_label = fst::kNoLabel; // == -1
51-
po.Register("write-compact", &write_compact, "If true, write in normal (compact) form.");
52-
po.Register("phi-label", &phi_label, "If >0, the label on backoff arcs of the LM");
50+
int32 phi_label = fst::kNoLabel; // == -1
51+
po.Register("write-compact", &write_compact,
52+
"If true, write in normal (compact) form.");
53+
po.Register("phi-label", &phi_label,
54+
"If >0, the label on backoff arcs of the LM");
5355
po.Register("num-states-cache", &num_states_cache,
54-
"Number of states we cache when mapping LM FST to lattice type. "
55-
"More -> more memory but faster.");
56+
"Number of states we cache when mapping LM FST to lattice type."
57+
" More -> more memory but faster.");
5658
po.Read(argc, argv);
5759

5860
if (po.NumArgs() != 3) {
@@ -72,10 +74,11 @@ int main(int argc, char *argv[]) {
7274
CompactLatticeWriter compact_lattice_writer;
7375
LatticeWriter lattice_writer;
7476

75-
if (write_compact)
77+
if (write_compact) {
7678
compact_lattice_writer.Open(lats_wspecifier);
77-
else
79+
} else {
7880
lattice_writer.Open(lats_wspecifier);
81+
}
7982

8083
if (ClassifyRspecifier(arg2, NULL, NULL) == kNoRspecifier) {
8184
std::string fst_rxfilename = arg2;
@@ -105,8 +108,11 @@ int main(int argc, char *argv[]) {
105108
Lattice lat1 = lattice_reader1.Value();
106109
ArcSort(&lat1, fst::OLabelCompare<LatticeArc>());
107110
Lattice composed_lat;
108-
if (phi_label > 0) PhiCompose(lat1, mapped_fst2, phi_label, &composed_lat);
109-
else Compose(lat1, mapped_fst2, &composed_lat);
111+
if (phi_label > 0) {
112+
PhiCompose(lat1, mapped_fst2, phi_label, &composed_lat);
113+
} else {
114+
Compose(lat1, mapped_fst2, &composed_lat);
115+
}
110116
if (composed_lat.Start() == fst::kNoStateId) {
111117
KALDI_WARN << "Empty lattice for utterance " << key << " (incompatible LM?)";
112118
n_fail++;
@@ -123,7 +129,7 @@ int main(int argc, char *argv[]) {
123129
}
124130
delete fst2;
125131
} else {
126-
// composing with each utterance with different fst,
132+
// Compose each utterance with its matching (by key) FST.
127133
std::string fst_rspecifier2 = arg2;
128134
RandomAccessTableReader<fst::VectorFstHolder> fst_reader2(fst_rspecifier2);
129135

@@ -135,7 +141,7 @@ int main(int argc, char *argv[]) {
135141

136142
if (!fst_reader2.HasKey(key)) {
137143
KALDI_WARN << "Not producing output for utterance " << key
138-
<< " because not present in second table.";
144+
<< " because it's not present in second table.";
139145
n_fail++;
140146
continue;
141147
}

src/nnet3bin/nnet3-latgen-faster-compose.cc

+19-16
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,20 @@
2020
// limitations under the License.
2121

2222

23+
#include <fst/compose.h>
24+
#include <fst/rmepsilon.h>
25+
26+
#include <memory>
27+
2328
#include "base/kaldi-common.h"
24-
#include "util/common-utils.h"
25-
#include "tree/context-dep.h"
26-
#include "hmm/transition-model.h"
27-
#include "fstext/fstext-lib.h"
29+
#include "base/timer.h"
2830
#include "decoder/decoder-wrappers.h"
31+
#include "fstext/fstext-lib.h"
32+
#include "hmm/transition-model.h"
2933
#include "nnet3/nnet-am-decodable-simple.h"
3034
#include "nnet3/nnet-utils.h"
31-
#include "base/timer.h"
32-
33-
#include <fst/compose.h>
34-
#include <fst/rmepsilon.h>
35-
#include <memory>
35+
#include "tree/context-dep.h"
36+
#include "util/common-utils.h"
3637

3738

3839
int main(int argc, char *argv[]) {
@@ -121,9 +122,10 @@ int main(int argc, char *argv[]) {
121122
CompactLatticeWriter compact_lattice_writer;
122123
LatticeWriter lattice_writer;
123124
if (! (determinize ? compact_lattice_writer.Open(lattice_wspecifier)
124-
: lattice_writer.Open(lattice_wspecifier)))
125+
: lattice_writer.Open(lattice_wspecifier))) {
125126
KALDI_ERR << "Could not open table for writing lattices: "
126-
<< lattice_wspecifier;
127+
<< lattice_wspecifier;
128+
}
127129

128130
RandomAccessBaseFloatMatrixReader online_ivector_reader(
129131
online_ivector_rspecifier);
@@ -213,13 +215,13 @@ int main(int argc, char *argv[]) {
213215

214216
timer_compose.Reset();
215217

216-
// RmEpsilon saved 30% of composition runtime...
218+
// RmEpsilon saved 30% of composition runtime.
217219
// - Note: we are loading 2-state graphs with eps back-link to the initial state.
218220
if (boosting_fst.Properties(fst::kIEpsilons, true) != 0) {
219221
fst::RmEpsilon(&boosting_fst);
220222
}
221223

222-
// make sure boosting graph is sorted on ilabel,
224+
// Make sure boosting graph is sorted on ilabel.
223225
if (boosting_fst.Properties(fst::kILabelSorted, true) == 0) {
224226
fst::ILabelCompare<StdArc> ilabel_comp;
225227
fst::ArcSort(&boosting_fst, ilabel_comp);
@@ -267,7 +269,9 @@ int main(int argc, char *argv[]) {
267269
tot_like += like;
268270
frame_count += nnet_decodable.NumFramesReady();
269271
num_success++;
270-
} else num_fail++;
272+
} else {
273+
++num_fail;
274+
}
271275
}
272276
}
273277

@@ -286,8 +290,7 @@ int main(int argc, char *argv[]) {
286290
<< (tot_like / frame_count) << " over "
287291
<< frame_count << " frames.";
288292

289-
if (num_success != 0) return 0;
290-
else return 1;
293+
return num_success != 0 ? 0 : 1;
291294
} catch(const std::exception &e) {
292295
std::cerr << e.what();
293296
return -1;

0 commit comments

Comments
 (0)