eric-haibin-lin closed pull request #10980: Sampling negative samples other classes only URL: https://github.com/apache/incubator-mxnet/pull/10980
This is a PR merged from a forked repository. As GitHub hides the original diff on merge, it is displayed below for the sake of provenance: As this is a foreign pull request (from a fork), the diff is supplied below (as it won't show otherwise due to GitHub magic): diff --git a/example/gluon/embedding_learning/model.py b/example/gluon/embedding_learning/model.py index 91f7735497d..f82240e2cd5 100644 --- a/example/gluon/embedding_learning/model.py +++ b/example/gluon/embedding_learning/model.py @@ -108,6 +108,7 @@ def hybrid_forward(self, F, x): mask = np.ones(weights.shape) for i in range(0, n, k): mask[i:i+k, i:i+k] = 0 + mask_uniform_probs = mask * (1.0/(n-k)) weights = weights * F.array(mask) * (distance < self.nonzero_loss_cutoff) weights_sum = F.sum(weights, axis=1, keepdims=True) @@ -125,7 +126,7 @@ def hybrid_forward(self, F, x): n_indices += np.random.choice(n, k-1, p=np_weights[i]).tolist() else: # all samples are above the cutoff so we sample uniformly - n_indices += np.random.choice(n, k-1).tolist() + n_indices += np.random.choice(n, k-1, p=mask_uniform_probs[i]).tolist() for j in range(block_idx * k, (block_idx + 1) * k): if j != i: a_indices.append(i) ---------------------------------------------------------------- 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: us...@infra.apache.org With regards, Apache Git Services