Skip to content

Commit

Permalink
[src,scripts] fix various typos and errors in comments (#3454)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored and danpovey committed Aug 13, 2019
1 parent 662dc57 commit 1ff668a
Show file tree
Hide file tree
Showing 78 changed files with 253 additions and 254 deletions.
2 changes: 1 addition & 1 deletion egs/wsj/s5/utils/apply_map.pl
Expand Up @@ -45,7 +45,7 @@
Usage: apply_map.pl [options] map <input >output
options: [-f <field-range> ] [--permissive]
This applies a map to some specified fields of some input text:
For each line in the map file: the first field is the thing wae
For each line in the map file: the first field is the thing we
map from, and the remaining fields are the sequence we map it to.
The -f (field-range) option says which fields of the input file the map
map should apply to.
Expand Down
10 changes: 5 additions & 5 deletions egs/wsj/s5/utils/int2sym.pl
Expand Up @@ -7,12 +7,12 @@


if ($ARGV[0] eq "-f") {
shift @ARGV;
$field_spec = shift @ARGV;
shift @ARGV;
$field_spec = shift @ARGV;
if ($field_spec =~ m/^\d+$/) {
$field_begin = $field_spec - 1; $field_end = $field_spec - 1;
}
if ($field_spec =~ m/^(\d*)[-:](\d*)/) { # accept e.g. 1:10 as a courtesty (properly, 1-10)
if ($field_spec =~ m/^(\d*)[-:](\d*)/) { # accept e.g. 1:10 as a courtesy (properly, 1-10)
if ($1 ne "") {
$field_begin = $1 - 1; # Change to zero-based indexing.
}
Expand All @@ -21,12 +21,12 @@
}
}
if (!defined $field_begin && !defined $field_end) {
die "Bad argument to -f option: $field_spec";
die "Bad argument to -f option: $field_spec";
}
}
$symtab = shift @ARGV;
if(!defined $symtab) {
print STDERR "Usage: sym2int.pl [options] symtab [input] > output\n" .
print STDERR "Usage: int2sym.pl [options] symtab [input] > output\n" .
"options: [-f (<field>|<field_start>-<field-end>)]\n" .
"e.g.: -f 2, or -f 3-4\n";
exit(1);
Expand Down
2 changes: 1 addition & 1 deletion egs/wsj/s5/utils/prepare_lang.sh
Expand Up @@ -269,7 +269,7 @@ fi
# add_lex_disambig.pl is responsible for adding disambiguation symbols to
# the lexicon, for telling us how many disambiguation symbols it used,
# and and also for modifying the unknown-word's pronunciation (if the
# and also for modifying the unknown-word's pronunciation (if the
# --unk-fst was provided) to the sequence "#1 #2 #3", and reserving those
# disambig symbols for that purpose.
# The #2 will later be replaced with the actual unk model. The reason
Expand Down
10 changes: 5 additions & 5 deletions egs/wsj/s5/utils/sym2int.pl
Expand Up @@ -19,7 +19,7 @@

for($x = 0; $x < 2; $x++) {
if ($ARGV[0] eq "--map-oov") {
shift @ARGV;
shift @ARGV;
$map_oov = shift @ARGV;
if ($map_oov eq "-f" || $map_oov =~ m/words\.txt$/ || $map_oov eq "") {
# disallow '-f', the empty string and anything ending in words.txt as the
Expand All @@ -29,11 +29,11 @@
}
if ($ARGV[0] eq "-f") {
shift @ARGV;
$field_spec = shift @ARGV;
$field_spec = shift @ARGV;
if ($field_spec =~ m/^\d+$/) {
$field_begin = $field_spec - 1; $field_end = $field_spec - 1;
}
if ($field_spec =~ m/^(\d*)[-:](\d*)/) { # accept e.g. 1:10 as a courtesty (properly, 1-10)
if ($field_spec =~ m/^(\d*)[-:](\d*)/) { # accept e.g. 1:10 as a courtesy (properly, 1-10)
if ($1 ne "") {
$field_begin = $1 - 1; # Change to zero-based indexing.
}
Expand All @@ -42,7 +42,7 @@
}
}
if (!defined $field_begin && !defined $field_end) {
die "Bad argument to -f option: $field_spec";
die "Bad argument to -f option: $field_spec";
}
}
}
Expand Down Expand Up @@ -98,7 +98,7 @@
print "\n";
}
if ($num_warning > 0) {
print STDERR "** Replaced $num_warning instances of OOVs with $map_oov\n";
print STDERR "** Replaced $num_warning instances of OOVs with $map_oov\n";
}

exit(0);
2 changes: 1 addition & 1 deletion src/base/kaldi-math.cc
Expand Up @@ -121,7 +121,7 @@ int32 RandInt(int32 min_val, int32 max_val, struct RandomState* state) {
}

// Returns poisson-distributed random number.
// Take care: this takes time proportinal
// Take care: this takes time proportional
// to lambda. Faster algorithms exist but are more complex.
int32 RandPoisson(float lambda, struct RandomState* state) {
// Knuth's algorithm.
Expand Down
7 changes: 4 additions & 3 deletions src/base/kaldi-math.h
Expand Up @@ -180,7 +180,7 @@ inline Float RandPrune(Float post, BaseFloat prune_thresh,
(RandUniform(state) <= fabs(post)/prune_thresh ? prune_thresh : 0.0);
}


// returns log(exp(x) + exp(y)).
inline double LogAdd(double x, double y) {
double diff;

Expand All @@ -202,6 +202,7 @@ inline double LogAdd(double x, double y) {
}


// returns log(exp(x) + exp(y)).
inline float LogAdd(float x, float y) {
float diff;

Expand All @@ -223,7 +224,7 @@ inline float LogAdd(float x, float y) {
}


// returns exp(x) - exp(y).
// returns log(exp(x) - exp(y)).
inline double LogSub(double x, double y) {
if (y >= x) { // Throws exception if y>=x.
if (y == x)
Expand All @@ -242,7 +243,7 @@ inline double LogSub(double x, double y) {
}


// returns exp(x) - exp(y).
// returns log(exp(x) - exp(y)).
inline float LogSub(float x, float y) {
if (y >= x) { // Throws exception if y>=x.
if (y == x)
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/Makefile
Expand Up @@ -14,6 +14,6 @@ LIBNAME = kaldi-decoder
ADDLIBS = ../lat/kaldi-lat.a ../fstext/kaldi-fstext.a ../hmm/kaldi-hmm.a \
../transform/kaldi-transform.a ../gmm/kaldi-gmm.a \
../tree/kaldi-tree.a ../util/kaldi-util.a ../matrix/kaldi-matrix.a \
../base/kaldi-base.a
../base/kaldi-base.a

include ../makefiles/default_rules.mk
8 changes: 4 additions & 4 deletions src/decoder/decodable-mapped.h
Expand Up @@ -44,20 +44,20 @@ class DecodableMapped: public DecodableInterface {
KALDI_ASSERT(static_cast<size_t>(state_index) < index_map_.size());
return decodable_->LogLikelihood(frame, index_map_[state_index]);
}

// note: indices are assumed to be numbered from one, so
// NumIndices() will be the same as the largest index.
virtual int32 NumIndices() const { return static_cast<int32>(index_map_.size()) - 1; }

virtual bool IsLastFrame(int32 frame) const {
// We require all the decodables have the same #frames. We don't check this though.
return decodable_->IsLastFrame(frame);
}
}

private:
std::vector<int32> index_map_;
DecodableInterface *decodable_;

KALDI_DISALLOW_COPY_AND_ASSIGN(DecodableMapped);
};

Expand Down
4 changes: 1 addition & 3 deletions src/decoder/decodable-matrix.h
Expand Up @@ -154,10 +154,8 @@ class DecodableMatrixMappedOffset: public DecodableInterface {
DecodableMatrixMappedOffset(const TransitionModel &tm):
trans_model_(tm), frame_offset_(0), input_is_finished_(false) { }

virtual int32 NumFramesReady() { return frame_offset_ + loglikes_.NumRows(); }

// this is not part of the generic Decodable interface.
int32 FirstAvailableFrame() { return frame_offset_; }
int32 FirstAvailableFrame() const { return frame_offset_; }

// Logically, this function appends 'loglikes' (interpreted as newly available
// frames) to the log-likelihoods stored in the class.
Expand Down
6 changes: 1 addition & 5 deletions src/decoder/decodable-sum.h
Expand Up @@ -49,7 +49,7 @@ class DecodableSum: public DecodableInterface {
const std::vector<std::pair<DecodableInterface*, BaseFloat> > &decodables) :
decodables_(decodables) { CheckSizes(); }

void CheckSizes() {
void CheckSizes() const {
KALDI_ASSERT(decodables_.size() >= 1
&& decodables_[0].first != NULL);
for (size_t i = 1; i < decodables_.size(); i++)
Expand All @@ -67,10 +67,6 @@ class DecodableSum: public DecodableInterface {
iter != decodables_.end();
++iter) {
sum += iter->first->LogLikelihood(frame, state_index) * iter->second;
// BaseFloat tmp = iter->first->LogLikelihood(frame, state_index);
// KALDI_LOG << "ITEM " << i << " contributed with loglike=" << tmp << " scaled by=" << iter->second;
// i+=1;
// sum += tmp * iter->second;
}
return sum;
}
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/decoder-wrappers.cc
Expand Up @@ -34,7 +34,7 @@ DecodeUtteranceLatticeFasterClass::DecodeUtteranceLatticeFasterClass(
DecodableInterface *decodable,
const TransitionModel &trans_model,
const fst::SymbolTable *word_syms,
std::string utt,
const std::string &utt,
BaseFloat acoustic_scale,
bool determinize,
bool allow_partial,
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/decoder-wrappers.h
Expand Up @@ -131,7 +131,7 @@ class DecodeUtteranceLatticeFasterClass {
DecodableInterface *decodable,
const TransitionModel &trans_model,
const fst::SymbolTable *word_syms,
std::string utt,
const std::string &utt,
BaseFloat acoustic_scale,
bool determinize,
bool allow_partial,
Expand Down
16 changes: 8 additions & 8 deletions src/decoder/faster-decoder.cc
Expand Up @@ -70,12 +70,12 @@ void FasterDecoder::AdvanceDecoding(DecodableInterface *decodable,
while (num_frames_decoded_ < target_frames_decoded) {
// note: ProcessEmitting() increments num_frames_decoded_
double weight_cutoff = ProcessEmitting(decodable);
ProcessNonemitting(weight_cutoff);
}
ProcessNonemitting(weight_cutoff);
}
}


bool FasterDecoder::ReachedFinal() {
bool FasterDecoder::ReachedFinal() const {
for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail) {
if (e->val->cost_ != std::numeric_limits<double>::infinity() &&
fst_.Final(e->key) != Weight::Zero())
Expand Down Expand Up @@ -178,7 +178,7 @@ double FasterDecoder::GetCutoff(Elem *list_head, size_t *tok_count,
double beam_cutoff = best_cost + config_.beam,
min_active_cutoff = std::numeric_limits<double>::infinity(),
max_active_cutoff = std::numeric_limits<double>::infinity();

if (tmp_array_.size() > static_cast<size_t>(config_.max_active)) {
std::nth_element(tmp_array_.begin(),
tmp_array_.begin() + config_.max_active,
Expand All @@ -189,7 +189,7 @@ double FasterDecoder::GetCutoff(Elem *list_head, size_t *tok_count,
if (adaptive_beam)
*adaptive_beam = max_active_cutoff - best_cost + config_.beam_delta;
return max_active_cutoff;
}
}
if (tmp_array_.size() > static_cast<size_t>(config_.min_active)) {
if (config_.min_active == 0) min_active_cutoff = best_cost;
else {
Expand Down Expand Up @@ -231,12 +231,12 @@ double FasterDecoder::ProcessEmitting(DecodableInterface *decodable) {
&adaptive_beam, &best_elem);
KALDI_VLOG(3) << tok_cnt << " tokens active.";
PossiblyResizeHash(tok_cnt); // This makes sure the hash is always big enough.

// This is the cutoff we use after adding in the log-likes (i.e.
// for the next frame). This is a bound on the cutoff we will use
// on the next frame.
double next_weight_cutoff = std::numeric_limits<double>::infinity();

// First process the best token to get a hopefully
// reasonably tight bound on the next cutoff.
if (best_elem) {
Expand Down Expand Up @@ -302,7 +302,7 @@ double FasterDecoder::ProcessEmitting(DecodableInterface *decodable) {

// TODO: first time we go through this, could avoid using the queue.
void FasterDecoder::ProcessNonemitting(double cutoff) {
// Processes nonemitting arcs for one frame.
// Processes nonemitting arcs for one frame.
KALDI_ASSERT(queue_.empty());
for (const Elem *e = toks_.GetList(); e != NULL; e = e->tail)
queue_.push_back(e);
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/faster-decoder.h
Expand Up @@ -76,7 +76,7 @@ class FasterDecoder {
void Decode(DecodableInterface *decodable);

/// Returns true if a final state was active on the last frame.
bool ReachedFinal();
bool ReachedFinal() const;

/// GetBestPath gets the decoding traceback. If "use_final_probs" is true
/// AND we reached a final state, it limits itself to final states;
Expand Down
2 changes: 1 addition & 1 deletion src/decoder/lattice-faster-online-decoder.h
Expand Up @@ -84,7 +84,7 @@ class LatticeFasterOnlineDecoderTpl:
// is one less than you might reasonably expect, e.g. it's -1 for
// the nonemitting transitions before the first frame.
BestPathIterator(void *t, int32 f): tok(t), frame(f) { }
bool Done() { return tok == NULL; }
bool Done() const { return tok == NULL; }
};


Expand Down
2 changes: 1 addition & 1 deletion src/decoder/lattice-simple-decoder.h
Expand Up @@ -79,7 +79,7 @@ class LatticeSimpleDecoder {
typedef Arc::Label Label;
typedef Arc::StateId StateId;
typedef Arc::Weight Weight;
// instantiate this class onece for each thing you have to decode.
// instantiate this class once for each thing you have to decode.
LatticeSimpleDecoder(const fst::Fst<fst::StdArc> &fst,
const LatticeSimpleDecoderConfig &config):
fst_(fst), config_(config), num_toks_(0) { config.Check(); }
Expand Down
6 changes: 3 additions & 3 deletions src/decoder/simple-decoder.cc
Expand Up @@ -76,7 +76,7 @@ void SimpleDecoder::AdvanceDecoding(DecodableInterface *decodable,
ProcessEmitting(decodable);
ProcessNonemitting();
PruneToks(beam_, &cur_toks_);
}
}
}

bool SimpleDecoder::ReachedFinal() const {
Expand Down Expand Up @@ -188,7 +188,7 @@ void SimpleDecoder::ProcessEmitting(DecodableInterface *decodable) {
if (arc.ilabel != 0) { // propagate..
BaseFloat acoustic_cost = -decodable->LogLikelihood(frame, arc.ilabel);
double total_cost = tok->cost_ + arc.weight.Value() + acoustic_cost;

if (total_cost > cutoff) continue;
if (total_cost + beam_ < cutoff)
cutoff = total_cost + beam_;
Expand Down Expand Up @@ -224,7 +224,7 @@ void SimpleDecoder::ProcessNonemitting() {
best_cost = std::min(best_cost, iter->second->cost_);
}
double cutoff = best_cost + beam_;

while (!queue.empty()) {
StateId state = queue.back();
queue.pop_back();
Expand Down
20 changes: 10 additions & 10 deletions src/decoder/simple-decoder.h
Expand Up @@ -40,7 +40,7 @@ class SimpleDecoder {
typedef StdArc::Weight StdWeight;
typedef StdArc::Label Label;
typedef StdArc::StateId StateId;

SimpleDecoder(const fst::Fst<fst::StdArc> &fst, BaseFloat beam): fst_(fst), beam_(beam) { }

~SimpleDecoder();
Expand All @@ -62,9 +62,9 @@ class SimpleDecoder {
// It returns true if the output lattice was nonempty (i.e. had states in it);
// using the return value is deprecated.
bool GetBestPath(Lattice *fst_out, bool use_final_probs = true) const;

/// *** The next functions are from the "new interface". ***

/// FinalRelativeCost() serves the same function as ReachedFinal(), but gives
/// more information. It returns the difference between the best (final-cost plus
/// cost) of any token on the final frame, and the best cost of any token
Expand All @@ -75,17 +75,17 @@ class SimpleDecoder {
/// InitDecoding initializes the decoding, and should only be used if you
/// intend to call AdvanceDecoding(). If you call Decode(), you don't need
/// to call this. You can call InitDecoding if you have already decoded an
/// utterance and want to start with a new utterance.
void InitDecoding();
/// utterance and want to start with a new utterance.
void InitDecoding();

/// This will decode until there are no more frames ready in the decodable
/// object, but if max_num_frames is >= 0 it will decode no more than
/// that many frames. If it returns false, then no tokens are alive,
/// which is a kind of error state.
void AdvanceDecoding(DecodableInterface *decodable,
int32 max_num_frames = -1);
/// Returns the number of frames already decoded.

/// Returns the number of frames already decoded.
int32 NumFramesDecoded() const { return num_frames_decoded_; }

private:
Expand Down Expand Up @@ -134,18 +134,18 @@ class SimpleDecoder {
void ProcessEmitting(DecodableInterface *decodable);

void ProcessNonemitting();

unordered_map<StateId, Token*> cur_toks_;
unordered_map<StateId, Token*> prev_toks_;
const fst::Fst<fst::StdArc> &fst_;
BaseFloat beam_;
// Keep track of the number of frames decoded in the current file.
int32 num_frames_decoded_;

static void ClearToks(unordered_map<StateId, Token*> &toks);

static void PruneToks(BaseFloat beam, unordered_map<StateId, Token*> *toks);

KALDI_DISALLOW_COPY_AND_ASSIGN(SimpleDecoder);
};

Expand Down

0 comments on commit 1ff668a

Please sign in to comment.