<jupyter_start><jupyter_text>Define sequences and its respective intervals<jupyter_code>sequences = voxcon_test_seqs
intervals = voxcon_test_intervals
sample_ids = voxcon_test_audio_ids

# load rttm files for metrics calculating
rttm_path = f'{base_dir}/datasets/voxconverse/test/rttm'
rttm_files = defaultdict(list)
for sample_id in sample_ids:
    rttm_files[sample_id] = os.path.join(rttm_path, sample_id + '.rttm')<jupyter_output><empty_output><jupyter_text>Cluster a single sequence<jupyter_code>idx = 259
sample_id = sample_ids[idx]
# labels = icassp2018_clusterer.predict(sequences[idx])
labels = configs.icassp2018_clusterer.predict(sequences[idx])


annotation = Annotation()
annotation.uri = sample_id
for jdx, speaker_id in enumerate(labels):
    segment_interval = intervals[idx][jdx]
    annotation[Segment(segment_interval[0], segment_interval[1])] = speaker_id

hypothesis = annotation.support()
hypothesis
reference = load_rttm(rttm_files[sample_id])[sample_id]
reference
der = derMetric(reference, hypothesis, detailed = True)
jer = jerMetric(reference, hypothesis)

confusion = der['confusion']/der['total']
false_alarm = der['false alarm']/der['total']
missed_detection = der['missed detection']/der['total']

print(f'{sample_id} DER = {100 * der["diarization error rate"]:.1f}% JER = {100 * jer:.1f}%')
print(f'{sample_id} DER_conf = {100 * confusion:.1f}% DER_fa = {100 * false_alarm:.1f}% DER_md = {100 * missed_detection:.1f}%')<jupyter_output>bxcfq DER = 4.5% JER = 6.6%
bxcfq DER_conf = 0.3% DER_fa = 0.0% DER_md = 4.2%<jupyter_text>Cluster all sequences<jupyter_code>derMetric = DiarizationErrorRate(collar=0.25)
jerMetric = JaccardErrorRate(collar=0.25)

predictions = []

for idx, sample_id in enumerate(sample_ids):
    labels = configs.icassp2018_clusterer.predict(sequences[idx])
#     labels = icassp2018_clusterer.predict(sequences[idx])
    
    annotation = Annotation()
    annotation.uri = sample_id
    for jdx, speaker_id in enumerate(labels):
        segment_interval = intervals[idx][jdx]
        annotation[Segment(segment_interval[0], segment_interval[1])] = speaker_id
    predictions.append(annotation)
    
    hypothesis = annotation.support()
    reference = load_rttm(rttm_files[sample_id])[sample_id]
    
    der = derMetric(reference, hypothesis, detailed = True)
    jer = jerMetric(reference, hypothesis)
    
    confusion = der['confusion']/der['total']
    false_alarm = der['false alarm']/der['total']
    missed_detection = der['missed detection']/der['total']
    

    
    print(f'{sample_id} Speakers: (truth) {len(reference.labels())} vs {len(hypothesis.labels())} (prediction)')
    print(f'DER = {100 * der["diarization error rate"]:.1f}% JER = {100 * jer:.1f}%')
    print(f'DER_conf = {100 * confusion:.1f}% DER_fa = {100 * false_alarm:.1f}% DER_md = {100 * missed_detection:.1f}%')

#     rttmFile = f'{base_dir}/rttm/{}.rttm'.format(audio_id)
#     with open(rttmFile, 'w') as writeRttmFile:
#         joined_annotation.write_rttm(writeRttmFile)    
reference
reference = load_rttm(rttm_files[sample_id])[sample_id]<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13643659711075443, 'fraction_numerical': 0.02536115569823435, 'mean_word_length': 5.7155172413793105, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 12, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '645352', 'license': 'MIT', 'n_tokens_mistral': 1203, 'n_tokens_neox': 1108, 'n_words': 190, 'path': 'clustering/spectral-clustering-predict.ipynb', 'repo_name': 'scalfs/voxsrc21-dia', 'size': '3115'}