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

Extra softmax layer #6

Open
Atcold opened this issue Nov 26, 2017 · 6 comments
Open

Extra softmax layer #6

Atcold opened this issue Nov 26, 2017 · 6 comments

Comments

@Atcold
Copy link

Atcold commented Nov 26, 2017

Why is there an extra softmax layer https://github.com/gram-ai/capsule-networks/blob/master/capsule_network.py#L106?
Each capsule's norm is already modelling a probability.

@InnovArul
Copy link

InnovArul commented Jun 10, 2018

Though each capsules norm is a probability [0-1], the capsules will be fighting within themselves to send the info to higher level capsules (based on their correlation with the output of the higher level capsules). Hence, there is a softmax layer.

@Atcold
Copy link
Author

Atcold commented Jun 11, 2018

That's not how Capsules work...

@InnovArul
Copy link

InnovArul commented Jun 11, 2018

Maybe if you could write your understanding about capsules or point out the lines in the paper, it will be helpful to discuss and learn I guess. Anyway, I will let the code owner to clarify your doubts.

In my understanding, more the correlation between primary capsule's output to digit capsule's output, the higher the bond between them. Hence, it's a kind of attention mechanism between primary capsules and digit capsules, which necessitates the need for a softmax (based on correlation).

@Atcold
Copy link
Author

Atcold commented Jun 11, 2018

From the paper, section 4, last paragraph, you have that

Our implementation [...] minimize the sum of the margin losses in Eq. 4.

(Install this extension to view LaTeX on GitHub.)

$L_k = T_k \max(0, m^+ - ||v_k||)^2 + λ (1 - T_k) \max(0, ||v_k|| - m^-)^2$

So, as you can see, you're supposed to use $||v_k||$, which is classes = (x ** 2).sum(dim=-1) ** 0.5.

@InnovArul
Copy link

InnovArul commented Jun 12, 2018

Oh I see. My bad. I didn't see which softmax you are mentioning:)

I think you are right. There is no need for softmax (since the vector's magnitude emulates probability). Thanks for elaborating it.

By the way, I have noticed some more deviations in the implementation with respect to paper. Please check if you find time. I'm not sure if my interpretation is correct.

#23

@Atcold
Copy link
Author

Atcold commented Jun 13, 2018

  • That's why I put there the link to the wrong line.
  • The point is not that "there is no need" but "it's plain wrong".
  • Okay, let me see.

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