Educational content in the form of a scientific draft that needs expert review before being adopted as an academic reference. No experimental result that was not actually run is shown here.
Definition
Two metrics of speech recognition quality that compute the edit distance (Levenshtein) between the reference text and the predicted text, divided by the reference length, at the word level (WER) or the character level (CER).
Mathematical Idea
We compute the minimum number of substitutions $S$, deletions $D$, and insertions $I$ needed to turn the hypothesis into the reference by dynamic programming, and then $\text{WER}=(S+D+I)/N$, where $N$ is the number of reference words. The rate can exceed 1 when there are many insertions. In Arabic, spelling, diacritics, and the unification of alef forms and teh marbuta affect the result, so a unified text normalization is needed before computing.
How It Works
We normalize the reference and the hypothesis (punctuation, diacritics, and letter forms).
We split into words (WER) or characters (CER).
We build the edit-distance table by dynamic programming.
We extract $S$, $D$, and $I$.
We divide the sum by the reference length $N$.
Stages Diagram
Reference text
Normalization
Alignment
S/D/I
Error rate
Equations
$$\text{WER}=\frac{S+D+I}{N}$$
$S$ is substitutions, $D$ is deletions, $I$ is insertions, and $N$ is the number of reference words.
The dynamic programming recurrence for edit distance.
Advantages
A standard and straightforward definition.
Easy to compute and compares systems.
CER suits some languages and long segments.
Limitations
Treats all errors with equal weight.
Sensitive to differences in normalization and spelling.
Does not reflect meaning.
Use Cases
Evaluating ASR systems.
Comparing models on the same set.
Monitoring improvement during development.
Applied Example
The reference is «ذهب الولد إلى المدرسة صباحا» ("The boy went to school in the morning", 5 words) and the hypothesis lacks «إلى»: $D=1$, so $\text{WER}=1/5=0.2$.
Code Example
PythonImplemented and Tested
def edit(r, h):
d = list(range(len(h) + 1))
for i in range(1, len(r) + 1):
prev, d[0] = d[0], i
for j in range(1, len(h) + 1):
cur = min(d[j] + 1, d[j-1] + 1, prev + (r[i-1] != h[j-1]))
prev, d[j] = d[j], cur
return d[-1]
ref = "ذهب الولد إلى المدرسة صباحا"
hyp = "ذهب الولد المدرسة صباحا"
wer = edit(ref.split(), hyp.split()) / len(ref.split())
cer = edit(ref, hyp) / len(ref)
print("WER =", round(wer, 3), " CER =", round(cer, 3))
Assistant Professor of Artificial Intelligence and Deep Learning
University of Al-Qadisiyah
About
Researcher and academic specialising in artificial intelligence (AI), deep learning, computer vision and natural language processing (NLP). The “Deep Learning in Arabic” project aims to enrich Arabic scientific and technical content with sound, free references and software for researchers and learners across the Arab world.
Smart Audio Assistant
I am the lab's Audio Assistant. Ask me about an algorithm, model, dataset, or experiment, and I will answer from the lab's content with links.
Smart Audio Assistant
Local mode: the lab's database
It answers from the lab's database only, without sending your question to any external party. Conversations and audio are not saved.
Smart assistant
Answers from the site’s content
The assistant can make mistakes, so check the attached sources.
Welcome! I am Dr. Alaa Taima, and this is my smart assistant on “Deep Learning in Arabic”. Ask it about any term or topic in artificial intelligence, and it will answer from the site's content with links to the sources.
DL Bot
Your smart assistant · Connecting…
Enter to send · Shift + Enter for a new line · The assistant can make mistakes, so check the sources.