Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Commit

Permalink
Sampling negative samples other classes only (#10980)
Browse files Browse the repository at this point in the history
The original code will have a chance to sample negative samples from the same class of the anchors
  • Loading branch information
jonbakerfish authored and eric-haibin-lin committed May 17, 2018
1 parent 7641759 commit 632f514
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion example/gluon/embedding_learning/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down

0 comments on commit 632f514

Please sign in to comment.