From 04029871b6a54e35d08116917f88eb7d6ead2d02 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Tue, 9 Nov 2021 13:44:51 +0800 Subject: [PATCH] Fix a bug in Nbest.compute_am_scores and Nbest.compute_lm_scores. (#111) --- icefall/decode.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/icefall/decode.py b/icefall/decode.py index d11920618..8b7bdd27f 100644 --- a/icefall/decode.py +++ b/icefall/decode.py @@ -364,7 +364,13 @@ class Nbest(object): Return a ragged tensor with 2 axes [utt][path_scores]. Its dtype is torch.float64. """ - saved_scores = self.fsa.scores + # Caution: We need a clone here. `self.fsa.scores` is a + # reference to a tensor representing the last field of an arc + # in the FSA (Remeber that an arc has four fields.) If we later assign + # `self.fsa.scores`, it will also change the scores on every arc, which + # means saved_scores will also be changed if we don't use `clone()` + # here. + saved_scores = self.fsa.scores.clone() # The `scores` of every arc consists of `am_scores` and `lm_scores` self.fsa.scores = self.fsa.scores - self.fsa.lm_scores @@ -391,10 +397,10 @@ class Nbest(object): Return a ragged tensor with 2 axes [utt][path_scores]. Its dtype is torch.float64. """ - saved_scores = self.fsa.scores + saved_scores = self.fsa.scores.clone() # The `scores` of every arc consists of `am_scores` and `lm_scores` - self.fsa.scores = self.fsa.lm_scores + self.fsa.scores = self.fsa.lm_scores.clone() lm_scores = self.fsa.get_tot_scores( use_double_scores=True, log_semiring=False