multihead-siamese-nets icon indicating copy to clipboard operation
multihead-siamese-nets copied to clipboard

Implement contrastive loss function.

Open tlatkowski opened this issue 6 years ago • 4 comments

Implement contrastive loss function according to paper: http://yann.lecun.com/exdb/publis/pdf/hadsell-chopra-lecun-06.pdf

tlatkowski avatar Feb 26 '18 09:02 tlatkowski

Isn't it already implemented? In layers.losses there is a contrastive loss function.

But I tried, but the loss is always 0. So, indeed it seems not working, although you can hand over the loss function a an argument?

What is actually the constrastive? Since there is also contrastive_lecun.

In your function contrastive you only hand over prediction. How is from this postive and negative examples generated?

I suppose this lecun_contrastive is similiar to triplet loss and to be a contrastive loss und need postive and negative examples.

datistiquo avatar May 24 '19 11:05 datistiquo

Hey @tlatkowski . Do you have an idea how I can use the loss other than MSE loss functions? I suppose I need to change the data set reader?

datistiquo avatar May 27 '19 13:05 datistiquo

Hi @datistiquo in current version of pipeline you have to modify code for the specific model, for example, for multihead model you have to modify the line where constructor from the base class is called:

https://github.com/tlatkowski/multihead-siamese-nets/blob/d6f2e67bae3858da6164b36e4889eadc800b9b1b/models/multihead_attention.py#L12

just change mse to contrastive for example

you also need to import it from losses module.

In the next version i will make a change in pipeline so you will be able to change loss from the main config file.

tlatkowski avatar May 28 '19 06:05 tlatkowski

Hi @tlatkowski

I already tried this, but I get for the loss zero.

I think you also need to change the input dataset to get pairs for the postive and negative examples at least for the contrastive_lecun function?

Why should the data set structure work for the contrastive function at all? You just handover the predction as argument. I dont see any operation where the postive and negative samples are extracted?

datistiquo avatar May 28 '19 13:05 datistiquo