-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Extending 'lattice-compose.cc' to compose with ark of fsts, #4692
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
Changes from 1 commit
b887460
f185670
7dc3723
cb6f272
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,6 +1,7 @@ | ||||||
| // latbin/lattice-compose.cc | ||||||
|
|
||||||
| // Copyright 2009-2011 Microsoft Corporation; Saarland University | ||||||
| // 2022 Brno University of Technology | ||||||
|
|
||||||
| // See ../../COPYING for clarification regarding multiple authors | ||||||
| // | ||||||
|
|
@@ -17,7 +18,6 @@ | |||||
| // See the Apache 2 License for the specific language governing permissions and | ||||||
| // limitations under the License. | ||||||
|
|
||||||
|
|
||||||
| #include "base/kaldi-common.h" | ||||||
| #include "util/common-utils.h" | ||||||
| #include "fstext/fstext-lib.h" | ||||||
|
|
@@ -39,22 +39,34 @@ int main(int argc, char *argv[]) { | |||||
| "or lattices with FSTs (rspecifiers are assumed to be lattices, and\n" | ||||||
| "rxfilenames are assumed to be FSTs, which have their weights interpreted\n" | ||||||
| "as \"graph weights\" when converted into the Lattice format.\n" | ||||||
| "Or, rspecifier can be ark of biasing FSTs, see --compose-with-fst=true.\n" | ||||||
| "\n" | ||||||
| "Usage: lattice-compose [options] lattice-rspecifier1 " | ||||||
| "(lattice-rspecifier2|fst-rxfilename2) lattice-wspecifier\n" | ||||||
| " e.g.: lattice-compose ark:1.lats ark:2.lats ark:composed.lats\n" | ||||||
| " or: lattice-compose ark:1.lats G.fst ark:composed.lats\n"; | ||||||
| " or: lattice-compose ark:1.lats G.fst ark:composed.lats\n" | ||||||
| " or: lattice-compose --compose-with-fst=true ark:1.lats\n" | ||||||
| " ark:biasing.fsts ark:composed.lats\n"; | ||||||
|
|
||||||
| ParseOptions po(usage); | ||||||
|
|
||||||
| bool write_compact = true; | ||||||
| int32 num_states_cache = 50000; | ||||||
| int32 phi_label = fst::kNoLabel; // == -1 | ||||||
| int32 rho_label = fst::kNoLabel; // == -1 | ||||||
| std::string compose_with_fst = "auto"; | ||||||
|
|
||||||
| po.Register("write-compact", &write_compact, "If true, write in normal (compact) form."); | ||||||
| po.Register("phi-label", &phi_label, "If >0, the label on backoff arcs of the LM"); | ||||||
| po.Register("rho-label", &rho_label, | ||||||
| "If >0, the label to forward fst1 paths not present biasing graph fst2. " | ||||||
| "(rho is input and output symbol on special arc in biasing graph)"); | ||||||
|
||||||
| po.Register("num-states-cache", &num_states_cache, | ||||||
| "Number of states we cache when mapping LM FST to lattice type. " | ||||||
| "More -> more memory but faster."); | ||||||
| po.Register("compose-with-fst", &compose_with_fst, | ||||||
| "(true|false|auto) For auto arg2 is: rspecifier=lats, rxfilename=fst " | ||||||
| "(old behavior), for true/false rspecifier is fst/lattice."); | ||||||
| po.Read(argc, argv); | ||||||
|
|
||||||
| if (po.NumArgs() != 3) { | ||||||
|
|
@@ -63,14 +75,30 @@ int main(int argc, char *argv[]) { | |||||
| } | ||||||
|
|
||||||
| KALDI_ASSERT(phi_label > 0 || phi_label == fst::kNoLabel); // e.g. 0 not allowed. | ||||||
| KALDI_ASSERT(rho_label > 0 || rho_label == fst::kNoLabel); // e.g. 0 not allowed. | ||||||
| if (phi_label > 0 && rho_label > 0) { | ||||||
| KALDI_ERR << "You cannot set both 'phi_label' and 'rho_label' at the same time."; | ||||||
| } | ||||||
|
|
||||||
| { // convert 'compose_with_fst' to lowercase to support: true, True, TRUE | ||||||
| std::string tmp_lc(compose_with_fst); | ||||||
| std::transform(compose_with_fst.begin(), compose_with_fst.end(), | ||||||
| tmp_lc.begin(), ::tolower); // lc | ||||||
|
||||||
| tmp_lc.begin(), ::tolower); // lc | |
| compose_with_fst.begin(), std::tolower); // lc |
It can be an in-place operation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see a strange behavior, the std::tolower version produces error:
/usr/local/include/c++/9.4.0/bits/stl_algo.h:4369:5: note: template argument deduction/substitution failed:
lattice-compose.cc:87:71: note: candidate expects 5 arguments, 4 provided
87 | std::transform(str.begin(), str.end(), str.begin(), std::tolower); // lc
i found that i can go-around it by wrapping it into lambda:
[](unsigned char c){ return std::tolower(c);}
but that looks quite complicated compared to ::tolower which compiles well,
and i saw it used in: util/parse-options.cc and nnet/nnet-component.cc ...
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Would you mind formatting the else in a more standard way that won't upset auto-formatters?
E.g.
} else {
/* comment here */
}
.. I see why you did what you did, but let's be consistent with other code.
Are you confident that this won't break existing code?
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| else if (not arg2_is_rxfilename && | |
| else if (!arg2_is_rxfilename && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole message is not very clear, especially with the modification. Can write:
Depending on the command-line arguments, either composes lattices with lattices,
or lattices with a single FST or multiple FSTs (whose weights are interpreted as "graph weights").
Then change the lines below to: