From 68506609ad1b36a3a0faeb142d3ff54f0e3608d9 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 16 Nov 2021 23:11:30 +0800 Subject: [PATCH] Set fsa.properties to None after changing its labels in-place. (#121) --- egs/librispeech/ASR/conformer_ctc/decode.py | 3 +++ egs/librispeech/ASR/conformer_mmi/decode.py | 3 +++ egs/librispeech/ASR/local/compile_hlg.py | 3 +++ egs/librispeech/ASR/tdnn_lstm_ctc/decode.py | 3 +++ egs/yesno/ASR/local/compile_hlg.py | 3 +++ 5 files changed, 15 insertions(+) diff --git a/egs/librispeech/ASR/conformer_ctc/decode.py b/egs/librispeech/ASR/conformer_ctc/decode.py index 01d636f13..96f6134f1 100755 --- a/egs/librispeech/ASR/conformer_ctc/decode.py +++ b/egs/librispeech/ASR/conformer_ctc/decode.py @@ -607,6 +607,9 @@ def main(): # Arcs entering the back-off state have label equal to #0. # We have to change it to 0 here. G.labels[G.labels >= first_word_disambig_id] = 0 + # See https://github.com/k2-fsa/k2/issues/874 + # for why we need to set G.properties to None + G.__dict__["_properties"] = None G = k2.Fsa.from_fsas([G]).to(device) G = k2.arc_sort(G) # Save a dummy value so that it can be loaded in C++. diff --git a/egs/librispeech/ASR/conformer_mmi/decode.py b/egs/librispeech/ASR/conformer_mmi/decode.py index 79012c98f..a77168b62 100755 --- a/egs/librispeech/ASR/conformer_mmi/decode.py +++ b/egs/librispeech/ASR/conformer_mmi/decode.py @@ -603,6 +603,9 @@ def main(): # Arcs entering the back-off state have label equal to #0. # We have to change it to 0 here. G.labels[G.labels >= first_word_disambig_id] = 0 + # See https://github.com/k2-fsa/k2/issues/874 + # for why we need to set G.properties to None + G.__dict__["_properties"] = None G = k2.Fsa.from_fsas([G]).to(device) G = k2.arc_sort(G) torch.save(G.as_dict(), params.lm_dir / "G_4_gram.pt") diff --git a/egs/librispeech/ASR/local/compile_hlg.py b/egs/librispeech/ASR/local/compile_hlg.py index 098d5d6a3..9a35750e0 100755 --- a/egs/librispeech/ASR/local/compile_hlg.py +++ b/egs/librispeech/ASR/local/compile_hlg.py @@ -101,6 +101,9 @@ def compile_HLG(lang_dir: str) -> k2.Fsa: logging.info("Removing disambiguation symbols on LG") LG.labels[LG.labels >= first_token_disambig_id] = 0 + # See https://github.com/k2-fsa/k2/issues/874 + # for why we need to set LG.properties to None + LG.__dict__["_properties"] = None assert isinstance(LG.aux_labels, k2.RaggedTensor) LG.aux_labels.values[LG.aux_labels.values >= first_word_disambig_id] = 0 diff --git a/egs/librispeech/ASR/tdnn_lstm_ctc/decode.py b/egs/librispeech/ASR/tdnn_lstm_ctc/decode.py index f44164f44..72ee2ff0b 100755 --- a/egs/librispeech/ASR/tdnn_lstm_ctc/decode.py +++ b/egs/librispeech/ASR/tdnn_lstm_ctc/decode.py @@ -422,6 +422,9 @@ def main(): # Arcs entering the back-off state have label equal to #0. # We have to change it to 0 here. G.labels[G.labels >= first_word_disambig_id] = 0 + # See https://github.com/k2-fsa/k2/issues/874 + # for why we need to set G.properties to None + G.__dict__["_properties"] = None G = k2.Fsa.from_fsas([G]).to(device) G = k2.arc_sort(G) torch.save(G.as_dict(), params.lm_dir / "G_4_gram.pt") diff --git a/egs/yesno/ASR/local/compile_hlg.py b/egs/yesno/ASR/local/compile_hlg.py index 9b6a4c5ba..f83be05cf 100755 --- a/egs/yesno/ASR/local/compile_hlg.py +++ b/egs/yesno/ASR/local/compile_hlg.py @@ -79,6 +79,9 @@ def compile_HLG(lang_dir: str) -> k2.Fsa: logging.info("Removing disambiguation symbols on LG") LG.labels[LG.labels >= first_token_disambig_id] = 0 + # See https://github.com/k2-fsa/k2/issues/874 + # for why we need to set LG.properties to None + LG.__dict__["_properties"] = None assert isinstance(LG.aux_labels, k2.RaggedTensor) LG.aux_labels.values[LG.aux_labels.values >= first_word_disambig_id] = 0