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

Add metrics/wer #63

Merged
merged 45 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
9dfe74e
Init commit
Mar 13, 2023
6ccad69
Init commit
Mar 13, 2023
880640c
Fix relative imports
Mar 13, 2023
481c0e0
Format with black
Mar 14, 2023
3b45f52
Remove redundant parameters
Mar 17, 2023
890725d
Refactor differ class
Mar 17, 2023
667e9c3
Reformat with black
Mar 17, 2023
c8a863d
Refactor class and format with black
Mar 17, 2023
4e0bcd7
Refactor class and format with black
Mar 17, 2023
d40152a
Add more-itertools
Mar 17, 2023
d56d1ff
refactor whisper normalizers for linting
Mar 17, 2023
a29d3a1
Move metrics dir
May 18, 2023
6c892f4
Merge branch 'master' into add-metrics/wer
May 18, 2023
0aedcae
Update README
May 18, 2023
e216866
Add example transcripts for WER
May 18, 2023
b8ed94a
add diarization metrics
May 18, 2023
7f93bdb
Merge branch 'add-metrics/wer' of gitlab1.speechmatics.io:python/spee…
May 18, 2023
1e997a3
update README
May 18, 2023
16b2836
update README
May 18, 2023
1af64e6
update README
May 18, 2023
b68df72
Fix issue with printing the errors
May 18, 2023
70888e8
Add installation / usage guidance
May 18, 2023
c938023
Fix issue with the README
May 18, 2023
2e3b09e
update utils to parse jsons in the same format the transcriber returns
May 18, 2023
70ae7d4
Merge branch 'add-metrics/wer' of gitlab1.speechmatics.io:python/spee…
May 18, 2023
2cf6ba9
update version in setup.py
May 18, 2023
d03631a
Merge branch 'master' into add-metrics/wer
Nov 2, 2023
c5921cd
Add metrics dir to linting, package, requirements
Nov 9, 2023
978ce77
Init Commit
Nov 9, 2023
db23627
Ignore virtual environment
Nov 9, 2023
4282586
Formatting
Nov 9, 2023
b25a6ad
Move wer scripts into dedicated dir
Nov 9, 2023
7956e4b
Add examples
Nov 9, 2023
582aae0
Update diarization README
Nov 9, 2023
9fcc69d
Update metrics entrypoint
Nov 9, 2023
e81cb15
Fix ctm format, fix normalizers
Nov 9, 2023
fafec79
Merge branch 'master' into add-metrics/wer
Nov 9, 2023
141513e
Add top level README for metrics
Nov 15, 2023
8879e2a
Update metrics READMEs
Nov 15, 2023
9f40f3f
Update READMEs + changelog
Nov 16, 2023
55ea02b
Skip empty files, improve printing
Nov 24, 2023
9083aec
Improve handling of disfluencies
Nov 29, 2023
e0eda99
Allow using SM JSON for metrics
Nov 29, 2023
bca7ac5
Modify disfluencies
Nov 30, 2023
56778d6
Bump version
Dec 7, 2023
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ target/

# pyenv
.python-version
venv

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SOURCES := speechmatics/ tests/ examples/ setup.py
SOURCES := speechmatics/ tests/ examples/ metrics/ setup.py
VERSION ?= $(shell cat VERSION)

.PHONY: all
Expand Down
47 changes: 47 additions & 0 deletions metrics/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SM Metrics

We provide some additional tooling to help benchmark transcription and diarization performance.

## Getting Started

### CLI

The `sm-metrics` binary is built after installing with PyPI or running `python3 setup.py` from the source code. To see the options from the command-line, use the following:
``` bash
sm-metrics -h
```

### Source Code

When executing directly from the source code:
```bash
python3 -m metrics.cli -h
```

## What's Included?

### Transcription Metrics

This includes tools to:
- Normalise transcripts
- Calculate Word Error Rate and Character Error Rate
- Calculate the number of substitutions, deletions and insertions for a given ASR transcript
- Visualise the alignment and differences between a reference and ASR transcript

### Diarization Metrics

This includes tools to calculate a number of metrics used in benchmarking diarization, including:

- Diarization Error Rate
- Segmentation precision, recall and F1-Scores
- Word Diarization Error Rate

## Documentation

More extensive information on the metrics themselves, as well as how to run them can be found on the READMEs.

For diarization, we provide an additional PDF.

## Support

