Example #1
0
 def sample(self, ex, is_target, candidates, num_samples=0):
     samples = self.filter_candidates(ex, is_target, candidates)
     num_samples = self.num_samples if num_samples <= 0 else num_samples
     # if corrupted negatives less than num_samples then augment with random samples
     if num_samples >= len(samples):
         return self.pad_samples(ex, samples, num_samples, is_target)
     #samples = np.random.choice(list(samples), num_samples, replace=False).tolist()
     # Cython code faster then np.random.choice()
     samples = sample_list(list(samples), num_samples)
     assert len(samples) >= 1
     return samples
Example #2
0
 def sample(self, ex, is_target, num_samples=0):
     candidates = self._entity_set.copy()
     samples = self.filter_candidates(ex, is_target, candidates)
     num_samples = self.num_samples if num_samples <= 0 else num_samples
     if num_samples == float('inf'):
         assert self.filtered or len(samples) == 14950
         return list(samples)
     #samples = np.random.choice(list(samples), num_samples, replace=False).tolist()
     #samples = list(samples)
     #np.random.shuffle(samples)
     #samples = samples[:num_samples]
     samples = sample_list(list(samples), num_samples)
     assert len(samples) >= 1
     return samples