speechbrain.utils.EDER module

Calculates Emotion Diarization Error Rate (EDER) which is the sum of Missed Emotion (ME), False Alarm (FA), and Confusion (CF).

Authors
  • Yingzhi Wang 2023

Summary

Functions:

EDER

Calculates the EDER value

distribute_overlap

Distributes the overlapped speech equally among the adjacent segments with different emotions.

getOverlap

Get the overlapped length of two intervals

is_overlapped

Returns True if segments are overlapping.

merge_ssegs_same_emotion_adjacent

Merge adjacent sub-segs if they are the same emotion.

reference_to_lol

Change reference to a list of list

Reference

speechbrain.utils.EDER.EDER(prediction, id, duration, emotion, window_length, stride)[source]

Calculates the EDER value

Parameters:
  • prediction (list) – a list of frame-wise predictions of the utterance

  • id (str) – id of the utterance

  • duration (float) – duration of the utterance

  • emotion (list of dicts) – the ground truth emotion and its duration, e.g. [{β€˜emo’: β€˜angry’, β€˜start’: 1.016, β€˜end’: 6.336}]

  • window_length (float) – the frame length used for frame-wise prediction

  • stride (float) – the frame length used for frame-wise prediction

Returns:

float

Return type:

the calculated EDER for the utterance

Example

>>> from speechbrain.utils.EDER import EDER
>>> prediction = ["n", "n", "n", "a", "a", "a"]
>>> id = "spk1_1"
>>> duration = 1.22
>>> emotion = [{"emo": "angry", "start": 0.39, "end": 1.10}]
>>> window_length = 0.2
>>> stride = 0.2
>>> EDER(prediction, id, duration, emotion, window_length, stride)
0.2704918032786885
speechbrain.utils.EDER.getOverlap(a, b)[source]

Get the overlapped length of two intervals

Parameters:
Returns:

float

Return type:

overlapped length

Example

>>> from speechbrain.utils.EDER import getOverlap
>>> interval1 = [1.2, 3.4]
>>> interval2 = [2.3, 4.5]
>>> getOverlap(interval1, interval2)
1.1
speechbrain.utils.EDER.is_overlapped(end1, start2)[source]

Returns True if segments are overlapping.

Parameters:
  • end1 (float) – End time of the first segment.

  • start2 (float) – Start time of the second segment.

Returns:

overlapped – True of segments overlapped else False.

Return type:

bool

Example

>>> is_overlapped(5.5, 3.4)
True
>>> is_overlapped(5.5, 6.4)
False
speechbrain.utils.EDER.merge_ssegs_same_emotion_adjacent(lol)[source]

Merge adjacent sub-segs if they are the same emotion.

Parameters:

lol (list of list) – Each list contains [utt_id, sseg_start, sseg_end, emo_label].

Returns:

new_lol – new_lol contains adjacent segments merged from the same emotion ID.

Return type:

list of list

Example

>>> from speechbrain.utils.EDER import merge_ssegs_same_emotion_adjacent
>>> lol = [
...     ["u1", 0.0, 7.0, "a"],
...     ["u1", 7.0, 9.0, "a"],
...     ["u1", 9.0, 11.0, "n"],
...     ["u1", 11.0, 13.0, "n"],
...     ["u1", 13.0, 15.0, "n"],
...     ["u1", 15.0, 16.0, "a"],
... ]
>>> merge_ssegs_same_emotion_adjacent(lol)
[['u1', 0.0, 9.0, 'a'], ['u1', 9.0, 15.0, 'n'], ['u1', 15.0, 16.0, 'a']]
speechbrain.utils.EDER.reference_to_lol(id, duration, emotion)[source]

Change reference to a list of list

Parameters:
  • id (str) – id of the utterance

  • duration (float) – duration of the utterance

  • emotion (list of dicts) – the ground truth emotion and its duration, e.g. [{β€˜emo’: β€˜angry’, β€˜start’: 1.016, β€˜end’: 6.336}]

Returns:

lol – It has each list structure as [rec_id, sseg_start, sseg_end, spkr_id].

Return type:

list of list

Example

>>> from speechbrain.utils.EDER import reference_to_lol
>>> id = "u1"
>>> duration = 8.0
>>> emotion = [{"emo": "angry", "start": 1.016, "end": 6.336}]
>>> reference_to_lol(id, duration, emotion)
[['u1', 0, 1.016, 'n'], ['u1', 1.016, 6.336, 'a'], ['u1', 6.336, 8.0, 'n']]
speechbrain.utils.EDER.distribute_overlap(lol)[source]

Distributes the overlapped speech equally among the adjacent segments with different emotions.

Parameters:

lol (list of list) – It has each list structure as [rec_id, sseg_start, sseg_end, spkr_id].

Returns:

new_lol – It contains the overlapped part equally divided among the adjacent segments with different emotion IDs.

Return type:

list of list

Example

>>> lol = [
...     ["r1", 5.5, 9.0, "s1"],
...     ["r1", 8.0, 11.0, "s2"],
...     ["r1", 11.5, 13.0, "s2"],
...     ["r1", 12.0, 15.0, "s1"],
... ]
>>> distribute_overlap(lol)
[['r1', 5.5, 8.5, 's1'], ['r1', 8.5, 11.0, 's2'], ['r1', 11.5, 12.5, 's2'], ['r1', 12.5, 15.0, 's1']]