From e423c5d03089c204f484cf8222f1f0b8ad825ed0 Mon Sep 17 00:00:00 2001 From: Yu Yang Date: Tue, 11 Apr 2017 16:03:09 +0800 Subject: [PATCH] It is no need to config num_classes in hsigmoid It should be always equals to label's size. --- python/paddle/trainer_config_helpers/layers.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/python/paddle/trainer_config_helpers/layers.py b/python/paddle/trainer_config_helpers/layers.py index 10e279f767c..aae419566f0 100755 --- a/python/paddle/trainer_config_helpers/layers.py +++ b/python/paddle/trainer_config_helpers/layers.py @@ -1916,7 +1916,7 @@ def cos_sim(a, b, scale=1, size=1, name=None, layer_attr=None): @layer_support() def hsigmoid(input, label, - num_classes, + num_classes=None, name=None, bias_attr=None, param_attr=None, @@ -1932,8 +1932,7 @@ def hsigmoid(input, .. code-block:: python cost = hsigmoid(input=[layer1, layer2], - label=data_layer, - num_classes=3) + label=data_layer) :param input: Input layers. It could be a LayerOutput or list/tuple of LayerOutput. @@ -1941,12 +1940,14 @@ def hsigmoid(input, :param label: Label layer. :type label: LayerOutput :param num_classes: number of classes. - :type num_classes: int + :type num_classes: int|None :param name: layer name :type name: basestring :param bias_attr: Bias attribute. None means default bias. False means no bias. :type bias_attr: ParameterAttribute|False + :param param_attr: Parameter Attribute. None means default parameter. + :type param_attr: ParameterAttribute|None :param layer_attr: Extra Layer Attribute. :type layer_attr: ExtraLayerAttribute :return: LayerOutput object. @@ -1966,6 +1967,11 @@ def hsigmoid(input, assert isinstance(label, LayerOutput) assert label.layer_type == LayerType.DATA + if num_classes is None: + num_classes = label.size + if num_classes is None or num_classes <= 2: + raise ValueError("hsigmoid label size must larger than 2.") + ipts_for_layer = [] parents = [] for each_input, each_param_attr in zip(input, param_attr): -- GitLab