Skip to content

Commit 1ef1dd9

Browse files
yunjeyapaszke
authored andcommitted
Add comments for readability (pytorch#2005)
1 parent 98206c3 commit 1ef1dd9

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

torch/nn/functional.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,9 @@ def cross_entropy(input, target, weight=None, size_average=True, ignore_index=-1
663663
over observations for each minibatch. However, if the field
664664
sizeAverage is set to False, the losses are instead summed
665665
for each minibatch.
666+
ignore_index (int, optional): Specifies a target value that is ignored
667+
and does not contribute to the input gradient. When size_average is
668+
True, the loss is averaged over non-ignored targets.
666669
"""
667670
return nll_loss(log_softmax(input), target, weight, size_average, ignore_index)
668671

torch/nn/modules/loss.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,10 +409,19 @@ class CrossEntropyLoss(_WeightedLoss):
409409
410410
The losses are averaged across observations for each minibatch.
411411
412+
Args:
413+
weight (Tensor, optional): a manual rescaling weight given to each class.
414+
If given, has to be a Tensor of size "nclasses"
415+
size_average (bool, optional): By default, the losses are averaged over observations for each minibatch.
416+
However, if the field size_average is set to False, the losses are
417+
instead summed for each minibatch.
418+
ignore_index (int, optional): Specifies a target value that is ignored
419+
and does not contribute to the input gradient. When size_average is
420+
True, the loss is averaged over non-ignored targets.
421+
412422
Shape:
413423
- Input: :math:`(N, C)` where `C = number of classes`
414-
- Target: :math:`(N)` where each value is `0 <= targets[i] <= C-1`
415-
424+
- Target: :math:`(N)` where each value is `0 <= targets[i] <= C-1
416425
"""
417426

418427
def __init__(self, weight=None, size_average=True, ignore_index=-100):

0 commit comments

Comments
 (0)