Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion nemo_text_processing/text_normalization/normalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ def _process_batch(batch, verbose, punct_pre_process, punct_post_process, **kwar
]
return normalized_lines

if not texts:
return []

# to save intermediate results to a file
batch = min(len(texts), batch_size)

Expand Down Expand Up @@ -520,7 +523,7 @@ def _process_batch(
logger.warning(f'Normalizing {len(lines)} line(s) of {manifest}...')

# to save intermediate results to a file
batch = min(len(lines), batch_size)
batch = max(1, min(len(lines), batch_size))

tmp_dir = "/tmp/parts"
if os.path.exists(tmp_dir):
Expand Down
22 changes: 22 additions & 0 deletions tests/nemo_text_processing/en/test_cardinal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,25 @@ def test_norm(self, test_input, expected):
punct_post_process=False,
)
assert expected in pred_non_deterministic, f"input: {test_input}"

@pytest.mark.run_only_on('CPU')
@pytest.mark.unit
def test_normalize_list_empty(self):
assert self.normalizer_en.normalize_list([]) == []
assert self.inverse_normalizer_en.inverse_normalize_list([]) == []

@pytest.mark.run_only_on('CPU')
@pytest.mark.unit
def test_normalize_manifest_empty(self, tmp_path):
manifest = tmp_path / "empty.json"
manifest.write_text("")
output = tmp_path / "empty_normalized.json"
self.normalizer_en.normalize_manifest(
manifest=str(manifest),
n_jobs=1,
punct_pre_process=True,
punct_post_process=True,
batch_size=10,
output_filename=str(output),
)
assert output.read_text() == ""