You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/05/09 21:00:25 UTC

[GitHub] safrooze commented on a change in pull request #10857: Fixed divison by zero bug in DistanceWeightedSampling in gluon example

safrooze commented on a change in pull request #10857: Fixed divison by zero bug in DistanceWeightedSampling in gluon example
URL: https://github.com/apache/incubator-mxnet/pull/10857#discussion_r187173431
 
 

 ##########
 File path: example/gluon/embedding_learning/model.py
 ##########
 @@ -218,6 +220,8 @@ def hybrid_forward(self, F, anchors, positives, negatives, beta_in, a_indices=No
         neg_loss = F.maximum(beta - d_an + self._margin, 0.0)
 
         pair_cnt = float(F.sum((pos_loss > 0.0) + (neg_loss > 0.0)).asscalar())
+        if pair_cnt == 0.0:
+            return F.zeros(1)
 
 Review comment:
   I recommend this code be changed to a Block or be written to be a proper HybridBlock. There are several issues that prevent the current code to be hybridizable.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services