Skip to content

Commit

Permalink
Patch decoding for PC models (#6630) (#6631)
Browse files Browse the repository at this point in the history
* Patch decoding logic for PC models



* Patch decoding logic for PC models



---------

Signed-off-by: smajumdar <[email protected]>
Co-authored-by: Somshubra Majumdar <[email protected]>
  • Loading branch information
2 people authored and yaoyu-33 committed May 26, 2023
1 parent 4b363ce commit 67b1906
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions nemo/collections/asr/metrics/rnnt_wer.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

import copy
import re
from abc import abstractmethod
from dataclasses import dataclass, is_dataclass
from typing import Callable, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -499,6 +500,10 @@ def decode_hypothesis(self, hypotheses_list: List[Hypothesis]) -> List[Union[Hyp
else:
hypothesis = self.decode_tokens_to_str(prediction)

# TODO: remove
# collapse leading spaces before . , ? for PC models
hypothesis = re.sub(r'(\s+)([\.\,\?])', r'\2', hypothesis)

if self.compute_hypothesis_token_set:
hypotheses_list[ind].tokens = self.decode_ids_to_tokens(prediction)

Expand Down
5 changes: 5 additions & 0 deletions nemo/collections/asr/metrics/wer.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
from abc import abstractmethod
from dataclasses import dataclass, is_dataclass
from typing import Callable, Dict, List, Optional, Tuple, Union
Expand Down Expand Up @@ -540,6 +541,10 @@ def decode_hypothesis(
else:
hypothesis = self.decode_tokens_to_str(decoded_prediction)

# TODO: remove
# collapse leading spaces before . , ? for PC models
hypothesis = re.sub(r'(\s+)([\.\,\?])', r'\2', hypothesis)

# Preserve this wrapped hypothesis or decoded text tokens.
hypotheses_list[ind].text = hypothesis

Expand Down

0 comments on commit 67b1906

Please sign in to comment.