Skip to main content

A simple commandline tool for calculating WERs.

Project description

simple-wer

A simple command line tool to calculate WER for ASR.

Installation

pip install simple-wer

Python API Usage

from simple_wer import simple_wer

# results is a list of (utterance_id, reference_words, hypothesis_words)
results = [
    ("utt1", ["I", "LOVE", "YOU"], ["i", "LOVE", "YOU"]),
    ("utt2", ["I", "HATE", "YOU"], ["I", "hate", "YOU"]),
]

# Use with custom logdir and test name
simple_wer(results, logdir="logs", test_name="my_test")

# Or let logdir default to a temp directory and test_name to current timestamp
simple_wer(results)

The results parameter is a list of tuples, each containing:

  • utterance_id (str): unique identifier for the utterance
  • reference (list[str]): reference transcript as a list of words
  • hypothesis (list[str]): hypothesis transcript as a list of words

When logdir is None (default), a temporary directory is created automatically. When test_name is None (default), the current timestamp (microsecond precision) is used.

Command Line Usage

$ simple-wer --help
Usage: simple-wer [OPTIONS] REFS HYPS

  The shell entry point to simple-wer, a simple tool to calculate WERs for
  ASR.

  The ``refs`` and ``hyps`` are the paths for references and hypothesis, their
  format should be ``utt_id \t refenence/hypothesis``.

Options:
  --test-name TEXT  The name for current test, it is used to distinguish the
                    file names for different tests.
  --logdir TEXT     The directory to write the WER results.
  --help            Show this message and exit.

For example:

The refs.txt contains:

1       I LOVE YOU
2       I HATE YOU

The hyps.txt contains:

1       i LOVE YOU
2       I hate YOU

Run the following command:

simple-wer --test-name example refs.txt hyps.txt

The logs look like:

2023-05-16 11:16:05,253 INFO [simple_wer.py:21] The transcripts are stored in logs/recogs-example.txt
2023-05-16 11:16:05,255 INFO [simple_wer.py:123] [example] %WER 33.33% [2 / 6, 0 ins, 0 del, 2 sub ]
2023-05-16 11:16:05,257 INFO [simple_wer.py:29] Wrote detailed error stats to logs/errs-example.txt

There will be two files (recogs-example.txt and errs-example.txt) in logs,

recogs-example.txt looks like:

1:      ref=['I', 'LOVE', 'YOU']
1:      hyp=['i', 'LOVE', 'YOU']

2:      ref=['I', 'HATE', 'YOU']
2:      hyp=['I', 'hate', 'YOU']

errs-example.txt looks like:

%WER = 33.33
Errors: 0 insertions, 0 deletions, 2 substitutions, over 6 reference words (4 correct)
Search below for sections starting with PER-UTT DETAILS:, SUBSTITUTIONS:, DELETIONS:, INSERTIONS:, PER-WORD STATS:

PER-UTT DETAILS: corr or (ref->hyp)  
1:      (I->i) LOVE YOU
2:      I (HATE->hate) YOU

SUBSTITUTIONS: count ref -> hyp
1   I -> i
1   HATE -> hate

DELETIONS: count ref

INSERTIONS: count hyp

PER-WORD STATS: word  corr tot_errs count_in_ref count_in_hyp
i   0 1 0 1
hate   0 1 0 1
I   1 1 2 1
HATE   0 1 1 0
YOU   2 0 2 2
LOVE   1 0 1 1

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

simple_wer-0.3.2.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simple_wer-0.3.2-py3-none-any.whl (12.3 kB view details)

Uploaded Python 3

File details

Details for the file simple_wer-0.3.2.tar.gz.

File metadata

  • Download URL: simple_wer-0.3.2.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for simple_wer-0.3.2.tar.gz
Algorithm Hash digest
SHA256 70d683209fb19532b5c5b5bda713216c286328d15d77dbcf56bd0600e42a9dc9
MD5 80c5b991eb2e6b2e50d7df3f6669595f
BLAKE2b-256 d55ad211633191e824185d8db87374876aa0d6953ee704ead8222d6e279ae1ae

See more details on using hashes here.

File details

Details for the file simple_wer-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: simple_wer-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for simple_wer-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9073563202254713facc43f53495bd17aae6df1276e2d8b21628645685ee13ff
MD5 64df5bbc9d0d16c73be1df2e091204f2
BLAKE2b-256 07a7c0252955108d56c13078b86d445602097bff99c49dfb4293f657ef25d777

See more details on using hashes here.

Supported by

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