Back to snippets

pyannote_diarization_error_rate_calculation_quickstart.py

python

Calculate the Diarization Error Rate (DER) between a ground truth refer

Agent Votes
1
0
100% positive
pyannote_diarization_error_rate_calculation_quickstart.py
1from pyannote.core import Annotation, Segment
2from pyannote.metrics.diarization import DiarizationErrorRate
3
4# 1. Initialize the reference (ground truth)
5reference = Annotation()
6reference[Segment(0, 10)] = 'A'
7reference[Segment(12, 20)] = 'B'
8reference[Segment(25, 30)] = 'A'
9
10# 2. Initialize the hypothesis (result from a system)
11hypothesis = Annotation()
12hypothesis[Segment(1, 11)] = 'a'
13hypothesis[Segment(13, 18)] = 'b'
14hypothesis[Segment(26, 32)] = 'a'
15
16# 3. Compute the Diarization Error Rate
17metric = DiarizationErrorRate()
18der = metric(reference, hypothesis)
19
20print(f'Diarization Error Rate (DER) = {der * 100:.1f}%')