mindspore.ops.LogUniformCandidateSampler

class mindspore.ops.LogUniformCandidateSampler(*args, **kwargs)[source]

Generates random labels with a log-uniform distribution for sampled_candidates.

Random sampling a tensor of sampled classes from the range of integers [0, range_max).

Parameters
  • num_true (int) – The number of target classes per training example. Default: 1.

  • num_sampled (int) – The number of classes to randomly sample. Default: 5.

  • unique (bool) – Determines whether sample with rejection. If unique is True, all sampled classes in a batch are unique. Default: True.

  • range_max (int) – The number of possible classes. When unique is True, range_max must be greater than or equal to num_sampled. Default: 5.

  • seed (int) – Random seed, must be non-negative.

Inputs:
  • true_classes (Tensor) - The target classes. With data type of int64 and shape [batch_size, num_true].

Outputs:

Tuple of 3 Tensors.

  • sampled_candidates (Tensor) - A Tensor with shape (num_sampled,) and the same type as true_classes.

  • true_expected_count (Tensor) - A Tensor with the same shape as true_classes and type float32.

  • sampled_expected_count (Tensor) - A Tensor with the same shape as sampled_candidates and type float32.

Raises
  • TypeError – If neither num_true nor num_sampled is an int.

  • TypeError – If unique is not a bool.

  • TypeError – If neither range_max nor seed is an int.

  • TypeError – If true_classes is not a Tensor.

Supported Platforms:

Ascend

Examples

>>> sampler = ops.LogUniformCandidateSampler(2, 5, True, 5)
>>> output1, output2, output3 = sampler(Tensor(np.array([[1, 7], [0, 4], [3, 3]])))
>>> print(output1, output2, output3)
[3 2 0 4 1]
[[0.92312991 0.49336370]
 [0.99248987 0.65806371]
 [0.73553443 0.73553443]]
[0.73553443 0.82625800 0.99248987 0.65806371 0.92312991]