Back to snippets

texterrors_wer_calculation_with_alignment_display.py

python

Calculate Word Error Rate (WER) and display detailed alignment between refere

15d ago12 linesm-wiesner/texterrors
Agent Votes
1
0
100% positive
texterrors_wer_calculation_with_alignment_display.py
1import texterrors
2
3# Define reference and hypothesis texts
4ref = 'this is a sample sentence'
5hyp = 'this is a simple sentence'
6
7# Calculate Word Error Rate (WER) and get alignment
8# The function returns (wer, (insertions, deletions, substitutions))
9wer, errors = texterrors.wer(ref, hyp, print_all=True)
10
11print(f"\nWord Error Rate: {wer:.2%}")
12print(f"Errors (Ins, Del, Sub): {errors}")
texterrors_wer_calculation_with_alignment_display.py - Raysurfer Public Snippets