Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[src] Hopefully make it possible to use empty FST in grammar-fst #3523

Merged
merged 1 commit into from
Aug 19, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/decoder/grammar-fst.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,15 @@ void GrammarFst::InitNonterminalMap() {
}


void GrammarFst::InitEntryArcs(int32 i) {
bool GrammarFst::InitEntryArcs(int32 i) {
KALDI_ASSERT(static_cast<size_t>(i) < ifsts_.size());
const ConstFst<StdArc> &fst = *(ifsts_[i].second);
if (fst.NumStates() == 0)
return false; /* this was the empty FST. */
InitEntryOrReentryArcs(fst, fst.Start(),
GetPhoneSymbolFor(kNontermBegin),
&(entry_arcs_[i]));
return true;
}

void GrammarFst::InitInstances() {
Expand Down Expand Up @@ -345,8 +348,12 @@ GrammarFst::ExpandedState *GrammarFst::ExpandStateUserDefined(
const ConstFst<StdArc> &child_fst = *(child_instance.fst);
int32 child_ifst_index = child_instance.ifst_index;
std::unordered_map<int32, int32> &entry_arcs = entry_arcs_[child_ifst_index];
if (entry_arcs.empty())
InitEntryArcs(child_ifst_index);
if (entry_arcs.empty()) {
if (!InitEntryArcs(child_ifst_index)) {
// This child-FST was the empty FST. There are no arcs to expand.
continue;
}
}
// for explanation of cost_correction, see documentation for CombineArcs().
float num_entry_arcs = entry_arcs.size(),
cost_correction = -log(num_entry_arcs);
Expand Down
5 changes: 4 additions & 1 deletion src/decoder/grammar-fst.h
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ class GrammarFst {
// too much work when it is initialized. Each call to this function only
// takes time O(number of left-context phones), which is quite small, but we'd
// like to avoid that if possible.
void InitEntryArcs(int32 i);
//
// This function returns true if it successfully initialized the
// entry_arcs_[i]; and false if it left it empty because
bool InitEntryArcs(int32 i);

// sets up instances_ with the top-level instance.
void InitInstances();
Expand Down