Last active
September 21, 2017 15:23
-
-
Save gyglim/bae2688b29b9e64ba333fa157fc2e54b to your computer and use it in GitHub Desktop.
Lasagne rank loss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rank_loss(prediction, margin=1): | |
''' | |
Implementation of a pairwise rank loss, based on https://github.com/Lasagne/Lasagne/issues/168#issuecomment-81134242 | |
:param prediction: | |
:param target_var: | |
:return: | |
''' | |
score_pos = prediction[0::2] | |
score_neg = prediction[1::2] | |
loss = T.mean(T.maximum(score_neg + margin - score_pos,0.0)) | |
return loss |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment