GithubHelp home page GithubHelp logo

raminnakhli / decoupled-contrastive-learning Goto Github PK

View Code? Open in Web Editor NEW
104.0 104.0 11.0 27 KB

This repository is an implementation for the loss function proposed in https://arxiv.org/pdf/2110.06848.pdf.

License: MIT License

Python 97.20% Shell 2.80%

decoupled-contrastive-learning's People

Contributors

raminnakhli avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

decoupled-contrastive-learning's Issues

Implementation of DCLW

Hi,

I saw your implementation of the nominator of DCLW weight_fn, which uses element multiplication for the z1 and z2 calculation.
But in the paper, the nominator of DCLW weight_fn formula is: exp(<z1, z2> / sigma). Can you tell me why you use element multiplication for the z1 and z2 calculation instead of torch.mm(z1, z2) or dot multiplication?

Thanks.

Why the learning rate is fixed

Hello, thanks for your excellent work. I noticed that your learning rate is fixed during training. Whey you do not apply a learning rate schedule?

Was trying to work with the formula

Hi there,

Great work! I am trying to learn from the formula and walk through the proof of propositions. I was trying to find the derivatives of the loss function and encountered finding the partial derivative of the cosine similarity term. By comparing my answer and steps in the paper I kind of get this result (as the image shows).

I am not quite sure if that is correct and how that works. Would you mind help me a bit with this?

image

negative loss value

Can you tell me why exist loss with negative values? Is that a potential bug in your code?

I doubt the total loss of InfoNCE and DCL should be averaged?

I think the total loss of InfoNCE as well as DCL should be averaged.
$L=\sum_{k \in { 1,2}, i \in [1,N]}L_{i}^{(k)}$
should be
$L=\frac{1}{N}\sum_{k \in { 1,2}, i \in [1,N]}L_{i}^{(k)}$

and
$L_{DC}=\sum_{k \in { 1,2}, i \in [1,N]}L_{DC,i}^{(k)}$
should be
$L_{DC}=\frac{1}{N}\sum_{k \in { 1,2}, i \in [1,N]}L_{DC,i}^{(k)}$

the code does this

return (positive_loss + negative_loss).mean()

About the optimization setting

Hello, Thanks for your good work! I'd like to know if the cosine annealing schedule is also applied to the small-scale dataset experiments of CIFAR and STL10?

DCLW bug?

In DCLW, your code is like:

weight_fn = lambda z1, z2: 2 - z1.size(0) * torch.nn.functional.softmax((z1 * z2).sum(dim=1) / sigma, dim=0).squeeze()

I think the right way shall be like:

weight_fn = lambda z1, z2: 2 - torch.nn.functional.softmax((z1 * z2).sum(dim=1) / sigma, dim=0).squeeze()

z1.size(0) is not a variable introduced in the origin paper.

What do you think of it?

Follow-up Issue of DCLW Implementation

    Hi @raminnakhli Thanks for the reply. 


截屏2022-10-27 下午2 30 34
As you can see from the two pictures, the formulas are similar which all include: exp(<z_1, z_2>). But in your code, for formula(5) (6) you use matrix multiplication, and for the formula of w(z_1, z_2), you use element multiplication.

Could you please explain to me why? Thanks!

Originally posted by @wqtwjt1996 in #10 (comment)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.