Browse Source

SampledSoftmaxLoss example

tags/v1.1.0
Jonathan Yan 5 years ago
parent
commit
a35d3441d4
1 changed files with 9 additions and 0 deletions
  1. +9
    -0
      mindspore/nn/loss/loss.py

+ 9
- 0
mindspore/nn/loss/loss.py View File

@@ -291,6 +291,15 @@ class SampledSoftmaxLoss(_Loss):
Outputs:
Tensor, a tensor of shape (N) with the per-example sampled softmax losses.

Examples:
>>> loss = nn.SampledSoftmaxLoss(num_sampled=4, num_classes=7, num_true=1)
>>> weights = Tensor(np.random.randint(0, 9, [7, 10]), mindspore.float32)
>>> biases = Tensor(np.random.randint(0, 9, [7]), mindspore.float32)
>>> labels = Tensor([0, 1, 2])
>>> inputs = Tensor(np.random.randint(0, 9, [3, 10]), mindspore.float32)
>>> output = loss(weights, biases, labels, inputs)
>>> print(output) # output is ranndom
[ 4.0181947 46.050743 7.0009117]
"""

def __init__(self, num_sampled, num_classes, num_true=1,


Loading…
Cancel
Save