Skip to main content

Alignment and word error rate calculations

Project description

WordErrorRate.py

Alignment and word error rate calculations

Python version of WordErrorrate.jl, which, because of Julia, is much faster.

Installation

pip install git+https://github.com/davidavdav/WordErrorRate.py.git

Synopsis

Usage:

>>> import worderrorrate
>>> ## A single comparison / alignment between reference and hypothesis
>>> w = worderrorrate.WER(["this", "is", "a", "test"], "this is another".split())
>>> print(f"Full alignment:\n{w}")
Full alignment:
REF: this is a    test
HYP: this is * another
Eval    c  c d       s
>>> print("The word error rate is", w.wer())
The word error rate is 0.5
>>> refali, hypali, evalali = w.align()
>>> print("Alignment indices:", refali, hypali, evalali)
Alignment indices: [0, 1, 2, 3] [0, 1, None, 2] ['c', 'c', 'd', 's']
>>> w.nref ## number of words in the reference
4
>>> w.nhyp ## in hypothesis
3
>>> w.nsub ## substitutions
1
>>> w.nins ## insertions
0
>>> w.ndel ## deletions
1
>>> ## Aggregate over multiple pairs of reference and hypothesis
>>> ws = worderrorrate.WERs() ## multiple utterances
>>> ws.append(["this", "is", "a", "test"], "this is another".split())
>>> ws.append("a b c d".split(), "a c e".split())
>>> ws.wer()
0.5
>>> ws.nref
8
>>> ws.nhyp
6
>>> ws.nsub
2
>>> ws.nins
0
>>> ws.ndel
2

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

worderrorrate-0.1.2.tar.gz (4.5 kB view hashes)

Uploaded Source

Built Distribution

worderrorrate-0.1.2-py3-none-any.whl (5.1 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page