Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Case insensitive #675

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions kraken/ketos/recognition.py
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ def test(ctx, batch_size, model, evaluation_files, device, pad, workers,

cer_list = []
wer_list = []
cer_case_insensitive_list=[]

with threadpool_limits(limits=threads):
for p, net in nn.items():
Expand Down Expand Up @@ -518,6 +519,7 @@ def test(ctx, batch_size, model, evaluation_files, device, pad, workers,
collate_fn=collate_sequences)

test_cer = CharErrorRate()
test_cer_case_insensitive = CharErrorRate()
test_wer = WordErrorRate()

with KrakenProgressBar() as progress:
Expand All @@ -537,6 +539,8 @@ def test(ctx, batch_size, model, evaluation_files, device, pad, workers,
algn_pred.extend(algn2)
error += c
test_cer.update(x, y)
# Update case-insensitive CER metric
test_cer_case_insensitive.update(x.lower(), y.lower())
test_wer.update(x, y)

except FileNotFoundError as e:
Expand All @@ -550,12 +554,14 @@ def test(ctx, batch_size, model, evaluation_files, device, pad, workers,
progress.update(pred_task, advance=1)

cer_list.append(1.0 - test_cer.compute())
cer_case_insensitive_list.append(1.0 - test_cer_case_insensitive.compute())
wer_list.append(1.0 - test_wer.compute())
confusions, scripts, ins, dels, subs = compute_confusions(algn_gt, algn_pred)
rep = render_report(p,
chars,
error,
cer_list[-1],
cer_case_insensitive_list[-1],
wer_list[-1],
confusions,
scripts,
Expand Down
2 changes: 2 additions & 0 deletions kraken/serialization.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ def render_report(model: str,
chars: int,
errors: int,
char_accuracy: float,
char_CI_accucary: float, #Case insensitive
word_accuracy: float,
char_confusions: 'Counter',
scripts: 'Counter',
Expand Down Expand Up @@ -278,6 +279,7 @@ def render_report(model: str,
'chars': chars,
'errors': errors,
'character_accuracy': char_accuracy * 100,
'character_CI_accucary': char_CI_accucary * 100,
'word_accuracy': word_accuracy * 100,
'insertions': sum(insertions.values()),
'deletions': deletions,
Expand Down
1 change: 1 addition & 0 deletions kraken/templates/report
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
{{ report.chars }} Characters
{{ report.errors }} Errors
{{ '%0.2f'| format(report.character_accuracy) }}% Character Accuracy
{{ '%0.2f'| format(report.character_CI_accucary) }}% Character Accuracy (Case-insensitive)
{{ '%0.2f'| format(report.word_accuracy) }}% Word Accuracy

{{ report.insertions }} Insertions
Expand Down