djl icon indicating copy to clipboard operation
djl copied to clipboard

How to define BPRLoss and MarginLoss by DJL? Does there have some samples?

Open dxjjhm opened this issue 4 years ago • 1 comments

How to define BPRLoss and MarginLoss by DJL? Does there have some samples?

For PairWise data in recommender systems, like user, pos_item, neg_item

I am already see the source of Loss in DJL, but still don't kown how to do it.

In pytorch, loss could be compute by extends nn.module, but in DJL loss is extended from Evaluator not from AbstractBlock ? Would some experts tell me how to do?

dxjjhm avatar Sep 16 '21 08:09 dxjjhm

You want to extend the Loss class. It should be fairly easy. You only need to define the evaluate method. As a simple example, try looking at the L2Loss.

In evaluate(...), you will need to pass the PairWise data using NDLists. The prediction NDList should be the data produced by your model and the label is the true answer. If you have multiple pieces of data for either of them, they can either be stored in the same NDArray or by using the NDList like a tuple.

zachgk avatar Sep 17 '21 21:09 zachgk