From 082c302c3f1a2e289808829bcdd3db0a8eb5a853 Mon Sep 17 00:00:00 2001 From: wanghaoshuang Date: Thu, 18 Jan 2018 16:58:54 +0800 Subject: [PATCH] Add comments --- doc/api/v2/fluid/layers.rst | 5 +++++ python/paddle/v2/fluid/layers/nn.py | 31 ++++++++++++++++++++++++----- 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/doc/api/v2/fluid/layers.rst b/doc/api/v2/fluid/layers.rst index 62c154e65..1b40a495d 100644 --- a/doc/api/v2/fluid/layers.rst +++ b/doc/api/v2/fluid/layers.rst @@ -493,3 +493,8 @@ swish ------ .. autofunction:: paddle.v2.fluid.layers.swish :noindex: + +greedy_ctc_error +------ +.. autofunction:: paddle.v2.fluid.layers.greedy_ctc_error + :noindex: diff --git a/python/paddle/v2/fluid/layers/nn.py b/python/paddle/v2/fluid/layers/nn.py index 8572b422e..c786f3128 100644 --- a/python/paddle/v2/fluid/layers/nn.py +++ b/python/paddle/v2/fluid/layers/nn.py @@ -50,7 +50,7 @@ __all__ = [ 'sequence_last_step', 'dropout', 'split', - 'greedy_ctc_evaluator', + 'greedy_ctc_error', ] @@ -1600,11 +1600,32 @@ def split(input, num_or_sections, dim=-1): return outs -def greedy_ctc_evaluator(input, label, blank, normalized=False, name=None): - """ +def greedy_ctc_error(input, label, blank, normalized=False, name=None): """ + This evaluator is to calculate sequence-to-sequence edit distance. + + Args: + + input(Variable): (LodTensor, default: LoDTensor), the unscaled probabilities of variable-length sequences, which is a 2-D Tensor with LoD information. It's shape is [Lp, num_classes + 1], where Lp is the sum of all input sequences' length and num_classes is the true number of classes. (not including the blank label). + + label(Variable): (LodTensor, default: LoDTensor), the ground truth of variable-length sequence, which is a 2-D Tensor with LoD information. It is of the shape [Lg, 1], where Lg is th sum of all labels' length. + + blank(int): the blank label index of Connectionist Temporal Classification (CTC) loss, which is in thehalf-opened interval [0, num_classes + 1). + + normalized(bool): Indicated whether to normalize the edit distance by the length of reference string. - helper = LayerHelper("greedy_ctc_evalutor", **locals()) + Returns: + Variable: sequence-to-sequence edit distance loss in shape [batch_size, 1]. + + Examples: + .. code-block:: python + + x = fluid.layers.data(name='x', shape=[8], dtype='float32') + y = fluid.layers.data(name='y', shape=[1], dtype='float32') + + cost = fluid.layers.greedy_ctc_error(input=x,label=y, blank=0) + """ + helper = LayerHelper("greedy_ctc_error", **locals()) # top 1 op topk_out = helper.create_tmp_variable(dtype=input.dtype) topk_indices = helper.create_tmp_variable(dtype="int64") @@ -1620,7 +1641,7 @@ def greedy_ctc_evaluator(input, label, blank, normalized=False, name=None): helper.append_op( type="ctc_align", inputs={"Input": [topk_indices]}, - outputs={"Out": [ctc_out]}, + outputs={"Output": [ctc_out]}, attrs={"merge_repeated": True, "blank": blank}) -- GitLab