I understand that, since scores contains the distances between all pairs (similar in the diagonal and non-matching in the rest of elements), in order to be faithful to Eq. 5 in the paper (max(0, m - d(f, v) + d(f, v_k)), as done in the line 367), the diagonal must be subtracted again, as it's done in line 370.
I might be missing something here, since I'm not used to TensorFlow, but I think it should only be done when cost_s != 0. Otherwise, we are not sure about m - d(f, v) + d(f, v_k) being greater than 0, since we still have to subtract the diagonal to get the right value for d(f, v_k). And in the case where it's lower than 0, we will have a loss equal to -diagonal.
Sorry for the late reply. diagonal is the diagonal part of scores, so the diagonal of cost_s in line 367 will always equal to self.config.emb_margin, which is greater than 0.
https://github.com/xthan/polyvore/blob/57e4f8ca6cf363980d46e8644c496180aa8cc15a/polyvore/polyvore_model_bi.py#L363-L371
I understand that, since
scores
contains the distances between all pairs (similar in the diagonal and non-matching in the rest of elements), in order to be faithful to Eq. 5 in the paper (max(0, m - d(f, v) + d(f, v_k))
, as done in the line 367), the diagonal must be subtracted again, as it's done in line 370.I might be missing something here, since I'm not used to TensorFlow, but I think it should only be done when
cost_s != 0
. Otherwise, we are not sure aboutm - d(f, v) + d(f, v_k)
being greater than0
, since we still have to subtract the diagonal to get the right value ford(f, v_k)
. And in the case where it's lower than0
, we will have a loss equal to-diagonal
.Same thing happens for
cost_im
.