error-align 0.1.0b9__tar.gz → 0.1.0b10__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {error_align-0.1.0b9 → error_align-0.1.0b10}/PKG-INFO +5 -3
- {error_align-0.1.0b9 → error_align-0.1.0b10}/README.md +3 -1
- {error_align-0.1.0b9 → error_align-0.1.0b10}/poetry.lock +10 -4
- {error_align-0.1.0b9 → error_align-0.1.0b10}/pyproject.toml +2 -2
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/error_align.py +48 -4
- {error_align-0.1.0b9 → error_align-0.1.0b10}/tests/test_default.py +29 -3
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.coveragerc +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/CODEOWNERS +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/aau.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/corti.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/dtu.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/empty.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/logo.svg +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/pcai.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/assets/ucph.png +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/pull_request_template.md +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/release_drafter_main_branch.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/build_and_publish.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/build_wheels.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/label_check.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/lint.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/release_draft_main_branch.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/tests_and_coverage.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.gitignore +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.pre-commit-config.yaml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/.python-version +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/CMakeLists.txt +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/Makefile +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/codecov.yml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/cpp/beam_search.cpp +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/cpp/edit_distance.cpp +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/evaluation/evaluate_dataset.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/evaluation/monolingual_eval.sh +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/evaluation/multilingual_eval.sh +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/evaluation/prepare_primock57.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/evaluation/transcribe_dataset.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/pytest.ini +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/ruff.toml +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/__init__.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/backtrace_graph.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/__init__.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/optimal_word_alignment.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/cmudict.rep.json +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/__init__.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/contractions.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/normalize.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/numbers.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/__init__.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/aligner.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/levenshtein.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/phonemes.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/pronounce.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/punct.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/readers.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/writers.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power_alignment.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/rapidfuzz_word_alignment.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/utils.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/beam_search.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/core.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/edit_distance.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/graph_metadata.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/path_to_alignment.py +0 -0
- {error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/utils.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.2
|
|
2
2
|
Name: error-align
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.0b10
|
|
4
4
|
Summary: Text-to-text alignment algorithm for speech recognition error analysis.
|
|
5
5
|
Keywords: speech-recognition,text-alignment,NLP,evaluation
|
|
6
6
|
Author-Email: Lasse Borgholt <lb@corti.ai>
|
|
@@ -24,8 +24,8 @@ Requires-Python: <3.15,>=3.10
|
|
|
24
24
|
Requires-Dist: tqdm>=4.67.1
|
|
25
25
|
Requires-Dist: unidecode>=1.4.0
|
|
26
26
|
Requires-Dist: regex>=2025.9.18
|
|
27
|
+
Requires-Dist: rapidfuzz>=3.13.0
|
|
27
28
|
Provides-Extra: evaluation
|
|
28
|
-
Requires-Dist: rapidfuzz>=3.13.0; python_version == "3.12" and extra == "evaluation"
|
|
29
29
|
Requires-Dist: num2words>=0.5.14; python_version == "3.12" and extra == "evaluation"
|
|
30
30
|
Requires-Dist: datasets>=3.3.2; python_version == "3.12" and extra == "evaluation"
|
|
31
31
|
Requires-Dist: soundfile>=0.13.1; python_version == "3.12" and extra == "evaluation"
|
|
@@ -62,7 +62,9 @@ Description-Content-Type: text/markdown
|
|
|
62
62
|
|
|
63
63
|
**Text-to-text alignment algorithm for speech recognition error analysis.** ErrorAlign helps you dig deeper into your speech recognition projects by accurately aligning each word in a reference transcript with the model-generated transcript. Unlike traditional methods, such as Levenshtein-based alignment, it is not restricted to simple one-to-one alignment, but can map a single reference word to multiple words or subwords in the model output. This enables quick and reliable identification of error patterns in rare words, names, or domain-specific terms that matter most for your application.
|
|
64
64
|
|
|
65
|
-
→ **Update [
|
|
65
|
+
→ **Update [2026-06-22]:** As of version `0.1.0b10`, the word-level pass defaults to a faster `rapidfuzz`-based method that anchors matches from a single optimal Levenshtein alignment. On longer examples (e.g., Earnings-21), the speedup is expected to be around 30×. The original graph-based pass is still available via `error_align(ref, hyp, word_level_method="unambiguous")`.
|
|
66
|
+
|
|
67
|
+
→ **Update [2025-12-10]:** As of version `0.1.0b5`, `error-align` will include a word-level pass to efficiently identify unambiguous matches, along with C++ extensions to accelerate beam search and backtrace construction. The combined speedup is ~15× over the pure-Python implementation.
|
|
66
68
|
|
|
67
69
|
[//]: <> (https://raw.githubusercontent.com/corticph/error-align/refs/heads/main/.github/assets/logo_gpt.svg)
|
|
68
70
|
|
|
@@ -13,7 +13,9 @@
|
|
|
13
13
|
|
|
14
14
|
**Text-to-text alignment algorithm for speech recognition error analysis.** ErrorAlign helps you dig deeper into your speech recognition projects by accurately aligning each word in a reference transcript with the model-generated transcript. Unlike traditional methods, such as Levenshtein-based alignment, it is not restricted to simple one-to-one alignment, but can map a single reference word to multiple words or subwords in the model output. This enables quick and reliable identification of error patterns in rare words, names, or domain-specific terms that matter most for your application.
|
|
15
15
|
|
|
16
|
-
→ **Update [
|
|
16
|
+
→ **Update [2026-06-22]:** As of version `0.1.0b10`, the word-level pass defaults to a faster `rapidfuzz`-based method that anchors matches from a single optimal Levenshtein alignment. On longer examples (e.g., Earnings-21), the speedup is expected to be around 30×. The original graph-based pass is still available via `error_align(ref, hyp, word_level_method="unambiguous")`.
|
|
17
|
+
|
|
18
|
+
→ **Update [2025-12-10]:** As of version `0.1.0b5`, `error-align` will include a word-level pass to efficiently identify unambiguous matches, along with C++ extensions to accelerate beam search and backtrace construction. The combined speedup is ~15× over the pure-Python implementation.
|
|
17
19
|
|
|
18
20
|
[//]: <> (https://raw.githubusercontent.com/corticph/error-align/refs/heads/main/.github/assets/logo_gpt.svg)
|
|
19
21
|
|
|
@@ -8036,6 +8036,13 @@ optional = false
|
|
|
8036
8036
|
python-versions = ">=3.8"
|
|
8037
8037
|
groups = ["main", "dev"]
|
|
8038
8038
|
files = [
|
|
8039
|
+
{file = "PyYAML-6.0.3-cp38-cp38-macosx_10_13_x86_64.whl", hash = "sha256:c2514fceb77bc5e7a2f7adfaa1feb2fb311607c9cb518dbc378688ec73d8292f"},
|
|
8040
|
+
{file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:9c57bb8c96f6d1808c030b1687b9b5fb476abaa47f0db9c0101f5e9f394e97f4"},
|
|
8041
|
+
{file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_s390x.manylinux_2_17_s390x.manylinux_2_28_s390x.whl", hash = "sha256:efd7b85f94a6f21e4932043973a7ba2613b059c4a000551892ac9f1d11f5baf3"},
|
|
8042
|
+
{file = "PyYAML-6.0.3-cp38-cp38-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl", hash = "sha256:22ba7cfcad58ef3ecddc7ed1db3409af68d023b7f940da23c6c2a1890976eda6"},
|
|
8043
|
+
{file = "PyYAML-6.0.3-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:6344df0d5755a2c9a276d4473ae6b90647e216ab4757f8426893b5dd2ac3f369"},
|
|
8044
|
+
{file = "PyYAML-6.0.3-cp38-cp38-win32.whl", hash = "sha256:3ff07ec89bae51176c0549bc4c63aa6202991da2d9a6129d7aef7f1407d3f295"},
|
|
8045
|
+
{file = "PyYAML-6.0.3-cp38-cp38-win_amd64.whl", hash = "sha256:5cf4e27da7e3fbed4d6c3d8e797387aaad68102272f8f9752883bc32d61cb87b"},
|
|
8039
8046
|
{file = "pyyaml-6.0.3-cp310-cp310-macosx_10_13_x86_64.whl", hash = "sha256:214ed4befebe12df36bcc8bc2b64b396ca31be9304b8f59e25c11cf94a4c033b"},
|
|
8040
8047
|
{file = "pyyaml-6.0.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:02ea2dfa234451bbb8772601d7b8e426c2bfa197136796224e50e35a78777956"},
|
|
8041
8048
|
{file = "pyyaml-6.0.3-cp310-cp310-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl", hash = "sha256:b30236e45cf30d2b8e7b3e85881719e98507abed1011bf463a8fa23e9c3e98a8"},
|
|
@@ -8131,10 +8138,9 @@ decord = ["decord"]
|
|
|
8131
8138
|
name = "rapidfuzz"
|
|
8132
8139
|
version = "3.14.3"
|
|
8133
8140
|
description = "rapid fuzzy string matching"
|
|
8134
|
-
optional =
|
|
8141
|
+
optional = false
|
|
8135
8142
|
python-versions = ">=3.10"
|
|
8136
8143
|
groups = ["main"]
|
|
8137
|
-
markers = "python_version == \"3.12\" and extra == \"evaluation\""
|
|
8138
8144
|
files = [
|
|
8139
8145
|
{file = "rapidfuzz-3.14.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:b9fcd4d751a4fffa17aed1dde41647923c72c74af02459ad1222e3b0022da3a1"},
|
|
8140
8146
|
{file = "rapidfuzz-3.14.3-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:4ad73afb688b36864a8d9b7344a9cf6da186c471e5790cbf541a635ee0f457f2"},
|
|
@@ -11405,9 +11411,9 @@ test = ["big-O", "jaraco.functools", "jaraco.itertools", "jaraco.test", "more_it
|
|
|
11405
11411
|
type = ["pytest-mypy"]
|
|
11406
11412
|
|
|
11407
11413
|
[extras]
|
|
11408
|
-
evaluation = ["backoff", "click", "datasets", "gitpython", "librosa", "lilcom", "matplotlib", "nemo-toolkit", "num2words", "numpy", "pandas", "pyphen", "
|
|
11414
|
+
evaluation = ["backoff", "click", "datasets", "gitpython", "librosa", "lilcom", "matplotlib", "nemo-toolkit", "num2words", "numpy", "pandas", "pyphen", "scipy", "soundfile", "textgrid", "torch", "torchcodec", "torchvision", "transformers"]
|
|
11409
11415
|
|
|
11410
11416
|
[metadata]
|
|
11411
11417
|
lock-version = "2.1"
|
|
11412
11418
|
python-versions = ">=3.10,<3.15"
|
|
11413
|
-
content-hash = "
|
|
11419
|
+
content-hash = "068773cea111445347373377f2f45f8527b6ce69612f0332aec8b922b5036f81"
|
|
@@ -9,7 +9,7 @@ build-backend = "scikit_build_core.build"
|
|
|
9
9
|
|
|
10
10
|
[project]
|
|
11
11
|
name = "error-align"
|
|
12
|
-
version = "0.1.
|
|
12
|
+
version = "0.1.0b10"
|
|
13
13
|
description = "Text-to-text alignment algorithm for speech recognition error analysis."
|
|
14
14
|
readme = "README.md"
|
|
15
15
|
requires-python = ">=3.10,<3.15"
|
|
@@ -36,6 +36,7 @@ dependencies = [
|
|
|
36
36
|
"tqdm>=4.67.1",
|
|
37
37
|
"unidecode>=1.4.0",
|
|
38
38
|
"regex>=2025.9.18",
|
|
39
|
+
"rapidfuzz>=3.13.0",
|
|
39
40
|
]
|
|
40
41
|
|
|
41
42
|
[project.urls]
|
|
@@ -43,7 +44,6 @@ Homepage = "https://github.com/corticph/error-align"
|
|
|
43
44
|
|
|
44
45
|
[project.optional-dependencies]
|
|
45
46
|
evaluation = [
|
|
46
|
-
"rapidfuzz>=3.13.0; python_version == '3.12'",
|
|
47
47
|
"num2words>=0.5.14; python_version == '3.12'",
|
|
48
48
|
"datasets>=3.3.2; python_version == '3.12'",
|
|
49
49
|
"soundfile>=0.13.1; python_version == '3.12'",
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
from rapidfuzz.distance import Levenshtein
|
|
2
|
+
|
|
1
3
|
from error_align.backtrace_graph import BacktraceGraph
|
|
2
4
|
from error_align.core import compute_levenshtein_distance_matrix, error_align_beam_search
|
|
3
5
|
from error_align.graph_metadata import GraphMetadata, SubgraphMetadata
|
|
@@ -19,6 +21,7 @@ def error_align(
|
|
|
19
21
|
normalizer: callable = basic_normalizer,
|
|
20
22
|
beam_size: int = 100,
|
|
21
23
|
word_level_pass: bool = True,
|
|
24
|
+
word_level_method: str = "rapidfuzz",
|
|
22
25
|
):
|
|
23
26
|
"""Run error alignment between reference and hypothesis texts.
|
|
24
27
|
|
|
@@ -28,7 +31,10 @@ def error_align(
|
|
|
28
31
|
tokenizer (callable): A function to tokenize the sequences. Must be regex-based and return Match objects.
|
|
29
32
|
normalizer (callable): A function to normalize the tokens. Defaults to basic_normalizer.
|
|
30
33
|
beam_size (int): The beam size for beam search alignment.
|
|
31
|
-
word_level_pass (bool): Whether to perform a word-level alignment pass to
|
|
34
|
+
word_level_pass (bool): Whether to perform a word-level alignment pass to anchor matches before beam search.
|
|
35
|
+
word_level_method (str): Which word-level pass to use when ``word_level_pass`` is True. ``"rapidfuzz"``
|
|
36
|
+
(default) takes the matches from a single optimal Levenshtein alignment via rapidfuzz. ``"unambiguous"``
|
|
37
|
+
builds the full backtrace graph and only anchors matches common to all optimal paths.
|
|
32
38
|
|
|
33
39
|
"""
|
|
34
40
|
graph_metadata = prepare_graph_metadata(
|
|
@@ -42,8 +48,12 @@ def error_align(
|
|
|
42
48
|
return align_identical_inputs(graph_metadata)
|
|
43
49
|
elif not word_level_pass:
|
|
44
50
|
return align_beam_search(graph_metadata, beam_size=beam_size)
|
|
45
|
-
|
|
51
|
+
elif word_level_method == "rapidfuzz":
|
|
52
|
+
return align_with_rapidfuzz_word_level_pass(graph_metadata, beam_size=beam_size)
|
|
53
|
+
elif word_level_method == "unambiguous":
|
|
46
54
|
return align_with_word_level_pass(graph_metadata, beam_size=beam_size)
|
|
55
|
+
else:
|
|
56
|
+
raise ValueError(f"Unknown word_level_method: {word_level_method!r}")
|
|
47
57
|
|
|
48
58
|
|
|
49
59
|
def prepare_graph_metadata(
|
|
@@ -127,10 +137,44 @@ def align_with_word_level_pass(
|
|
|
127
137
|
)
|
|
128
138
|
backtrace_graph = BacktraceGraph(backtrace_matrix)
|
|
129
139
|
match_indices = backtrace_graph.get_unambiguous_node_matches()
|
|
140
|
+
return align_from_match_indices(graph_metadata, beam_size, match_indices)
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def align_with_rapidfuzz_word_level_pass(
|
|
144
|
+
graph_metadata: GraphMetadata,
|
|
145
|
+
beam_size: int,
|
|
146
|
+
) -> list[Alignment]:
|
|
147
|
+
"""Perform a word-level alignment pass using matches from a single optimal Levenshtein alignment."""
|
|
148
|
+
match_indices = get_rapidfuzz_match_indices(graph_metadata.ref_norm, graph_metadata.hyp_norm)
|
|
149
|
+
return align_from_match_indices(graph_metadata, beam_size, match_indices)
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
def get_rapidfuzz_match_indices(ref_norm: list[str], hyp_norm: list[str]) -> list[tuple[int, int]]:
|
|
153
|
+
"""Infer word-level match indices from a rapidfuzz Levenshtein alignment.
|
|
154
|
+
|
|
155
|
+
rapidfuzz only emits the non-match operations (insert/delete/replace), so matches are recovered as the
|
|
156
|
+
complement of the edited token indices. Returns ``(hyp_idx, ref_idx)`` tuples to match the convention used
|
|
157
|
+
by ``BacktraceGraph.get_unambiguous_node_matches`` and consumed by ``align_from_match_indices``.
|
|
158
|
+
"""
|
|
159
|
+
edit_ops = Levenshtein.editops(ref_norm, hyp_norm).as_list() # (op, ref_idx, hyp_idx)
|
|
160
|
+
ref_edit_idxs = {op[1] for op in edit_ops if op[0] != "insert"}
|
|
161
|
+
hyp_edit_idxs = {op[2] for op in edit_ops if op[0] != "delete"}
|
|
162
|
+
ref_match = [i for i in range(len(ref_norm)) if i not in ref_edit_idxs]
|
|
163
|
+
hyp_match = [i for i in range(len(hyp_norm)) if i not in hyp_edit_idxs]
|
|
164
|
+
# Matches are monotonic in both axes; zip the complements and swap to (hyp, ref).
|
|
165
|
+
return [(h, r) for r, h in zip(ref_match, hyp_match, strict=True)]
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def align_from_match_indices(
|
|
169
|
+
graph_metadata: GraphMetadata,
|
|
170
|
+
beam_size: int,
|
|
171
|
+
match_indices: list[tuple[int, int]],
|
|
172
|
+
) -> list[Alignment]:
|
|
173
|
+
"""Extract alignments from word-level match anchors, beam-searching the ambiguous spans between them."""
|
|
130
174
|
# NOTE: We always add an artificial terminal match node to simplify subspan extraction.
|
|
131
175
|
match_indices = match_indices + [(len(graph_metadata.hyp_norm), len(graph_metadata.ref_norm))]
|
|
132
176
|
|
|
133
|
-
# Iterate over the
|
|
177
|
+
# Iterate over the matches to extract subspans (i.e., the span of words between two matches).
|
|
134
178
|
hyp_start, ref_start = (0, 0)
|
|
135
179
|
alignments = []
|
|
136
180
|
end_index = len(match_indices) - 1
|
|
@@ -174,7 +218,7 @@ def align_with_word_level_pass(
|
|
|
174
218
|
hyp_index=hyp_end,
|
|
175
219
|
)
|
|
176
220
|
)
|
|
177
|
-
|
|
221
|
+
hyp_start, ref_start = (hyp_end + 1, ref_end + 1)
|
|
178
222
|
|
|
179
223
|
return alignments
|
|
180
224
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import pytest
|
|
1
2
|
from error_align._cpp_beam_search import error_align_beam_search as cpp_error_align_beam_search
|
|
2
3
|
from typeguard import suppress_type_checks
|
|
3
4
|
|
|
@@ -6,7 +7,7 @@ from error_align.backtrace_graph import BacktraceGraph
|
|
|
6
7
|
from error_align.beam_search import _cpp_path_to_py_path
|
|
7
8
|
from error_align.beam_search import error_align_beam_search as python_error_align_beam_search
|
|
8
9
|
from error_align.edit_distance import compute_error_align_distance_matrix, compute_levenshtein_distance_matrix
|
|
9
|
-
from error_align.error_align import prepare_graph_metadata
|
|
10
|
+
from error_align.error_align import get_rapidfuzz_match_indices, prepare_graph_metadata
|
|
10
11
|
from error_align.graph_metadata import SubgraphMetadata
|
|
11
12
|
from error_align.utils import (
|
|
12
13
|
Alignment,
|
|
@@ -19,13 +20,14 @@ from error_align.utils import (
|
|
|
19
20
|
)
|
|
20
21
|
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
@pytest.mark.parametrize("word_level_method", ["rapidfuzz", "unambiguous"])
|
|
24
|
+
def test_error_align(word_level_method: str) -> None:
|
|
23
25
|
"""Test error alignment for an example including all substitution types."""
|
|
24
26
|
|
|
25
27
|
ref = "This is a substitution test deleted."
|
|
26
28
|
hyp = "Inserted this is a contribution test."
|
|
27
29
|
|
|
28
|
-
alignments = error_align(ref, hyp)
|
|
30
|
+
alignments = error_align(ref, hyp, word_level_method=word_level_method)
|
|
29
31
|
expected_ops = [
|
|
30
32
|
OpType.INSERT, # Inserted
|
|
31
33
|
OpType.MATCH, # This
|
|
@@ -40,6 +42,30 @@ def test_error_align() -> None:
|
|
|
40
42
|
assert alignment.op_type == op
|
|
41
43
|
|
|
42
44
|
|
|
45
|
+
@pytest.mark.parametrize(
|
|
46
|
+
("ref_norm", "hyp_norm", "expected"),
|
|
47
|
+
[
|
|
48
|
+
# Replace: equal lengths, only the differing token is excluded.
|
|
49
|
+
(["this", "is", "a", "test"], ["this", "is", "a", "pest"], [(0, 0), (1, 1), (2, 2)]),
|
|
50
|
+
# Insertion: hyp longer; "b" stays matched at (hyp=2, ref=1).
|
|
51
|
+
(["a", "b"], ["a", "x", "b"], [(0, 0), (2, 1)]),
|
|
52
|
+
# Deletion: ref longer; "c" stays matched at (hyp=1, ref=2).
|
|
53
|
+
(["a", "b", "c"], ["a", "c"], [(0, 0), (1, 2)]),
|
|
54
|
+
],
|
|
55
|
+
)
|
|
56
|
+
def test_get_rapidfuzz_match_indices(ref_norm: list[str], hyp_norm: list[str], expected: list[tuple[int, int]]) -> None:
|
|
57
|
+
"""Match indices are inferred as the complement of rapidfuzz edit ops, in (hyp_idx, ref_idx) order."""
|
|
58
|
+
|
|
59
|
+
assert get_rapidfuzz_match_indices(ref_norm, hyp_norm) == expected
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_error_align_unknown_word_level_method() -> None:
|
|
63
|
+
"""An unknown word-level method raises a clear error."""
|
|
64
|
+
|
|
65
|
+
with pytest.raises(ValueError, match="Unknown word_level_method"):
|
|
66
|
+
error_align("a b c", "a x c", word_level_method="nonsense")
|
|
67
|
+
|
|
68
|
+
|
|
43
69
|
def test_beam_search_cpp_vs_python() -> None:
|
|
44
70
|
"""Test that the C++ and Python beam search implementations produce the same results."""
|
|
45
71
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/.github/workflows/release_draft_main_branch.yml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/optimal_word_alignment.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/cmudict.rep.json
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/normalize.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/normalize/numbers.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/__init__.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/aligner.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/levenshtein.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/phonemes.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/pronounce.py
RENAMED
|
File without changes
|
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/readers.py
RENAMED
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/power/power/writers.py
RENAMED
|
File without changes
|
|
File without changes
|
{error_align-0.1.0b9 → error_align-0.1.0b10}/src/error_align/baselines/rapidfuzz_word_alignment.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|