@@ -359,6 +359,11 @@ def dynamic_lstm(input,
359
359
W_{fh}, W_{oh}`}
360
360
- The shape is (D x 4D), where D is the hidden
361
361
size.
362
+
363
+ If it is set to None or one attribute of ParamAttr,
364
+ dynamic_lstm will create ParamAttr as param_attr.
365
+ If the Initializer of the param_attr is not set, the
366
+ parameter is initialized with Xavier. Default: None.
362
367
bias_attr (ParamAttr|None): The bias attribute for the learnable bias
363
368
weights, which contains two parts, input-hidden
364
369
bias weights and peephole connections weights if
@@ -371,6 +376,11 @@ def dynamic_lstm(input,
371
376
- Biases = { :math:`b_c, b_i, b_f, b_o, W_{ic}, \
372
377
W_{fc}, W_{oc}`}.
373
378
- The shape is (1 x 7D).
379
+
380
+ If it is set to None or one attribute of ParamAttr,
381
+ dynamic_lstm will create ParamAttr as bias_attr.
382
+ If the Initializer of the bias_attr is not set,
383
+ the bias is initialized zero. Default: None.
374
384
use_peepholes (bool): ${use_peepholes_comment}
375
385
is_reverse (bool): ${is_reverse_comment}
376
386
gate_activation (str): ${gate_activation_comment}
@@ -393,7 +403,7 @@ def dynamic_lstm(input,
393
403
forward, _ = fluid.layers.dynamic_lstm(
394
404
input=forward_proj, size=hidden_dim * 4, use_peepholes=False)
395
405
"""
396
-
406
+ assert bias_attr is not False , "bias_attr should not be False in dynamic_lstmp."
397
407
helper = LayerHelper ('lstm' , ** locals ())
398
408
size = size // 4
399
409
weight = helper .create_parameter (
@@ -528,6 +538,11 @@ def dynamic_lstmp(input,
528
538
size.
529
539
- Projection weight = {:math:`W_{rh}`}.
530
540
- The shape of projection weight is (D x P).
541
+
542
+ If it is set to None or one attribute of ParamAttr,
543
+ dynamic_lstm will create ParamAttr as param_attr.
544
+ If the Initializer of the param_attr is not set, the
545
+ parameter is initialized with Xavier. Default: None.
531
546
bias_attr(ParamAttr|None): The bias attribute for the learnable bias
532
547
weights, which contains two parts, input-hidden
533
548
bias weights and peephole connections weights if
@@ -540,6 +555,11 @@ def dynamic_lstmp(input,
540
555
- Biases = { :math:`b_c, b_i, b_f, b_o, W_{ic}, \
541
556
W_{fc}, W_{oc}`}.
542
557
- The shape is (1 x 7D).
558
+
559
+ If it is set to None or one attribute of ParamAttr,
560
+ dynamic_lstm will create ParamAttr as bias_attr.
561
+ If the Initializer of the bias_attr is not set,
562
+ the bias is initialized zero. Default: None.
543
563
use_peepholes(bool): Whether to enable diagonal/peephole connections,
544
564
default `True`.
545
565
is_reverse(bool): Whether to compute reversed LSTM, default `False`.
@@ -584,6 +604,7 @@ def dynamic_lstmp(input,
584
604
proj_activation="tanh")
585
605
"""
586
606
607
+ assert bias_attr is not False , "bias_attr should not be False in dynamic_lstmp."
587
608
helper = LayerHelper ('lstmp' , ** locals ())
588
609
size = size // 4
589
610
weight = helper .create_parameter (
@@ -1283,11 +1304,12 @@ def sequence_conv(input,
1283
1304
If it is set to None or one attribute of ParamAttr, sequence_conv
1284
1305
will create ParamAttr as bias_attr. If the Initializer of the bias_attr
1285
1306
is not set, the bias is initialized zero. Default: None.
1286
- param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
1307
+ param_attr (ParamAttr|None ): The parameter attribute for learnable parameters/weights
1287
1308
of sequence_conv. If it is set to None or one attribute of ParamAttr, sequence_conv
1288
1309
will create ParamAttr as param_attr. If the Initializer of the param_attr
1289
1310
is not set, the parameter is initialized with Xavier. Default: None.
1290
- act (str): the activation type
1311
+ act (str): Activation type, if it is set to None, activation is not appended.
1312
+ Default: None.
1291
1313
name (str|None): A name for this layer(optional). If set None, the layer
1292
1314
will be named automatically. Default: None.
1293
1315
@@ -1502,7 +1524,7 @@ def conv2d(input,
1502
1524
the first half of the filters is only connected to the first half
1503
1525
of the input channels, while the second half of the filters is only
1504
1526
connected to the second half of the input channels. Default: groups=1.
1505
- param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
1527
+ param_attr (ParamAttr|None ): The parameter attribute for learnable parameters/weights
1506
1528
of conv2d. If it is set to None or one attribute of ParamAttr, conv2d
1507
1529
will create ParamAttr as param_attr. If the Initializer of the param_attr
1508
1530
is not set, the parameter is initialized with :math:`Normal(0.0, std)`,
@@ -1675,7 +1697,7 @@ def conv3d(input,
1675
1697
the first half of the filters is only connected to the first half
1676
1698
of the input channels, while the second half of the filters is only
1677
1699
connected to the second half of the input channels. Default: groups=1
1678
- param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
1700
+ param_attr (ParamAttr|None ): The parameter attribute for learnable parameters/weights
1679
1701
of conv3d. If it is set to None or one attribute of ParamAttr, conv3d
1680
1702
will create ParamAttr as param_attr. If it is set to None, the parameter
1681
1703
is initialized with :math:`Normal(0.0, std)`, and the :math:`std` is
@@ -2137,8 +2159,14 @@ def batch_norm(input,
2137
2159
is_test(bool, Default False): Used for training or training.
2138
2160
momentum(float, Default 0.9):
2139
2161
epsilon(float, Default 1e-05):
2140
- param_attr(ParamAttr): The parameter attribute for Parameter `scale`.
2141
- bias_attr(ParamAttr): The parameter attribute for Parameter `bias`.
2162
+ param_attr(ParamAttr|None): The parameter attribute for Parameter `scale`
2163
+ of batch_norm. If it is set to None or one attribute of ParamAttr, batch_norm
2164
+ will create ParamAttr as param_attr. If the Initializer of the param_attr
2165
+ is not set, the parameter is initialized with Xavier. Default: None.
2166
+ bias_attr(ParamAttr|None): The parameter attribute for the bias of batch_norm.
2167
+ If it is set to None or one attribute of ParamAttr, batch_norm
2168
+ will create ParamAttr as bias_attr. If the Initializer of the bias_attr
2169
+ is not set, the bias is initialized zero. Default: None.
2142
2170
data_layout(string, default NCHW): NCHW|NHWC
2143
2171
in_place(bool, Default False): Make the input and output of batch norm reuse memory.
2144
2172
name(string, Default None): A name for this layer(optional). If set None, the layer
@@ -2158,6 +2186,7 @@ def batch_norm(input,
2158
2186
hidden1 = fluid.layers.fc(input=x, size=200, param_attr='fc1.w')
2159
2187
hidden2 = fluid.layers.batch_norm(input=hidden1)
2160
2188
"""
2189
+ assert bias_attr is not False , "bias_attr should not be False in batch_norm."
2161
2190
helper = LayerHelper ('batch_norm' , ** locals ())
2162
2191
dtype = helper .input_dtype ()
2163
2192
@@ -2428,7 +2457,7 @@ def conv2d_transpose(input,
2428
2457
first half of the input channels, while the second half of the
2429
2458
filters is only connected to the second half of the input channels.
2430
2459
Default: groups = 1.
2431
- param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
2460
+ param_attr (ParamAttr|None ): The parameter attribute for learnable parameters/weights
2432
2461
of conv2d_transpose. If it is set to None or one attribute of ParamAttr, conv2d_transpose
2433
2462
will create ParamAttr as param_attr. If the Initializer of the param_attr
2434
2463
is not set, the parameter is initialized with Xavier. Default: None.
@@ -2457,7 +2486,7 @@ def conv2d_transpose(input,
2457
2486
data = fluid.layers.data(name='data', shape=[3, 32, 32], dtype='float32')
2458
2487
conv2d_transpose = fluid.layers.conv2d_transpose(input=data, num_filters=2, filter_size=3)
2459
2488
"""
2460
-
2489
+ assert param_attr is not False , "param_attr should not be False in conv2d_transpose."
2461
2490
input_channel = input .shape [1 ]
2462
2491
2463
2492
op_type = 'conv2d_transpose'
@@ -2616,7 +2645,7 @@ def conv3d_transpose(input,
2616
2645
first half of the input channels, while the second half of the
2617
2646
filters is only connected to the second half of the input channels.
2618
2647
Default: groups=1
2619
- param_attr (ParamAttr): The parameter attribute for learnable parameters/weights
2648
+ param_attr (ParamAttr|None ): The parameter attribute for learnable parameters/weights
2620
2649
of conv3d_transpose. If it is set to None or one attribute of ParamAttr, conv3d_transpose
2621
2650
will create ParamAttr as param_attr. If the Initializer of the param_attr
2622
2651
is not set, the parameter is initialized with Xavier. Default: None.
@@ -2645,6 +2674,7 @@ def conv3d_transpose(input,
2645
2674
data = fluid.layers.data(name='data', shape=[3, 12, 32, 32], dtype='float32')
2646
2675
conv3d_transpose = fluid.layers.conv3d_transpose(input=data, num_filters=2, filter_size=3)
2647
2676
"""
2677
+ assert param_attr is not False , "param_attr should not be False in conv3d_transpose."
2648
2678
l_type = "conv3d_transpose"
2649
2679
helper = LayerHelper (l_type , ** locals ())
2650
2680
if not isinstance (input , Variable ):
@@ -4018,7 +4048,8 @@ def nce(input,
4018
4048
sample_weight = None ,
4019
4049
param_attr = None ,
4020
4050
bias_attr = None ,
4021
- num_neg_samples = None ):
4051
+ num_neg_samples = None ,
4052
+ name = None ):
4022
4053
"""
4023
4054
${comment}
4024
4055
@@ -4029,9 +4060,18 @@ def nce(input,
4029
4060
sample_weight (Variable|None): A Variable of shape [batch_size, 1]
4030
4061
storing a weight for each sample. The default weight for each
4031
4062
sample is 1.0.
4032
- param_attr (ParamAttr|None): attributes for parameter
4033
- bias_attr (ParamAttr|None): attributes for bias
4063
+ param_attr (ParamAttr|None): The parameter attribute for learnable parameters/weights
4064
+ of nce. If it is set to None or one attribute of ParamAttr, nce
4065
+ will create ParamAttr as param_attr. If the Initializer of the param_attr
4066
+ is not set, the parameter is initialized with Xavier. Default: None.
4067
+ bias_attr (ParamAttr|bool|None): The parameter attribute for the bias of nce.
4068
+ If it is set to False, no bias will be added to the output units.
4069
+ If it is set to None or one attribute of ParamAttr, nce
4070
+ will create ParamAttr as bias_attr. If the Initializer of the bias_attr
4071
+ is not set, the bias is initialized zero. Default: None.
4034
4072
num_neg_samples (int): ${num_neg_samples_comment}
4073
+ name (str|None): A name for this layer(optional). If set None, the layer
4074
+ will be named automatically. Default: None.
4035
4075
4036
4076
Returns:
4037
4077
Variable: The output nce loss.
@@ -4064,19 +4104,28 @@ def nce(input,
4064
4104
"""
4065
4105
helper = LayerHelper ('nce' , ** locals ())
4066
4106
assert isinstance (input , Variable )
4067
- dim = input .shape [1 ]
4068
4107
assert isinstance (label , Variable )
4108
+
4109
+ dim = input .shape [1 ]
4069
4110
num_true_class = label .shape [1 ]
4070
4111
w = helper .create_parameter (
4071
4112
attr = helper .param_attr ,
4072
4113
shape = [num_total_classes , dim ],
4073
4114
is_bias = False ,
4074
4115
dtype = input .dtype )
4075
- b = helper .create_parameter (
4076
- attr = helper .bias_attr ,
4077
- shape = [num_total_classes , 1 ],
4078
- is_bias = True ,
4079
- dtype = input .dtype )
4116
+ inputs = {
4117
+ 'Input' : input ,
4118
+ 'Label' : label ,
4119
+ 'Weight' : w ,
4120
+ 'SampleWeight' : sample_weight if sample_weight is not None else []
4121
+ }
4122
+ if helper .bias_attr :
4123
+ b = helper .create_parameter (
4124
+ attr = helper .bias_attr ,
4125
+ shape = [num_total_classes , 1 ],
4126
+ is_bias = True ,
4127
+ dtype = input .dtype )
4128
+ inputs ['Bias' ] = b
4080
4129
cost = helper .create_tmp_variable (dtype = input .dtype )
4081
4130
sample_logits = helper .create_tmp_variable (dtype = input .dtype )
4082
4131
sample_labels = helper .create_tmp_variable (dtype = label .dtype )
@@ -4093,13 +4142,7 @@ def nce(input,
4093
4142
4094
4143
helper .append_op (
4095
4144
type = 'nce' ,
4096
- inputs = {
4097
- 'Input' : input ,
4098
- 'Label' : label ,
4099
- 'Weight' : w ,
4100
- 'Bias' : b ,
4101
- 'SampleWeight' : sample_weight if sample_weight is not None else []
4102
- },
4145
+ inputs = inputs ,
4103
4146
outputs = {
4104
4147
'Cost' : cost ,
4105
4148
'SampleLogits' : sample_logits ,
@@ -4109,7 +4152,12 @@ def nce(input,
4109
4152
return cost / (num_neg_samples + 1 )
4110
4153
4111
4154
4112
- def hsigmoid (input , label , num_classes , param_attr = None , bias_attr = None ):
4155
+ def hsigmoid (input ,
4156
+ label ,
4157
+ num_classes ,
4158
+ param_attr = None ,
4159
+ bias_attr = None ,
4160
+ name = None ):
4113
4161
"""
4114
4162
The hierarchical sigmoid operator is used to accelerate the training
4115
4163
process of language model. This operator organizes the classes into a
@@ -4130,11 +4178,17 @@ def hsigmoid(input, label, num_classes, param_attr=None, bias_attr=None):
4130
4178
label (Variable): The tensor variable contains labels of training data.
4131
4179
It's a tensor with shape is :math:`[N \\ times 1]`.
4132
4180
num_classes: (int), The number of classes, must not be less than 2.
4133
- param_attr (ParamAttr|list of ParamAttr, default None): The parameter
4134
- attribute for learnable parameters/weights of this layer.
4135
- bias_attr (ParamAttr|list of ParamAttr, default None): The parameter
4136
- attribute for the bias of this layer. If it is set to False, no
4137
- bias will be applied.
4181
+ param_attr (ParamAttr|None): The parameter attribute for learnable parameters/weights
4182
+ of hsigmoid. If it is set to None or one attribute of ParamAttr, hsigmoid
4183
+ will create ParamAttr as param_attr. If the Initializer of the param_attr
4184
+ is not set, the parameter is initialized with Xavier. Default: None.
4185
+ bias_attr (ParamAttr|bool|None): The parameter attribute for the bias of hsigmoid.
4186
+ If it is set to False, no bias will be added to the output units.
4187
+ If it is set to None or one attribute of ParamAttr, hsigmoid
4188
+ will create ParamAttr as bias_attr. If the Initializer of the bias_attr
4189
+ is not set, the bias is initialized zero. Default: None.
4190
+ name (str|None): A name for this layer(optional). If set None, the layer
4191
+ will be named automatically. Default: None.
4138
4192
4139
4193
Returns:
4140
4194
Out: (Tensor) The cost of hierarchical sigmoid operator. the shape is [N, 1]
0 commit comments