Skip to content

Commit dd711c3

Browse files
committed
"add beam search"
1 parent dbe0fe6 commit dd711c3

File tree

1 file changed

+19
-7
lines changed
  • python/paddle/fluid/layers

1 file changed

+19
-7
lines changed

python/paddle/fluid/layers/nn.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -834,11 +834,14 @@ def linear_chain_crf(input, label, param_attr=None):
834834
835835
Args:
836836
input(${emission_type}): ${emission_comment}
837+
input(${transition_type}): ${transition_comment}
837838
label(${label_type}): ${label_comment}
838839
param_attr(ParamAttr): The attribute of the learnable parameter.
839840
840841
Returns:
841842
${log_likelihood_comment}
843+
${transitionexps_comment}
844+
${emissionexps_comment}
842845
843846
"""
844847
helper = LayerHelper('linear_chain_crf', **locals())
@@ -1170,10 +1173,6 @@ def sequence_conv(input,
11701173
Variable: output of sequence_conv
11711174
"""
11721175

1173-
# FIXME(dzh) : want to unify the argument of python layer
1174-
# function. So we ignore some unecessary attributes.
1175-
# such as, padding_trainable, context_start.
1176-
11771176
helper = LayerHelper('sequence_conv', **locals())
11781177
dtype = helper.input_dtype()
11791178
filter_shape = [filter_size * input.shape[1], num_filters]
@@ -2051,18 +2050,31 @@ def layer_norm(input,
20512050

20522051
def beam_search_decode(ids, scores, name=None):
20532052
"""
2053+
Beam Search Decode
2054+
20542055
This layers is to pack the output of beam search layer into sentences and
20552056
associated scores. It is usually called after the beam search layer.
2057+
Typically, the output of beam search layer is a tensor of selected ids, with
2058+
a tensor of the score of each id. Beam search layer's output ids, however,
2059+
are generated directly during the tree search, and they are stacked by each
2060+
level of the search tree. Thus we need to reorganize them into sentences,
2061+
based on the score of each id. This layer takes the output of beam search
2062+
layer as input and repack them into sentences.
20562063
20572064
${beam_search_decode}
20582065
20592066
Args:
2060-
ids (Variable): ${ids_comment}
2061-
scores (Variable): ${scores_comment}
2067+
ids (Variable): The selected ids, output of beam search layer.
2068+
scores (Variable): The associated scores of the ids, out put of beam
2069+
search layer.
20622070
name (str): The name of this layer. It is optional.
20632071
20642072
Returns:
2065-
tuple(Variable): a tuple of two output variable: sentence_ids, sentence_scores
2073+
tuple(Variable): a tuple of two output tensors: sentence_ids, sentence_scores.
2074+
sentence_ids is a tensor with shape [size, length], where size is the
2075+
beam size of beam search, and length is the length of each sentence.
2076+
Note that the length of sentences may vary.
2077+
sentence_scores is a tensor with the same shape as sentence_ids.
20662078
20672079
Examples:
20682080
.. code-block:: python

0 commit comments

Comments
 (0)