bootphon / pygamma-agreement

Gamma Agreement in Python
MIT License
43 stars 8 forks source link

ValueError: cannot assign slice from input of different size #30

Closed phlobo closed 3 years ago

phlobo commented 3 years ago

Dear all,

I want to use pygamma-agreement for a linguistic annotation project. The attached code causes an error ValueError: cannot assign slice from input of different size.

Is there anything wrong with my data?

Any help is appreciated.

from pygamma_agreement import Continuum, CombinedCategoricalDissimilarity
from pyannote.core import Segment

a =   [['annotator_1', 1240, 1269, 'label_1'],
       ['annotator_1', 1270, 1273, 'label_2'],
       ['annotator_1', 1274, 1275, 'label_1'],
       ['annotator_1', 1280, 1294, 'label_1'],
       ['annotator_1', 1295, 1308, 'label_1'],
       ['annotator_1', 1309, 1322, 'label_2'],
       ['annotator_1', 1350, 1362, 'label_2'],
       ['annotator_1', 1363, 1376, 'label_1'],
       ['annotator_1', 1377, 1380, 'label_2'],
       ['annotator_1', 1381, 1385, 'label_1'],
       ['annotator_1', 1414, 1423, 'label_3'],
       ['annotator_1', 1424, 1454, 'label_1'],
       ['annotator_1', 1428, 1437, 'label_3'],
       ['annotator_1', 1442, 1454, 'label_3'],
       ['annotator_2', 1240, 1269, 'label_1'],
       ['annotator_2', 1270, 1273, 'label_2'],
       ['annotator_2', 1274, 1275, 'label_1'],
       ['annotator_2', 1280, 1294, 'label_1'],
       ['annotator_2', 1295, 1308, 'label_1'],
       ['annotator_2', 1309, 1322, 'label_2'],
       ['annotator_2', 1350, 1362, 'label_2'],
       ['annotator_2', 1363, 1366, 'label_2'],
       ['annotator_2', 1363, 1376, 'label_1'],
       ['annotator_2', 1377, 1380, 'label_2'],
       ['annotator_2', 1381, 1385, 'label_1'],
       ['annotator_2', 1414, 1423, 'label_3'],
       ['annotator_2', 1424, 1454, 'label_1'],
       ['annotator_2', 1428, 1437, 'label_3'],
       ['annotator_2', 1442, 1454, 'label_3'],
       ['annotator_3', 1240, 1269, 'label_1'],
       ['annotator_3', 1270, 1273, 'label_2'],
       ['annotator_3', 1274, 1275, 'label_1'],
       ['annotator_3', 1280, 1294, 'label_1'],
       ['annotator_3', 1295, 1308, 'label_1'],
       ['annotator_3', 1309, 1322, 'label_2'],
       ['annotator_3', 1323, 1343, 'label_1'],
       ['annotator_3', 1350, 1362, 'label_2'],
       ['annotator_3', 1363, 1376, 'label_1'],
       ['annotator_3', 1377, 1380, 'label_2'],
       ['annotator_3', 1381, 1385, 'label_1'],
       ['annotator_3', 1414, 1423, 'label_3'],
       ['annotator_3', 1424, 1437, 'label_1'],
       ['annotator_3', 1428, 1437, 'label_3'],
       ['annotator_3', 1442, 1454, 'label_2'],
       ['annotator_3', 1442, 1454, 'label_1'],
       ['annotator_4', 1240, 1269, 'label_1'],
       ['annotator_4', 1270, 1273, 'label_2'],
       ['annotator_4', 1274, 1275, 'label_1'],
       ['annotator_4', 1280, 1294, 'label_1'],
       ['annotator_4', 1295, 1308, 'label_1'],
       ['annotator_4', 1309, 1322, 'label_2'],
       ['annotator_4', 1350, 1362, 'label_2'],
       ['annotator_4', 1363, 1376, 'label_1'],
       ['annotator_4', 1377, 1380, 'label_2'],
       ['annotator_4', 1381, 1385, 'label_1'],
       ['annotator_4', 1414, 1423, 'label_3'],
       ['annotator_4', 1428, 1437, 'label_3'],
       ['annotator_4', 1442, 1454, 'label_3'],
       ['annotator_5', 1240, 1269, 'label_1'],
       ['annotator_5', 1270, 1273, 'label_2'],
       ['annotator_5', 1274, 1275, 'label_1'],
       ['annotator_5', 1280, 1294, 'label_1'],
       ['annotator_5', 1295, 1308, 'label_1'],
       ['annotator_5', 1309, 1322, 'label_2'],
       ['annotator_5', 1350, 1362, 'label_2'],
       ['annotator_5', 1363, 1376, 'label_1'],
       ['annotator_5', 1377, 1380, 'label_2'],
       ['annotator_5', 1381, 1385, 'label_1'],
       ['annotator_5', 1414, 1423, 'label_3'],
       ['annotator_5', 1424, 1437, 'label_1'],
       ['annotator_5', 1428, 1437, 'label_3'],
       ['annotator_5', 1442, 1454, 'label_3'],
       ['annotator_5', 1442, 1454, 'label_1']]

continuum = Continuum()

for ann in a:
    continuum.add(ann[0], Segment(ann[1], ann[2]), ann[3])

diss = CombinedCategoricalDissimilarity()

continuum.compute_gamma(diss)
ghost commented 3 years ago

Hi ! This is a quite concerning edge-case bug that has been found very recently, and it happens whenever the input continuum has a lot of potential alignments of annotations. I will push a new version on pypi today with a fix.

Thank you for your issue :)

ghost commented 3 years ago

Update 0.4.1 is available on pypi, with this problem fixed. Thanks again !

phlobo commented 3 years ago

Thank you for the quick solution! It works now for me and runs in reasonable time even for a larger dataset.

ogreyesp commented 1 year ago

This is happening again in version 0.5.3

hadware commented 1 year ago

Hello, does it happen with the same code example as provided by the OP of this issue? Can you provide your python version, and ideally a pip freeze output, please?