Skip to content

Instantly share code, notes, and snippets.

@gyglim
Last active September 21, 2017 15:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gyglim/bae2688b29b9e64ba333fa157fc2e54b to your computer and use it in GitHub Desktop.
Save gyglim/bae2688b29b9e64ba333fa157fc2e54b to your computer and use it in GitHub Desktop.
Lasagne rank loss
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