Keras: Is it possible to make custom loss function with more input than y_pred and y_true?

Created on 25 Nov 2015  路  5Comments  路  Source: keras-team/keras

I would like to design a loss function base on the Ranking score, which is not directly derived from y_pred and y_true.

My idea is to input two feature, that's say 64 + 64 = 128 concatenate together as the input layer and output the 1 unit regression of these two feature.
I am using Muti-layer Perceptron structure.
Input: X and Xselect (64+64 unit)
Output: y (1 unit)
where Xselect is a feature selected from Xlibrary to compare with X. So I expect to get the output candidates by looping the X with the selections of X in library to make a rank. Then use those the rank list as the loss function by Mean Reciprocal Rank.

In short, I need to calculate multiple forward propagation to create the rank list, and to make my loss function. I wonder if it is possible to do that in Keras? Or I should define the function in then?

stale

Most helpful comment

Is there any update on it? I'm also interested in using ranking-based metric but not sure how could I put it into function.

All 5 comments

I think I had a similar issue and solved it by currying, i.e. write a function that only takes the additional arguments as input (everything except y_pred and y_true) and returns another function that is compatible to the interface (i.e. only takes y_pred and y_true as input), see #1061.
However, it feels a little hacky, so I'd be happy to hear of a better solution.

Is there any update on it? I'm also interested in using ranking-based metric but not sure how could I put it into function.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed after 30 days if no further activity occurs, but feel free to re-open a closed issue if needed.

any update on this?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KeironO picture KeironO  路  3Comments

harishkrishnav picture harishkrishnav  路  3Comments

braingineer picture braingineer  路  3Comments

nryant picture nryant  路  3Comments

anjishnu picture anjishnu  路  3Comments