From ce6394ed73ae5f9b6ad44c0e8dca762791001f2d Mon Sep 17 00:00:00 2001 From: yuyang18 Date: Wed, 13 Jun 2018 17:50:27 +0800 Subject: [PATCH] Polish example --- paddle/fluid/operators/row_conv_op.cc | 2 +- paddle/fluid/operators/uniform_random_op.cc | 2 -- python/paddle/fluid/layers/nn.py | 30 ++++++++++++++------- python/paddle/fluid/layers/ops.py | 21 ++++++++++++++- python/paddle/fluid/layers/tensor.py | 15 +++++------ 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/paddle/fluid/operators/row_conv_op.cc b/paddle/fluid/operators/row_conv_op.cc index f4b540f1cbb..d7286111fd9 100644 --- a/paddle/fluid/operators/row_conv_op.cc +++ b/paddle/fluid/operators/row_conv_op.cc @@ -114,7 +114,7 @@ and a filter ($W$) of size $context \times d$, the output sequence is convolved as: $$ -out_{i, :} = \sum_{j=i}^{i + context} in_{j,:} \dot W_{i-j, :} +out_{i, :} = \\sum_{j=i}^{i + context} in_{j,:} \\cdot W_{i-j, :} $$ In the above equation: diff --git a/paddle/fluid/operators/uniform_random_op.cc b/paddle/fluid/operators/uniform_random_op.cc index 65525526c9a..edd1baa4ace 100644 --- a/paddle/fluid/operators/uniform_random_op.cc +++ b/paddle/fluid/operators/uniform_random_op.cc @@ -88,8 +88,6 @@ class UniformRandomOpMaker : public framework::OpProtoAndCheckerMaker { void Make() override { AddOutput("Out", "The output tensor of uniform random op"); AddComment(R"DOC( -Uniform random operator. - This operator initializes a tensor with random values sampled from a uniform distribution. The random result is in set [min, max]. diff --git a/python/paddle/fluid/layers/nn.py b/python/paddle/fluid/layers/nn.py index fe60d8b78d4..f1241d94792 100644 --- a/python/paddle/fluid/layers/nn.py +++ b/python/paddle/fluid/layers/nn.py @@ -1718,10 +1718,14 @@ def layer_norm(input, h & = f(\\frac{g}{\\sigma}(a - \\mu) + b) - >>> import paddle.fluid as fluid - >>> data = fluid.layers.data(name='data', shape=[3, 32, 32], - >>> dtype='float32') - >>> x = fluid.layers.layer_norm(input=data, begin_norm_axis=1) + * :math:`a`: the vector representation of the summed inputs to the neurons + in that layer. + + * :math:`H`: the number of hidden units in a layers + + * :math:`g`: the trainable scale parameter. + + * :math:`b`: the trainable bias parameter. Args: input(Variable): The input tensor variable. @@ -1742,6 +1746,12 @@ def layer_norm(input, Returns: ${y_comment} + + Examples: + + >>> data = fluid.layers.data(name='data', shape=[3, 32, 32], + >>> dtype='float32') + >>> x = fluid.layers.layer_norm(input=data, begin_norm_axis=1) """ helper = LayerHelper('layer_norm', **locals()) dtype = helper.input_dtype() @@ -3262,12 +3272,6 @@ def row_conv(input, future_context_size, param_attr=None, act=None): """ ${comment} - >>> import paddle.fluid as fluid - >>> x = fluid.layers.data(name='x', shape=[16], - >>> dtype='float32', lod_level=1) - >>> out = fluid.layers.row_conv(input=x, future_context_size=2) - - Args: input (${x_type}): ${x_comment}. future_context_size (int): Future context size. Please note, the shape @@ -3278,6 +3282,12 @@ def row_conv(input, future_context_size, param_attr=None, act=None): Returns: ${out_comment}. + + Examples: + >>> import paddle.fluid as fluid + >>> x = fluid.layers.data(name='x', shape=[16], + >>> dtype='float32', lod_level=1) + >>> out = fluid.layers.row_conv(input=x, future_context_size=2) """ helper = LayerHelper('row_conv', **locals()) dtype = helper.input_dtype() diff --git a/python/paddle/fluid/layers/ops.py b/python/paddle/fluid/layers/ops.py index 98f169e8f08..46c6fd686e0 100644 --- a/python/paddle/fluid/layers/ops.py +++ b/python/paddle/fluid/layers/ops.py @@ -64,7 +64,6 @@ __all__ = [ 'logical_or', 'logical_xor', 'logical_not', - 'uniform_random', 'uniform_random_batch_size_like', 'gaussian_random', 'gaussian_random_batch_size_like', @@ -79,3 +78,23 @@ __all__ = [ for _OP in set(__all__): globals()[_OP] = generate_layer_fn(_OP) + +__all__ += ["uniform_random"] + +_uniform_random_ = generate_layer_fn('uniform_random') + + +def uniform_random(shape, dtype=None, min=None, max=None, seed=None): + kwargs = dict() + for name in locals(): + val = locals()[name] + if val is not None: + kwargs[name] = val + return _uniform_random_(**kwargs) + +uniform_random.__doc__ = _uniform_random_.__doc__ + "\n"\ ++""" +Examples: + + >>> result = fluid.layers.uniform_random(shape=[32, 784]) +""" diff --git a/python/paddle/fluid/layers/tensor.py b/python/paddle/fluid/layers/tensor.py index 241bbe78bd5..04efc40af5e 100644 --- a/python/paddle/fluid/layers/tensor.py +++ b/python/paddle/fluid/layers/tensor.py @@ -6,7 +6,7 @@ # # http://www.apache.org/licenses/LICENSE-2.0 # -# Unless required by applicable law or agreed to in writing, software +# Unlessf required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and @@ -57,12 +57,6 @@ def create_parameter(shape, NOTE: this is a very low-level API. This API is useful when you create operator by your self. instead of using layers. - >>> import paddle.fluid as fluid - >>> W = fluid.layers.create_parameter(shape=[784, 200], dtype='float32') - >>> data = fluid.layers.data(name="img", shape=[64, 784], - >>> append_batch_size=False) - >>> hidden = fluid.layers.matmul(x=data, y=W) - Args: shape(list[int]): shape of the parameter dtype(string): element type of the parameter @@ -74,7 +68,12 @@ def create_parameter(shape, default_initializer(Initializer): initializer for the parameter Returns: - the created parameter + the created parameter. + + Examples: + >>> W = fluid.layers.create_parameter(shape=[784, 200], dtype='float32') + >>> data = fluid.layers.data(name="img", shape=[64, 784], append_batch_size=False) + >>> hidden = fluid.layers.matmul(x=data, y=W) """ helper = LayerHelper("create_parameter", **locals()) if attr is None: -- GitLab