Document feedback

Question document fragment

When a question document fragment contains a formula, it is displayed as a space.

Submission type
issue

It's a little complicated...

I'd like to ask someone.

Please select the submission type

Problem type
Specifications and Common Mistakes

- Specifications and Common Mistakes:

- Misspellings or punctuation mistakes,incorrect formulas, abnormal display.

- Incorrect links, empty cells, or wrong formats.

- Chinese characters in English context.

- Minor inconsistencies between the UI and descriptions.

- Low writing fluency that does not affect understanding.

- Incorrect version numbers, including software package names and version numbers on the UI.

Usability

- Usability:

- Incorrect or missing key steps.

- Missing main function descriptions, keyword explanation, necessary prerequisites, or precautions.

- Ambiguous descriptions, unclear reference, or contradictory context.

- Unclear logic, such as missing classifications, items, and steps.

Correctness

- Correctness:

- Technical principles, function descriptions, supported platforms, parameter types, or exceptions inconsistent with that of software implementation.

- Incorrect schematic or architecture diagrams.

- Incorrect commands or command parameters.

- Incorrect code.

- Commands inconsistent with the functions.

- Wrong screenshots.

- Sample code running error, or running results inconsistent with the expectation.

Risk Warnings

- Risk Warnings:

- Lack of risk warnings for operations that may damage the system or important data.

Content Compliance

- Content Compliance:

- Contents that may violate applicable laws and regulations or geo-cultural context-sensitive words and expressions.

- Copyright infringement.

Please select the type of question

Problem description

Describe the bug so that we can quickly locate the problem.

mindspore.ops.ComputeAccidentalHits

class mindspore.ops.ComputeAccidentalHits(num_true=1)[source]

Compute accidental hits of sampled classes which match target classes.

When a target class matches the sample class, we call it "accidental hit". The result of calculating accidental hits contain 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. FLOAT_MAX indicates the max value in the type of Float

Parameters

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

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

  • sampled_candidates (Tensor) - The Candidate sampling results of operators, types of training samples, with data type of int64 and shape (num_sampled,).

Outputs:

Tuple of 3 Tensors.

  • indices (Tensor) - A Tensor with shape (num_accidental_hits,), with data type of int32.

  • ids (Tensor) - A Tensor with shape (num_accidental_hits,), with data type of int64.

  • weights (Tensor) - A Tensor with shape (num_accidental_hits,), with the type float32.

Raises
  • TypeError – If dtype of num_true is not int.

  • TypeError – If true_classes or sampled_candidates is not a Tensor.

  • TypeError – If dtype of true_classes or sampled_candidates is neither int32 nor int64.

Supported Platforms:

Ascend

Examples

>>> import numpy as np
>>> from mindspore import Tensor, ops
>>> true_classes = np.array([[1, 2], [0, 4], [3, 3]])
>>> sampled_candidates = np.array([0, 1, 2, 3, 4])
>>> sampler = ops.ComputeAccidentalHits(2)
>>> indices, ids, weights = sampler(Tensor(true_classes), Tensor(sampled_candidates))
>>> print(indices, ids, weights)
[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]