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

move to rapidfuzz library #71

Merged
merged 1 commit into from
Mar 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 7 additions & 9 deletions jiwer/measures.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,19 @@
The following measures are implemented:

- Word Error Rate (WER), which is where this library got its name from. This
has has long been (and arguably still is) the de facto standard for computing
has long been (and arguably still is) the de facto standard for computing
ASR performance.
- Match Error Rate (MER)
- Word Information Lost (WIL)
- Word Information Preserved (WIP)
"""
import warnings

import Levenshtein
import rapidfuzz

from typing import Any, Dict, List, Tuple, Union
from itertools import chain

from jiwer import transforms as tr
from jiwer.transformations import wer_default, wer_standardize, cer_default_transform
from jiwer.transformations import wer_default, cer_default_transform

__all__ = [
"wer",
Expand Down Expand Up @@ -365,11 +363,11 @@ def _get_operation_counts(
:param destination_string: the destination to transform the source string into
:return: a tuple of #hits, #substitutions, #deletions, #insertions
"""
editops = Levenshtein.editops(source_string, destination_string)
editops = rapidfuzz.distance.Levenshtein.editops(source_string, destination_string)

substitutions = sum(1 if op[0] == "replace" else 0 for op in editops)
deletions = sum(1 if op[0] == "delete" else 0 for op in editops)
insertions = sum(1 if op[0] == "insert" else 0 for op in editops)
substitutions = sum(1 if op.tag == "replace" else 0 for op in editops)
deletions = sum(1 if op.tag == "delete" else 0 for op in editops)
insertions = sum(1 if op.tag == "insert" else 0 for op in editops)
hits = len(source_string) - (substitutions + deletions)

return hits, substitutions, deletions, insertions
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "jiwer"
version = "2.5.0"
version = "2.5.1"
description = "Evaluate your speech-to-text system with similarity measures such as word error rate (WER)"
authors = ["Nik Vaessen <nikvaes@gmail.com>"]
readme = "README.md"
Expand All @@ -10,11 +10,11 @@ include = ["LICENCE"]

[tool.poetry.dependencies]
python = "^3.7"
levenshtein = "0.20.2"
rapidfuzz = "2.13.7"

[tool.poetry.group.dev.dependencies]
black = "^22.8.0"
pytest = "^7.1.3"
pytest = "7.1.3"
pytest-benchmark = "^3.4.1"
flake8 = "^5.0.4"

Expand Down