TaoRuijie / Loss-Gated-Learning

ICASSP 2022: 'Self-supervised Speaker Recognition with Loss-gated Learning'
MIT License
85 stars 15 forks source link

why use label in loss.py #4

Closed gancx closed 1 year ago

gancx commented 1 year ago

Thanks for your great work. I understand you use label to compute precision in loss.py. However, you initiated label tensor in 81th row. I wonder how and why you set label like this. Thank you.

TaoRuijie commented 1 year ago

Sorry did not get your point. Where is 81th row ?

gancx commented 1 year ago

Sorry, I mistake the row number. I mean this: label = torch.from_numpy(numpy.asarray(list(range(batch_size - 1,batch_size*2 - 1)) + list(range(0,batch_size)))).cuda() in loss.py.

TaoRuijie commented 1 year ago

It is the labels for trianing in stage 1, let's say we have 200 data , 400 segments in one minibatch.

The positive pairs are segments from the same data. Negative pairs are segments from the different data. So we can build a label matrix:

1, 0, 0.... , 0 0, 1, 0..... , 0 0, 0, 1.... , .. .... 0, 0, 0......, 1

something like that. The diagonal is 1 and the rest part is 0.

gancx commented 1 year ago

However, the output label may be [2, 3, 4, 0, 1, 2] if the batch size is 3. what's the relationship between output label and label matrix you mentioned?

TaoRuijie commented 1 year ago

As what I remember, batchsize=3 -> 6 segments

for each segments, itself can not be selected for choice, so there are 5 choices (0,1,2,3,4)

so the matrix I mentioned (similar to one-hot) can be transformed into the classification label, [2,3,4,0,1,2] means the class. This order is due to the processing in computing the loss.

This part is only used to compute the trianing accuracy for understanding the training process, so it will effect the results.

gancx commented 1 year ago

Ok. it makes sense to me. You do a transformation between original label and one-hot vector. I may understand. Thanks for your explanation.