From c287b6b216aa74bbbea92a2897df907525c2d766 Mon Sep 17 00:00:00 2001 From: Peng Li Date: Thu, 15 Dec 2016 14:36:50 +0800 Subject: [PATCH] Add an extra parameter label to chunk_evaluator In order to keep consistent with other evaluators, an extra parameter label is add to chunk_evaluator. Document and demos are modified accordingly. --- demo/sequence_tagging/linear_crf.py | 3 ++- demo/sequence_tagging/rnn_crf.py | 3 ++- .../trainer_config_helpers/evaluators.py | 18 +++++++++++------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/demo/sequence_tagging/linear_crf.py b/demo/sequence_tagging/linear_crf.py index 736b580bb..0624b1778 100644 --- a/demo/sequence_tagging/linear_crf.py +++ b/demo/sequence_tagging/linear_crf.py @@ -74,7 +74,8 @@ sum_evaluator( chunk_evaluator( name="chunk_f1", - input=[crf_decoding, chunk], + input=crf_decoding, + label=chunk, chunk_scheme="IOB", num_chunk_types=11, ) diff --git a/demo/sequence_tagging/rnn_crf.py b/demo/sequence_tagging/rnn_crf.py index ad1e7b68e..b9b41b243 100644 --- a/demo/sequence_tagging/rnn_crf.py +++ b/demo/sequence_tagging/rnn_crf.py @@ -112,7 +112,8 @@ sum_evaluator( chunk_evaluator( name="chunk_f1", - input=[crf_decoding, chunk], + input=crf_decoding, + label=chunk, chunk_scheme="IOB", num_chunk_types=11, ) diff --git a/python/paddle/trainer_config_helpers/evaluators.py b/python/paddle/trainer_config_helpers/evaluators.py index 0ee116d8c..15b573b48 100644 --- a/python/paddle/trainer_config_helpers/evaluators.py +++ b/python/paddle/trainer_config_helpers/evaluators.py @@ -327,9 +327,11 @@ def ctc_error_evaluator( @wrap_name_default() def chunk_evaluator( input, + label, + chunk_scheme, + num_chunk_types, name=None, - chunk_scheme=None, - num_chunk_types=None, ): + ): """ Chunk evaluator is used to evaluate segment labelling accuracy for a sequence. It calculates the chunk detection F1 score. @@ -363,22 +365,24 @@ def chunk_evaluator( .. code-block:: python - eval = chunk_evaluator(input) + eval = chunk_evaluator(input, label, chunk_scheme, num_chunk_types) :param input: The input layers. :type input: LayerOutput - :param name: The Evaluator name, it is not necessary. - :type name: basename|None + :param label: An input layer containing the ground truth label. + :type label: LayerOutput :param chunk_scheme: The labelling schemes support 4 types. It is one of - "IOB", "IOE", "IOBES", "plain".This Evaluator must - contain this chunk_scheme. + "IOB", "IOE", "IOBES", "plain". It is required. :type chunk_scheme: basestring :param num_chunk_types: number of chunk types other than "other" + :param name: The Evaluator name, it is optional. + :type name: basename|None """ evaluator_base( name=name, type="chunk", input=input, + label=label, chunk_scheme=chunk_scheme, num_chunk_types=num_chunk_types) -- GitLab