From ecec40dbeeed86b3fe9ac0d6c37ed97729661bec Mon Sep 17 00:00:00 2001 From: Vitaly Lavrukhin Date: Wed, 24 May 2023 13:43:11 -0700 Subject: [PATCH 1/2] Replaced jiwer with editdistance to speed up CER estimation Signed-off-by: Vitaly Lavrukhin --- .../text_normalization/normalize_with_audio.py | 4 ++-- requirements/requirements.txt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/nemo_text_processing/text_normalization/normalize_with_audio.py b/nemo_text_processing/text_normalization/normalize_with_audio.py index a6dacf049..1d99eeca1 100644 --- a/nemo_text_processing/text_normalization/normalize_with_audio.py +++ b/nemo_text_processing/text_normalization/normalize_with_audio.py @@ -18,7 +18,7 @@ from time import perf_counter from typing import List, Optional, Tuple -import jiwer +import editdistance import pynini from nemo_text_processing.text_normalization.data_loader_utils import post_process_punct, pre_process from nemo_text_processing.text_normalization.normalize import Normalizer @@ -406,7 +406,7 @@ def calculate_cer(normalized_texts: List[str], pred_text: str, remove_punct=Fals for punct in "!?:;,.-()*+-/<=>@^_": text_clean = text_clean.replace(punct, " ").replace(" ", " ") - cer = jiwer.cer(pred_text, text_clean) * 100 + cer = editdistance.eval(pred_text, text_clean) * 100. / len(pred_text) normalized_options.append((text, cer, i)) return normalized_options diff --git a/requirements/requirements.txt b/requirements/requirements.txt index b3ed551f0..8c8de986e 100644 --- a/requirements/requirements.txt +++ b/requirements/requirements.txt @@ -1,6 +1,6 @@ cdifflib +editdistance inflect -jiwer>2.3.0 joblib pandas pynini==2.1.5 From ab90ca5af9f2c2e3fbcde8dad7c68503d1a654ef Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 24 May 2023 22:16:18 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- nemo_text_processing/text_normalization/normalize_with_audio.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nemo_text_processing/text_normalization/normalize_with_audio.py b/nemo_text_processing/text_normalization/normalize_with_audio.py index 1d99eeca1..f232c04df 100644 --- a/nemo_text_processing/text_normalization/normalize_with_audio.py +++ b/nemo_text_processing/text_normalization/normalize_with_audio.py @@ -406,7 +406,7 @@ def calculate_cer(normalized_texts: List[str], pred_text: str, remove_punct=Fals for punct in "!?:;,.-()*+-/<=>@^_": text_clean = text_clean.replace(punct, " ").replace(" ", " ") - cer = editdistance.eval(pred_text, text_clean) * 100. / len(pred_text) + cer = editdistance.eval(pred_text, text_clean) * 100.0 / len(pred_text) normalized_options.append((text, cer, i)) return normalized_options