Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[question] How is M computed in wasserstein layer? #257

Open
kirk86 opened this issue May 1, 2021 · 4 comments
Open

[question] How is M computed in wasserstein layer? #257

kirk86 opened this issue May 1, 2021 · 4 comments

Comments

@kirk86
Copy link

kirk86 commented May 1, 2021

Hi,
I was wondering if anyone could shed some light on the following questions regarding the wasserstein layer.

  • How is M computed, where can I find this info?
  • What is the pred variable is it logits, softmax outputs or something else?
  • Same for label is it hard labels like [3, 2, 5, 7, 9, 1, 0], one-hot encoded or something else?

Do the above vars change according to the problem (multi-class classification), for instance on MNIST with hard labels (i.e. unique labels) vs MNIST with multi-labels for each class?

@pluskid
Copy link
Owner

pluskid commented May 3, 2021

M is the ground metric matrix, which should be defined beforehand according to your prior knowledge of the label space (i.e. how similar label a is to label b).

Both pred and label should be k_class -by- n_eg. Both pred and label should be normalized to 1. So pred should be softmax output. If you have hard labels, they need to be one-hot encoded, and if there are multiple labels for one instance, the one-hot labels need to re-normalized to sum to 1. Hope this helps.

@kirk86
Copy link
Author

kirk86 commented May 3, 2021

Thanks that helps!

M is the ground metric according to your prior knowledge of the label space (i.e. how similar label a is to label b)

So basically M is just an adjacency matrix between all pairs of labels?

Given k = num_classes, n = num_samples, where then ?

@pluskid
Copy link
Owner

pluskid commented May 5, 2021

I'm not sure if I follow your notation. Basically, M is k x k shape, where M[i, j] is the distance between class i and class j. The distance depend on specific applications. For examples, if you have class cat, dog, car, etc. Then you might have some ground metric that measures longer distance between cat and car than between cat and dog. In the most extreme case, where you do not have any information available on the classes, then you can use the uninformative distances to say every class is equal distant to every other class. If this is the case, then this might not be a good application scenario for wasserstein loss any way.

@kirk86
Copy link
Author

kirk86 commented May 6, 2021

Basically, M is k x k shape

Yep, that's what my notation says as well.

if you have class cat, dog, car, etc. Then you might have some ground metric that measures longer distance between cat and car than between cat and dog

Thanks, do you have any references or examples to such ground metrics?

I've used the l1-norm between labels to generate M above in my notation.
When I tried training using SGD the model would not train beyond a 40-50% acc.
Adam gave better results but still nowhere near compared to training without the wasserstein, any thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants