The MIT License (MIT)
Copyright (c) 2014 CNRS
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.
AUTHORS
Hervé Bredin -- http://herve.niderb.fr
from pyannote.core import Annotation, Segment
reference = Annotation()
reference[Segment(0, 1)] = 'SHELDON'
reference[Segment(1, 2)] = 'PENNY'
reference[Segment(3, 4)] = 'LEONARD'
reference[Segment(4, 6)] = 'SHELDON'
reference
hypothesis = Annotation()
hypothesis[Segment(0.2, 1.2)] = 'SHELDON'
hypothesis[Segment(1.2, 1.9)] = 'PENNY'
hypothesis[Segment(2.8, 4)] = 'LEONARD'
hypothesis[Segment(4, 5)] = 'SHELDON'
hypothesis[Segment(5.1, 6)] = 'RAJ'
hypothesis
Speech activity detection results are reported using three complementary evaluation metrics.
The Detection error rate (DER) is the ratio of the duration incorrectly classified as speech (false alarm) or non-speech (missed detection) over the total duration of speech in the episode:
$\displaystyle \text{DER} = \frac{\text{miss} + \text{fa}}{\text{total}}$
where:
from pyannote.metrics.detection import DetectionErrorRate
detectionErrorRate = DetectionErrorRate()
d = detectionErrorRate(reference, hypothesis)
print 'Detection error rate: {d:.1f}%'.format(d=100*d)
Using detailed=True, we get more details:
details = detectionErrorRate(reference, hypothesis, detailed=True)
details
Precision is the ratio of the total duration reported as speech that is indeed annotated as speech in the reference annotation.
from pyannote.metrics.detection import DetectionPrecision
detectionPrecision = DetectionPrecision()
p = detectionPrecision(reference, hypothesis)
print 'Detection precision: {p:.1f}%'.format(p=100*p)
Recall is the ratio of the total duration of speech according to the reference annotation that is is indeed detected as speech in the hypothesis.
from pyannote.metrics.detection import DetectionRecall
detectionRecall = DetectionRecall()
r = detectionRecall(reference, hypothesis)
print 'Detection recall: {r:.1f}%'.format(r=100*r)
from pyannote.metrics import f_measure
print 'Detection f-measure: {f:.1f}%'.format(f=100*f_measure(p, r))
Speaker identification results are reported using Identification error rate (IER), defined as follows:
$\displaystyle \text{IER} = \frac{\text{miss} + \text{fa} + \text{confusion}}{\text{total}}$
where
In other words, it is a compound metric that accounts for both speech turns detection and identification errors.
from pyannote.metrics.identification import IdentificationErrorRate
identificationErrorRate = IdentificationErrorRate()
i = identificationErrorRate(reference, hypothesis)
print 'Identification error rate: {i:.1f}%'.format(i=100*i)
Using detailed=True, we get more details:
identificationErrorRate(reference, hypothesis, detailed=True)
Standard precision and recall metrics are also available for identification.
from pyannote.metrics.identification import IdentificationPrecision
precision = IdentificationPrecision()
p = precision(reference, hypothesis)
print 'Identification precision: {p:.1f}%'.format(p=100*p)
from pyannote.metrics.identification import IdentificationRecall
recall = IdentificationRecall()
r = recall(reference, hypothesis)
print 'Identification recall: {r:.1f}%'.format(r=100*r)
An in-depth analysis or identification errors is also available.
from pyannote.metrics.errors.identification import IdentificationErrorAnalysis
identificationErrorAnalysis = IdentificationErrorAnalysis()
identificationErrorAnalysis.matrix(reference, hypothesis)
Finally, here is the list of errors, sorted from the most to the least frequent, along with their duration.
identificationErrorAnalysis.annotation(reference, hypothesis).chart()