Files
ea18bc70d8 Align audio CI and releases; require Python 3.11 (#2081)
* feat(cli): add --subfolder option to benchmark command (#2063)
* fix(utils): fix `SpeakerDiarizationMixin.optimal_mapping` when `reference` is a mapping
* fix(task): fix `balance` option crashing training with `KeyError: 'metadata'` (#2067)
* fix(io): fix `Audio.crop` raising when an in-memory waveform is cropped up to its very end (#2068)
* fix(model): make Model.default_activation return identity for unsupported tasks
* fix: compute sample duration from preloaded waveform
* fix(pipeline): omit unset runtime options from model references (#2080)

Co-authored-by: abeeranajam31 <128603901+abeeranajam31@users.noreply.github.com>
Co-authored-by: antoinelaurent <antoinelaurent@me.com>
Co-authored-by: Kayvan Zahiri <123409429+Kayvan-Zahiri@users.noreply.github.com>
Co-authored-by: Mohammad Hijjawi <51020382+MohammadHijjawi97@users.noreply.github.com>
2026-10-22 15:07:01 +02:00

77 lines
2.6 KiB
Python

# MIT License
#
# Copyright (c) 2026- pyannoteAI
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import pytest
from pyannote.core import Annotation, Segment, Timeline
from pyannote.metrics.diarization import DiarizationErrorRate
from pyannote.audio.pipelines.utils.diarization import SpeakerDiarizationMixin
@pytest.fixture
def reference():
annotation = Annotation()
annotation[Segment(0, 10)] = "A"
annotation[Segment(12, 20)] = "B"
annotation[Segment(24, 27)] = "A"
annotation[Segment(30, 40)] = "C"
return annotation
@pytest.fixture
def hypothesis():
annotation = Annotation()
annotation[Segment(2, 13)] = "a"
annotation[Segment(13, 14)] = "d"
annotation[Segment(14, 20)] = "b"
annotation[Segment(22, 38)] = "c"
annotation[Segment(38, 40)] = "d"
return annotation
@pytest.fixture
def annotated():
return Timeline([Segment(10, 20)])
def test_optimal_mapping_accepts_mapping(reference, hypothesis):
_, mapping = SpeakerDiarizationMixin.optimal_mapping(
{"annotation": reference}, hypothesis, return_mapping=True
)
assert mapping == {"a": "A", "b": "B", "c": "C"}
def test_optimal_mapping_uses_annotated_as_uem(reference, hypothesis, annotated):
_, mapping = SpeakerDiarizationMixin.optimal_mapping(
{"annotation": reference, "annotated": annotated},
hypothesis,
return_mapping=True,
)
expected = DiarizationErrorRate().optimal_mapping(
reference, hypothesis, uem=annotated
)
assert mapping == expected
# the UEM is not cosmetic: it changes which labels can be mapped
assert mapping != DiarizationErrorRate().optimal_mapping(reference, hypothesis)