Skip to content

Commit

Permalink
Move functions from objectives to losses
Browse files Browse the repository at this point in the history
  • Loading branch information
lvapeab committed Sep 29, 2017
1 parent e54d070 commit 06f91b9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
21 changes: 21 additions & 0 deletions keras/losses.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ def cosine_proximity(y_true, y_pred):
y_pred = K.l2_normalize(y_pred, axis=-1)
return -K.mean(y_true * y_pred, axis=-1)

def log_diff(args):
"""
log prob difference between a GT and a hypothesis
:param args: y_pred, y_true, h_pred, h_true
:return:
"""
y_pred, y_true, h_pred, h_true = args
p_y_x = K.mean(K.categorical_crossentropy(y_pred, y_true))
p_h_x = K.mean(K.categorical_crossentropy(h_pred, h_true))
return p_y_x - p_h_x


def y_true(y_true, y_pred):
"""
Returns the label (y_true)
:param y_true:
:param y_pred:
:return:
"""
return y_true


# Aliases.

Expand Down
19 changes: 1 addition & 18 deletions keras/objectives.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,4 @@
Only kept for backwards API compatibility.
"""
from __future__ import absolute_import
from .losses import *


def log_diff(args):
''' log prob difference between a GT and a hypothesis
'''
y_pred, y_true, h_pred, h_true = args
p_y_x = K.mean(K.categorical_crossentropy(y_pred, y_true))
p_h_x = K.mean(K.categorical_crossentropy(h_pred, h_true))
l = p_y_x - p_h_x
return l


def y_true(y_true, y_pred):
'''Returns the label (y_true)
'''
return y_true

from .losses import *

0 comments on commit 06f91b9

Please sign in to comment.