Skip to content

Commit

Permalink
Allow --global for --cer in CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
nikvaessen committed May 5, 2024
1 parent 7dfd008 commit 547a6e3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
31 changes: 20 additions & 11 deletions jiwer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,19 +96,28 @@ def cli(

if not global_alignment and len(reference_sentences) != len(hypothesis_sentences):
raise ValueError(
f"Number of sentences does not match. "
f"{reference_file} contains {len(reference_sentences)} lines."
f"{hypothesis_file} contains {len(hypothesis_sentences)} lines."
f"Number of reference sentences "
f"({len(reference_sentences)} in '{reference_file}') "
f"and hypothesis sentences "
f"({len(hypothesis_sentences)} in '{hypothesis_file}') "
f"do not match! "
f"Use the `--global` flag to compute the measures over a global alignment "
f"of the reference and hypothesis sentences."
)

if global_alignment and compute_cer:
raise ValueError("--global and --cer are mutually exclusive.")

if compute_cer:
out = jiwer.process_characters(
reference_sentences,
hypothesis_sentences,
)
if global_alignment:
out = jiwer.process_characters(
reference_sentences,
hypothesis_sentences,
reference_transform=jiwer.cer_contiguous,
hypothesis_transform=jiwer.cer_contiguous,
)
else:
out = jiwer.process_characters(
reference_sentences,
hypothesis_sentences,
)
else:
if global_alignment:
out = jiwer.process_words(
Expand All @@ -121,7 +130,7 @@ def cli(
out = jiwer.process_words(reference_sentences, hypothesis_sentences)

if show_alignment:
print(jiwer.visualize_alignment(out, show_measures=True))
print(jiwer.visualize_alignment(out, show_measures=True), end="")
else:
if compute_cer:
print(out.cer)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jiwer"
version = "3.0.3"
version = "3.0.4"
description = "Evaluate your speech-to-text system with similarity measures such as word error rate (WER)"
authors = ["Nik Vaessen <nikvaes@gmail.com>"]
readme = "README.md"
Expand Down

0 comments on commit 547a6e3

Please sign in to comment.