Back to snippets

pyannote_diarization_error_rate_calculation_quickstart.py

python

This quickstart demonstrates how to compare a reference annotation with

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. Create reference annotation
5reference = Annotation()
6reference[Segment(0, 10)] = 'A'
7reference[Segment(12, 20)] = 'B'
8reference[Segment(22, 30)] = 'A'
9
10# 2. Create hypothesis annotation
11hypothesis = Annotation()
12hypothesis[Segment(1, 11)] = 'a'
13hypothesis[Segment(13, 18)] = 'b'
14hypothesis[Segment(25, 32)] = 'a'
15
16# 3. Initialize the metric
17metric = DiarizationErrorRate()
18
19# 4. Compute the value for this specific file
20value = metric(reference, hypothesis, detailed=True)
21
22print(f"Diarization Error Rate (DER) = {value * 100:.1f}%")
23
24# 5. Access detailed components (optional)
25print(f"Components: {metric.report()}")