mindspore.ops.ComputeAccidentalHits
- class mindspore.ops.ComputeAccidentalHits(*args, **kwargs)[source]
Compute accidental hits of sampled classes which happen to match target classes.
When a target class matches the sample class, we call it “accidental hit”. The result of calculating accidental hit contains three parts (index, id, weight), where index represents the row number in true_classes, and id represents the position in sampled_candidates, the weight is -FLOAT_MAX.
- Parameters
num_true (int) – The number of target classes per training example.
- Inputs:
true_classes (Tensor) - The target classes. With data type of int32 or int64 and shape [batch_size, num_true].
sampled_candidates (Tensor) - The sampled_candidates output of CandidateSampler, with data type of int32 or int64 and shape [num_sampled].
- Outputs:
Tuple of 3 Tensors.
indices (Tensor) - A Tensor with shape (num_accidental_hits,), with the same type as true_classes.
ids (Tensor) - A Tensor with shape (num_accidental_hits,), with the same type as true_classes.
weights (Tensor) - A Tensor with shape (num_accidental_hits,), with the type float32.
- Raises
- Supported Platforms:
Ascend
Examples
>>> x = np.array([[1, 2], [0, 4], [3, 3]]) >>> y = np.array([0, 1, 2, 3, 4]) >>> sampler = ops.ComputeAccidentalHits(2) >>> output1, output2, output3 = sampler(Tensor(x), Tensor(y)) >>> print(output1, output2, output3) [0 0 1 1 2 2] [1 2 0 4 3 3] [-3.4028235e+38 -3.4028235e+38 -3.4028235e+38 -3.4028235e+38 -3.4028235e+38 -3.4028235e+38]