From e2c2652fc046150f45bfe8ac481b3bbcbd1d0c5a Mon Sep 17 00:00:00 2001 From: Yibing Liu Date: Wed, 27 Dec 2017 09:13:23 +0000 Subject: [PATCH] amend comments in cross_entropy_op --- paddle/operators/cross_entropy_op.cc | 6 +++--- python/paddle/v2/fluid/layers/nn.py | 26 +++++++++++++------------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/paddle/operators/cross_entropy_op.cc b/paddle/operators/cross_entropy_op.cc index a9c5c7046f8..fe39cb481aa 100644 --- a/paddle/operators/cross_entropy_op.cc +++ b/paddle/operators/cross_entropy_op.cc @@ -114,15 +114,15 @@ class CrossEntropyOpMaker : public framework::OpProtoAndCheckerMaker { CrossEntropyOpMaker(OpProto* proto, OpAttrChecker* op_checker) : OpProtoAndCheckerMaker(proto, op_checker) { AddInput("X", - "(Tensor, default Tensor), a 2-D tensor with shape N x D, " - "where N is the batch size and D is the number of classes. " + "(Tensor, default Tensor), a 2-D tensor with shape [N x D]," + " where N is the batch size and D is the number of classes. " "This input is a probability computed by the previous operator, " "which is almost always the result of a softmax operator."); AddInput("Label", "(Tensor), the ground truth which is a 2-D tensor. When " "soft_label is set to false, Label is a Tensor with shape " "[N x 1]. When soft_label is set to true, Label is a " - "Tensor with shape [N x K]."); + "Tensor with shape [N x D]."); AddOutput("Y", "(Tensor, default Tensor), a 2-D tensor with shape " "[N x 1]. The cross entropy loss."); diff --git a/python/paddle/v2/fluid/layers/nn.py b/python/paddle/v2/fluid/layers/nn.py index 6e7145966f3..26180c38c8c 100644 --- a/python/paddle/v2/fluid/layers/nn.py +++ b/python/paddle/v2/fluid/layers/nn.py @@ -365,47 +365,47 @@ def cross_entropy(input, label, **kwargs): both standard cross-entropy and soft-label cross-entropy loss computation. 1) One-hot cross-entropy: - `soft_label = false`, `Label[i, 0]` indicates the class index for sample i: + `soft_label = False`, `Label[i, 0]` indicates the class index for sample i: .. math:: Y[i] = -\log(X[i, Label[i]]) 2) Soft-label cross-entropy: - `soft_label = true`, `Label[i, j]` indicates the soft label of class j + `soft_label = True`, `Label[i, j]` indicates the soft label of class j for sample i: .. math:: Y[i] = \sum_j{-Label[i, j] * log(X[i, j])} - Please make sure that in this case the summuation of each row of `label` + Please make sure that in this case the summation of each row of `label` equals one. 3) One-hot cross-entropy with vecterized `label`: As a special case of 2), when each row of 'label' has only one - non-zero element (equals 1), soft-label cross-entropy degenerates to a - one-hot cross-entropy with one-hot label representation. + non-zero element which is equal to 1, soft-label cross-entropy degenerates + to a one-hot cross-entropy with one-hot label representation. Args: - input (Variable|list): a 2-D tensor with shape N x D, where N is the + input (Variable|list): a 2-D tensor with shape [N x D], where N is the batch size and D is the number of classes. This input is a probability computed by the previous operator, which is almost always the result of a softmax operator. label (Variable|list): the ground truth which is a 2-D tensor. When - `soft_label` is set to `false`, `label` is a tensor with shape - [N x 1]. When `soft_label` is set to `true`, `label` is a - tensor with shape [N x K]. + `soft_label` is set to `False`, `label` is a tensor with shape + [N x 1]. When `soft_label` is set to `True`, `label` is a + tensor with shape [N x D]. soft_label (bool, via `**kwargs`): a flag indicating whether to interpretate - the given labels as soft labels, default `false`. + the given labels as soft labels, default `False`. Returns: A 2-D tensor with shape [N x 1], the cross entropy loss. Raises: - `ValueError`: 1) If the 1st dimension of `input` and `label` are not equal; 2) If \ - `soft_label == true`, and the 2nd dimension of `input` and `label` are not \ - equal; 3) If `soft_label == false`, and the 2nd dimension of `label` is not 1. + `ValueError`: 1) the 1st dimension of `input` and `label` are not equal; 2) when \ + `soft_label == True`, and the 2nd dimension of `input` and `label` are not \ + equal; 3) when `soft_label == False`, and the 2nd dimension of `label` is not 1. Examples: .. code-block:: python -- GitLab