If you have any issues with this library or encounter any bugs then please get in touch with us at [email protected] or raise an issue for this repo.
Empty file added metrics/__init__.py
Empty file.
36 changes: 36 additions & 0 deletions metrics/cli.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
"""Entrypoint for SM metrics"""
import argparse

import metrics.diarization.sm_diarization_metrics.cookbook as diarization_metrics
import metrics.wer.__main__ as wer_metrics


def main():
parser = argparse.ArgumentParser(description="Your CLI description")

# Create subparsers
subparsers = parser.add_subparsers(
dest="mode", help="Metrics mode. Choose from 'wer' or 'diarization"
)
subparsers.required = True # Make sure a subparser id always provided

wer_parser = subparsers.add_parser("wer", help="Entrypoint for WER metrics")
wer_metrics.get_wer_args(wer_parser)

diarization_parser = subparsers.add_parser(
"diarization", help="Entrypoint for diarization metrics"
)
diarization_metrics.get_diarization_args(diarization_parser)

args = parser.parse_args()

if args.mode == "wer":
wer_metrics.main(args)
elif args.mode == "diarization":
diarization_metrics.main(args)
else:
print("Unsupported mode. Please use 'wer' or 'diarization'")


if __name__ == "__main__":
main()
13 changes: 13 additions & 0 deletions metrics/diarization/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
clean_files := .deps .deps-dev build dist

.PHONY: clean
clean:
$(RM) -rf $(clean_files)

.PHONY: wheel
wheel:
(pip install wheel && python3 setup.py bdist_wheel)

.PHONY: install
install:
pip install ./dist/*
81 changes: 81 additions & 0 deletions metrics/diarization/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# SM Diarisation Metrics

## Getting Started

This project is Speechmatics' fork of https://github.com/pyannote/pyannote-metrics used to calculate various speaker diarization metrics from reference/hypothesis transcript pairs.

### Run from PyPI

```
pip install speechmatics-python
```

This package has a CLI supporting ctm, lab, or V2 JSON format transcripts and can be run using:

```bash
sm-metrics diarization <reference file> <hypothesis file>
```

For further guidance run:

```
sm-metrics diarization -h
```

### Run from source code

If you would prefer to clone the repo and run the source code, that can be done as follows.

Clone the repository and install package:
```bash
git clone https://github.com/speechmatics/speechmatics-python.git && cd speechmatics-python && python setup.py install
```

And run directly:
```
python3 -m metrics.cli <reference file> <transcript_file>
```



## Permitted Formats

### CTM

Plain text file with the '.ctm' extension. Each line is of the form:
```
<file id> <speaker> <start time> <end time> <word> <confidence>
```

### LAB

Plain text file with the '.lab' extension. Each line is of the form:
```
<start time> <end time> <speaker>
```

### JSON (Diarisation Reference format)

JSON file of the form:

```json
[
{
"speaker_name": "Speaker 1",
"word": "Seems",
"start": 0.75,
"duration": 0.29
},
]

```

### JSON (Speechmatics ASR Output)

V2 JSON output of Speechmatics ASR can be directly used as a hypothesis for diarization metrics

## Docs

Further description of how to use the tool and the metrics available are in sm_diarization_metrics.pdf

When using the PDF, be aware that it assumes you are running the source code directly from `./metrics/diarization`
4 changes: 4 additions & 0 deletions metrics/diarization/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pyannote.core
pyannote.database
docopt
tabulate
34 changes: 34 additions & 0 deletions metrics/diarization/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
"""Package module."""

import os

from pip._internal.req import parse_requirements
from setuptools import find_packages, setup

requirements = parse_requirements("./requirements.txt", session=False)

git_tag = os.environ.get("CI_COMMIT_TAG")
if git_tag:
assert git_tag.startswith("diarization-metrics")
version = git_tag.lstrip("diarization-metrics/") if git_tag else "0.0.3"


def read(fname):
return open(os.path.join(os.path.dirname(__file__), fname)).read()


setup(
author="Speechmatics",
author_email="[email protected]",
description="Python module for evaluating speaker diarization.",
install_requires=[str(r.requirement) for r in requirements],
name="speechmatics_diarization_metrics",
license="Speechmatics Proprietary License",
packages=find_packages(exclude=("tests",)),
platforms=["linux"],
python_requires=">=3.5",
version=version,
long_description=read("README.md"),
long_description_content_type="text/markdown",
)
Binary file added metrics/diarization/sm_diarisation_metrics.pdf
Binary file not shown.
Empty file.
Loading
Loading