def _negative_sampling(self, num_negative_samples, target_indices):
assert num_negative_samples > 0
logging.debug('Stochastically sampling %d negative instances '
'out of %d classes (%.2f%%).',
num_negative_samples, self.num_entities,
100.0 *
float(num_negative_samples) / self.num_entities)
from theano.tensor.shared_randomstreams import RandomStreams
srng = RandomStreams(
seed=np.random.randint(low=0, high=(1 << 30)))
rng_sample_size = (self.batch_size, num_negative_samples,)
logging.debug(
'Using %s for random sample generation of %s tensors.',
RandomStreams, rng_sample_size)
logging.debug('For every batch %d random integers are sampled.',
np.prod(rng_sample_size))
random_negative_indices = srng.choice(
rng_sample_size,
a=self.num_entities,
p=self.clazz_distribution)
if self.__DEBUG__:
random_negative_indices = theano.printing.Print(
'random_negative_indices')(random_negative_indices)
return random_negative_indices
评论列表
文章目录