Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into sub_sequence_op

release/0.11.0
wanghaox 8 years ago
commit 29c25828b0

2
.gitignore vendored

@ -21,7 +21,7 @@ third_party/
cmake-build-* cmake-build-*
# generated while compiling # generated while compiling
python/paddle/v2/framework/core.so python/paddle/v2/fluid/core.so
paddle/pybind/pybind.h paddle/pybind/pybind.h
CMakeFiles CMakeFiles
cmake_install.cmake cmake_install.cmake

@ -27,6 +27,7 @@ class BeamSearchDecodeOp : public framework::OperatorBase {
void Run(const framework::Scope& scope, void Run(const framework::Scope& scope,
const platform::DeviceContext& dev_ctx) const override { const platform::DeviceContext& dev_ctx) const override {
framework::ExecutionContext ctx(*this, scope, dev_ctx); framework::ExecutionContext ctx(*this, scope, dev_ctx);
const LoDTensorArray* ids = ctx.Input<LoDTensorArray>("Ids"); const LoDTensorArray* ids = ctx.Input<LoDTensorArray>("Ids");
const LoDTensorArray* scores = ctx.Input<LoDTensorArray>("Scores"); const LoDTensorArray* scores = ctx.Input<LoDTensorArray>("Scores");
const size_t step_num = ids->size(); const size_t step_num = ids->size();

@ -29,7 +29,7 @@ class L1NormKernel : public framework::OpKernel<T> {
Out->mutable_data<T>(context.GetPlace()); Out->mutable_data<T>(context.GetPlace());
auto x = framework::EigenVector<T>::Flatten(*X); auto x = framework::EigenVector<T>::Flatten(*X);
auto out = framework::EigenVector<T>::Flatten(*Out); auto out = framework::EigenScalar<T>::From(*Out);
auto place = context.GetEigenDevice<Place>(); auto place = context.GetEigenDevice<Place>();
out.device(place) = x.abs().sum(); out.device(place) = x.abs().sum();

@ -0,0 +1,120 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless 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
limitations under the License. */
#include "paddle/operators/lod_reset_op.h"
namespace paddle {
namespace operators {
class LoDResetOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
void InferShape(framework::InferShapeContext *ctx) const override {
// input check
PADDLE_ENFORCE(ctx->HasInput("X"),
"Input(X) of LoDResetOp should not be null.");
PADDLE_ENFORCE(ctx->HasOutput("Out"),
"Output(Out) of LoDResetOp should not be null.");
// If target LoD is not set form Input(), then it must be set from Attr().
if (!ctx->HasInput("TargetLoD")) {
auto level0 = ctx->Attrs().Get<std::vector<int>>("target_lod");
PADDLE_ENFORCE(level0.size() > 1,
"Target LoD is not found, should be set to be a valid one "
"through Input() or Attr().");
}
ctx->SetOutputDim("Out", ctx->GetInputDim("X"));
}
protected:
framework::OpKernelType GetKernelType(
const framework::ExecutionContext &ctx) const override {
return framework::OpKernelType(
framework::ToDataType(ctx.Input<framework::LoDTensor>("X")->type()),
ctx.device_context());
}
};
class LoDResetOpMaker : public framework::OpProtoAndCheckerMaker {
public:
LoDResetOpMaker(framework::OpProto *proto,
framework::OpAttrChecker *op_checker)
: OpProtoAndCheckerMaker(proto, op_checker) {
AddInput("X", "(LoDTensor) The input tensor of lod_reset operator.");
AddInput("TargetLoD",
"(Tensor, optional) The target level 0 LoD from Input().")
.AsDispensable();
AddOutput("Out", "(LoDTensor) The output tensor of lod_reset operator.");
AddAttr<std::vector<int>>("target_lod",
"The target level 0 LoD from Attr().")
.SetDefault(std::vector<int>{});
AddComment(R"DOC(LoDReset operator
Reset LoD of Input(X) into a new one specified by Input(TargetLoD) or
Attr(target_lod), or set LoD for Input(X) if it doesn't have one.
Currently the lod_reset operator only supports the reset of level 0 LoD.
At least one of Input(TargetLoD) and Attr(target_lod) must be set,
and if both of them are set, Input(TargetLoD) will be chosen as the
target LoD.
An example:
Given a float LoDTensor X with shape (6, 1), its transpose form represents
[1.0, 2.0, 3.0, 4.0, 5.0, 6.0],
with LoD = [[0, 2, 5, 6]] and the three (transposed) sequences look like
[1.0, 2.0], [3.0, 4.0, 5.0], [6.0].
If target LoD = [0, 4, 6], the lod_reset operator will reset the LoD and
the sequences that the LoDTensor Output(Out) contains becomes:
[1.0, 2.0, 3.0, 4.0], [5.0, 6.0].
)DOC");
}
};
class LoDResetGradOp : public framework::OperatorWithKernel {
public:
using framework::OperatorWithKernel::OperatorWithKernel;
void InferShape(framework::InferShapeContext *ctx) const override {
PADDLE_ENFORCE(ctx->HasInput("X"), "Input(X) shouldn't be null.");
PADDLE_ENFORCE(ctx->HasInput(framework::GradVarName("Out")),
"Input(Out@GRAD) shouldn't be null.");
ctx->SetOutputDim(framework::GradVarName("X"), ctx->GetInputDim("X"));
}
protected:
framework::OpKernelType GetKernelType(
const framework::ExecutionContext &ctx) const override {
return framework::OpKernelType(
framework::ToDataType(ctx.Input<framework::LoDTensor>("X")->type()),
ctx.device_context());
}
};
} // namespace operators
} // namespace paddle
namespace ops = paddle::operators;
REGISTER_OP(lod_reset, ops::LoDResetOp, ops::LoDResetOpMaker, lod_reset_grad,
ops::LoDResetGradOp);
REGISTER_OP_CPU_KERNEL(lod_reset,
ops::LoDResetKernel<paddle::platform::CPUPlace, float>,
ops::LoDResetKernel<paddle::platform::CPUPlace, double>);
REGISTER_OP_CPU_KERNEL(
lod_reset_grad, ops::LoDResetGradKernel<paddle::platform::CPUPlace, float>,
ops::LoDResetGradKernel<paddle::platform::CPUPlace, double>);

@ -0,0 +1,24 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless 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
limitations under the License. */
#include "paddle/operators/lod_reset_op.h"
namespace ops = paddle::operators;
REGISTER_OP_GPU_KERNEL(lod_reset,
ops::LoDResetKernel<paddle::platform::GPUPlace, float>,
ops::LoDResetKernel<paddle::platform::GPUPlace, double>);
REGISTER_OP_GPU_KERNEL(
lod_reset_grad, ops::LoDResetGradKernel<paddle::platform::GPUPlace, float>,
ops::LoDResetGradKernel<paddle::platform::GPUPlace, double>);

@ -0,0 +1,78 @@
/* Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserve.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless 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
limitations under the License. */
#pragma once
#include "paddle/framework/eigen.h"
#include "paddle/framework/op_registry.h"
namespace paddle {
namespace operators {
template <typename Place, typename T>
class LoDResetKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const {
auto* out = ctx.Output<framework::LoDTensor>("Out");
auto* in = ctx.Input<framework::LoDTensor>("X");
auto* lod_t = ctx.Input<framework::Tensor>("TargetLoD");
std::vector<int> level0;
if (lod_t) {
auto* lod = lod_t->data<int>();
if (platform::is_gpu_place(ctx.GetPlace())) {
framework::Tensor lod_cpu;
lod_cpu.CopyFrom(*lod_t, platform::CPUPlace(), ctx.device_context());
lod = lod_cpu.data<int>();
}
level0 = std::vector<int>(lod, lod + lod_t->numel());
} else {
level0 = ctx.Attr<std::vector<int>>("target_lod");
}
PADDLE_ENFORCE(level0.size() > 1UL,
"The size of target LoD should be greater than 1.");
PADDLE_ENFORCE(level0[0] == 0,
"Target LoD should be a vector starting from 0.");
PADDLE_ENFORCE(level0.back() == in->dims()[0],
"Target LoD should be a vector end with the "
"first dimension of Input(X).");
for (size_t i = 0; i < level0.size() - 1; ++i) {
PADDLE_ENFORCE(level0[i + 1] > level0[i],
"Target LoD should be an ascending vector.");
}
out->ShareDataWith(*in);
// cast level0 to size_t
std::vector<size_t> ulevel0(level0.size(), 0);
std::transform(level0.begin(), level0.end(), ulevel0.begin(),
[](int a) { return static_cast<size_t>(a); });
framework::LoD target_lod;
target_lod.push_back(ulevel0);
out->set_lod(target_lod);
}
};
template <typename Place, typename T>
class LoDResetGradKernel : public framework::OpKernel<T> {
public:
void Compute(const framework::ExecutionContext& ctx) const {
auto* d_out = ctx.Input<framework::Tensor>(framework::GradVarName("Out"));
auto* d_x = ctx.Output<framework::Tensor>(framework::GradVarName("X"));
d_x->ShareDataWith(*d_out);
}
};
} // namespace operators
} // namespace paddle

@ -29,7 +29,7 @@ class SquaredL2NormKernel : public framework::OpKernel<T> {
Out->mutable_data<T>(context.GetPlace()); Out->mutable_data<T>(context.GetPlace());
auto x = framework::EigenVector<T>::Flatten(*X); auto x = framework::EigenVector<T>::Flatten(*X);
auto out = framework::EigenVector<T>::Flatten(*Out); auto out = framework::EigenScalar<T>::From(*Out);
auto place = context.GetEigenDevice<Place>(); auto place = context.GetEigenDevice<Place>();
out.device(place) = x.square().sum(); out.device(place) = x.square().sum();

@ -42,6 +42,9 @@ limitations under the License. */
#include "paddle/platform/gpu_info.h" #include "paddle/platform/gpu_info.h"
#endif #endif
// disable auto conversion to list in Python
PYBIND11_MAKE_OPAQUE(paddle::framework::LoDTensorArray);
namespace paddle { namespace paddle {
namespace pybind { namespace pybind {
static size_t UniqueIntegerGenerator(const std::string &prefix) { static size_t UniqueIntegerGenerator(const std::string &prefix) {

@ -37,10 +37,10 @@ configure_file(${CMAKE_CURRENT_SOURCE_DIR}/setup.py.in
${CMAKE_CURRENT_BINARY_DIR}/setup.py) ${CMAKE_CURRENT_BINARY_DIR}/setup.py)
add_custom_command(OUTPUT ${PADDLE_SOURCE_DIR}/python/paddle/v2/framework/core.so add_custom_command(OUTPUT ${PADDLE_SOURCE_DIR}/python/paddle/v2/fluid/core.so
COMMAND cmake -E copy $<TARGET_FILE:paddle_pybind> ${PADDLE_SOURCE_DIR}/python/paddle/v2/framework/core.so COMMAND cmake -E copy $<TARGET_FILE:paddle_pybind> ${PADDLE_SOURCE_DIR}/python/paddle/v2/fluid/core.so
DEPENDS paddle_pybind) DEPENDS paddle_pybind)
add_custom_target(copy_paddle_pybind ALL DEPENDS ${PADDLE_SOURCE_DIR}/python/paddle/v2/framework/core.so) add_custom_target(copy_paddle_pybind ALL DEPENDS ${PADDLE_SOURCE_DIR}/python/paddle/v2/fluid/core.so)
add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp add_custom_command(OUTPUT ${PADDLE_PYTHON_BUILD_DIR}/.timestamp
@ -66,7 +66,7 @@ if (WITH_TESTING)
add_subdirectory(paddle/v2/tests) add_subdirectory(paddle/v2/tests)
add_subdirectory(paddle/v2/reader/tests) add_subdirectory(paddle/v2/reader/tests)
add_subdirectory(paddle/v2/plot/tests) add_subdirectory(paddle/v2/plot/tests)
add_subdirectory(paddle/v2/framework/tests) add_subdirectory(paddle/v2/fluid/tests)
endif() endif()
endif() endif()
install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR} install(DIRECTORY ${PADDLE_PYTHON_PACKAGE_DIR}

@ -3592,10 +3592,9 @@ def lstm_step_layer(input,
:type gate_act: BaseActivation :type gate_act: BaseActivation
:param state_act: State Activation Type. TanhActivation is the default. :param state_act: State Activation Type. TanhActivation is the default.
:type state_act: BaseActivation :type state_act: BaseActivation
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is
whose type is not ParameterAttribute, no bias is defined. If the set to True or None, the bias is initialized to zero.
parameter is set to True, the bias is initialized to zero. :type bias_attr: ParameterAttribute | None | True
:type bias_attr: ParameterAttribute | None | bool | Any
:param layer_attr: layer's extra attribute. :param layer_attr: layer's extra attribute.
:type layer_attr: ExtraLayerAttribute :type layer_attr: ExtraLayerAttribute
:return: LayerOutput object. :return: LayerOutput object.
@ -3650,9 +3649,10 @@ def gru_step_layer(input,
:param name: The name of this layer. It is optional. :param name: The name of this layer. It is optional.
:param gate_act: Activation type of this layer's two gates. Default is Sigmoid. :param gate_act: Activation type of this layer's two gates. Default is Sigmoid.
:type gate_act: BaseActivation :type gate_act: BaseActivation
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is set to
whose type is not ParameterAttribute, no bias is defined. If the False or an object whose type is not ParameterAttribute, no bias
parameter is set to True, the bias is initialized to zero. is defined. If this parameter is set to True,
the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param param_attr: the parameter_attribute for transforming the output_mem :param param_attr: the parameter_attribute for transforming the output_mem
from previous step. from previous step.
@ -3712,9 +3712,10 @@ def gru_step_naive_layer(input,
:type act: BaseActivation :type act: BaseActivation
:param gate_act: Activation type of this layer's two gates. Default is Sigmoid. :param gate_act: Activation type of this layer's two gates. Default is Sigmoid.
:type gate_act: BaseActivation :type gate_act: BaseActivation
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is set to
whose type is not ParameterAttribute, no bias is defined. If the False or an object whose type is not ParameterAttribute, no bias
parameter is set to True, the bias is initialized to zero. is defined. If this parameter is set to True,
the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param param_attr: :param param_attr:
:param layer_attr: :param layer_attr:
@ -3844,9 +3845,10 @@ def recurrent_layer(input,
:type input: LayerOutput :type input: LayerOutput
:param act: Activation type. TanhActivation is the default. :param act: Activation type. TanhActivation is the default.
:type act: BaseActivation :type act: BaseActivation
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is set to
whose type is not ParameterAttribute, no bias is defined. If the False or an object whose type is not ParameterAttribute,
parameter is set to True, the bias is initialized to zero. no bias is defined. If the parameter is set to True,
the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param param_attr: parameter attribute. :param param_attr: parameter attribute.
:type param_attr: ParameterAttribute :type param_attr: ParameterAttribute
@ -4836,9 +4838,10 @@ def tensor_layer(a,
:type act: BaseActivation :type act: BaseActivation
:param param_attr: The Parameter Attribute. :param param_attr: The Parameter Attribute.
:type param_attr: ParameterAttribute :type param_attr: ParameterAttribute
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is set to
whose type is not ParameterAttribute, no bias is defined. If the False or an object whose type is not ParameterAttribute,
parameter is set to True, the bias is initialized to zero. no bias is defined. If this parameter is set to True,
the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param layer_attr: Extra Layer config. :param layer_attr: Extra Layer config.
:type layer_attr: ExtraLayerAttribute | None :type layer_attr: ExtraLayerAttribute | None
@ -4900,9 +4903,10 @@ def selective_fc_layer(input,
:type act: BaseActivation :type act: BaseActivation
:param param_attr: The Parameter Attribute. :param param_attr: The Parameter Attribute.
:type param_attr: ParameterAttribute :type param_attr: ParameterAttribute
:param bias_attr: The bias attribute. If the parameter is set to False or an object :param bias_attr: The parameter attribute for bias. If this parameter is set to
whose type is not ParameterAttribute, no bias is defined. If the False or an object whose type is not ParameterAttribute,
parameter is set to True, the bias is initialized to zero. no bias is defined. If this parameter is set to True,
the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param layer_attr: Extra Layer config. :param layer_attr: Extra Layer config.
:type layer_attr: ExtraLayerAttribute | None :type layer_attr: ExtraLayerAttribute | None
@ -5585,10 +5589,10 @@ def nce_layer(input,
to the num_classes. Each member of the list defines to the num_classes. Each member of the list defines
the probability of a class given input x. the probability of a class given input x.
:type neg_distribution: list | tuple | collections.Sequence | None :type neg_distribution: list | tuple | collections.Sequence | None
:param bias_attr: The attribute for bias. If this parameter is set False or :param bias_attr: The parameter attribute for bias. If this parameter is set to
any object whose type is not ParameterAttribute, no bias False or an object whose type is not ParameterAttribute,
is added. If this parameter is set True, the bias is no bias is defined. If this parameter is set to True,
initialized to zero. the bias is initialized to zero.
:type bias_attr: ParameterAttribute | None | bool | Any :type bias_attr: ParameterAttribute | None | bool | Any
:param layer_attr: Extra Layer Attribute. :param layer_attr: Extra Layer Attribute.
:type layer_attr: ExtraLayerAttribute :type layer_attr: ExtraLayerAttribute
@ -6498,9 +6502,9 @@ def gated_unit_layer(input,
:param gate_param_attr: The parameter attribute of the gate. See ParameterAttribute :param gate_param_attr: The parameter attribute of the gate. See ParameterAttribute
for details. for details.
:type gate_param_attr: ParameterAttribute :type gate_param_attr: ParameterAttribute
:param gate_bias_attr: The bias attribute of the gate. If the parameter is set to False or :param gate_bias_attr: The bias attribute of the gate. If this parameter is set to False or
an object whose type is not ParameterAttribute, no bias is defined. an object whose type is not ParameterAttribute, no bias is defined.
If the parameter is set to True, the bias is initialized to zero. If this parameter is set to True, the bias is initialized to zero.
:type gate_bias_attr: ParameterAttribute | bool | None | Any :type gate_bias_attr: ParameterAttribute | bool | None | Any
:param inproj_attr: Extra layer attributes of the projection. See ExtraLayerAttribute for :param inproj_attr: Extra layer attributes of the projection. See ExtraLayerAttribute for
details. details.
@ -6508,9 +6512,9 @@ def gated_unit_layer(input,
:param inproj_param_attr: The parameter attribute of the projection. See ParameterAttribute :param inproj_param_attr: The parameter attribute of the projection. See ParameterAttribute
for details. for details.
:type inproj_param_attr: ParameterAttribute :type inproj_param_attr: ParameterAttribute
:param inproj_bias_attr: The bias attribute of the projection. If the parameter is set to False :param inproj_bias_attr: The bias attribute of the projection. If this parameter is set to False
or an object whose type is not ParameterAttribute, no bias is defined. or an object whose type is not ParameterAttribute, no bias is defined.
If the parameter is set to True, the bias is initialized to zero. If this parameter is set to True, the bias is initialized to zero.
:type inproj_bias_attr: ParameterAttribute | bool | None | Any :type inproj_bias_attr: ParameterAttribute | bool | None | Any
:param layer_attr: Extra layer attribute of the product. See ExtraLayerAttribute for :param layer_attr: Extra layer attribute of the product. See ExtraLayerAttribute for
details. details.

@ -681,34 +681,42 @@ def lstmemory_unit(input,
state_act=TanhActivation()) state_act=TanhActivation())
:param input: input layer. :param input: Input layer.
:type input: LayerOutput :type input: LayerOutput
:param out_memory: output of previous time step :param out_memory: The output of previous time step.
:type out_memory: LayerOutput | None :type out_memory: LayerOutput | None
:param name: lstmemory unit name. :param name: The lstmemory unit name.
:type name: basestring :type name: basestring
:param size: lstmemory unit size. :param size: The lstmemory unit size.
:type size: int :type size: int
:param param_attr: parameter attribute, None means default attribute. :param param_attr: The parameter attribute for the weights in
input to hidden projection.
None means default attribute.
:type param_attr: ParameterAttribute :type param_attr: ParameterAttribute
:param act: last activiation type of lstm. :param act: The last activiation type of lstm.
:type act: BaseActivation :type act: BaseActivation
:param gate_act: gate activiation type of lstm. :param gate_act: The gate activiation type of lstm.
:type gate_act: BaseActivation :type gate_act: BaseActivation
:param state_act: state activiation type of lstm. :param state_act: The state activiation type of lstm.
:type state_act: BaseActivation :type state_act: BaseActivation
:param input_proj_bias_attr: bias attribute for input to hidden projection. :param input_proj_bias_attr: The parameter attribute for the bias in
False means no bias, None means default bias. input to hidden projection.
:type input_proj_bias_attr: ParameterAttribute|False|None False or None means no bias.
:param input_proj_layer_attr: extra layer attribute for input to hidden If this parameter is set to True,
projection of the LSTM unit, such as dropout, error clipping. the bias is initialized to zero.
:type input_proj_bias_attr: ParameterAttribute|bool|None
:param input_proj_layer_attr: The extra layer attribute for
input to hidden projection of the LSTM unit,
such as dropout, error clipping.
:type input_proj_layer_attr: ExtraLayerAttribute :type input_proj_layer_attr: ExtraLayerAttribute
:param lstm_bias_attr: bias parameter attribute of lstm layer. :param lstm_bias_attr: The parameter attribute for the bias in lstm layer.
False means no bias, None means default bias. False or None means no bias.
:type lstm_bias_attr: ParameterAttribute|False|None If this parameter is set to True,
:param lstm_layer_attr: extra attribute of lstm layer. the bias is initialized to zero.
:type lstm_bias_attr: ParameterAttribute|True|None
:param lstm_layer_attr: The extra attribute of lstm layer.
:type lstm_layer_attr: ExtraLayerAttribute :type lstm_layer_attr: ExtraLayerAttribute
:return: lstmemory unit name. :return: The lstmemory unit name.
:rtype: LayerOutput :rtype: LayerOutput
""" """
if size is None: if size is None:
@ -786,34 +794,42 @@ def lstmemory_group(input,
gate_act=SigmoidActivation(), gate_act=SigmoidActivation(),
state_act=TanhActivation()) state_act=TanhActivation())
:param input: input layer. :param input: Input layer.
:type input: LayerOutput :type input: LayerOutput
:param size: lstmemory group size. :param size: The lstmemory group size.
:type size: int :type size: int
:param name: name of lstmemory group. :param name: The name of lstmemory group.
:type name: basestring :type name: basestring
:param out_memory: output of previous time step. :param out_memory: The output of previous time step.
:type out_memory: LayerOutput | None :type out_memory: LayerOutput | None
:param reverse: process the input in a reverse order or not. :param reverse: Process the input in a reverse order or not.
:type reverse: bool :type reverse: bool
:param param_attr: parameter attribute, None means default attribute. :param param_attr: The parameter attribute for the weights in
input to hidden projection.
None means default attribute.
:type param_attr: ParameterAttribute :type param_attr: ParameterAttribute
:param act: last activiation type of lstm. :param act: The last activiation type of lstm.
:type act: BaseActivation :type act: BaseActivation
:param gate_act: gate activiation type of lstm. :param gate_act: The gate activiation type of lstm.
:type gate_act: BaseActivation :type gate_act: BaseActivation
:param state_act: state activiation type of lstm. :param state_act: The state activiation type of lstm.
:type state_act: BaseActivation :type state_act: BaseActivation
:param lstm_bias_attr: bias parameter attribute of lstm layer. :param input_proj_bias_attr: The parameter attribute for the bias in
False means no bias, None means default bias. input to hidden projection.
:type lstm_bias_attr: ParameterAttribute|False|None False or None means no bias.
:param input_proj_bias_attr: bias attribute for input to hidden projection. If this parameter is set to True,
False means no bias, None means default bias. the bias is initialized to zero.
:type input_proj_bias_attr: ParameterAttribute|False|None :type input_proj_bias_attr: ParameterAttribute|bool|None
:param input_proj_layer_attr: extra layer attribute for input to hidden :param input_proj_layer_attr: The extra layer attribute for
projection of the LSTM unit, such as dropout, error clipping. input to hidden projection of the LSTM unit,
such as dropout, error clipping.
:type input_proj_layer_attr: ExtraLayerAttribute :type input_proj_layer_attr: ExtraLayerAttribute
:param lstm_layer_attr: lstm layer's extra attribute. :param lstm_bias_attr: The parameter attribute for the bias in lstm layer.
False or None means no bias.
If this parameter is set to True,
the bias is initialized to zero.
:type lstm_bias_attr: ParameterAttribute|True|None
:param lstm_layer_attr: The extra attribute of lstm layer.
:type lstm_layer_attr: ExtraLayerAttribute :type lstm_layer_attr: ExtraLayerAttribute
:return: the lstmemory group. :return: the lstmemory group.
:rtype: LayerOutput :rtype: LayerOutput

@ -1,4 +1,4 @@
from paddle.v2.framework import framework as framework from paddle.v2.fluid import framework as framework
__all__ = ['append_backward_ops'] __all__ = ['append_backward_ops']

@ -13,7 +13,7 @@ A `scoped_function` will take a `function` as input. That function will be
invoked in a new local scope. invoked in a new local scope.
""" """
import paddle.v2.framework.core import paddle.v2.fluid.core
import threading import threading
__tl_scope__ = threading.local() __tl_scope__ = threading.local()
@ -27,13 +27,13 @@ __all__ = [
def get_cur_scope(): def get_cur_scope():
""" """
Get current scope. Get current scope.
:rtype: paddle.v2.framework.core.Scope :rtype: paddle.v2.fluid.core.Scope
""" """
cur_scope_stack = getattr(__tl_scope__, 'cur_scope', None) cur_scope_stack = getattr(__tl_scope__, 'cur_scope', None)
if cur_scope_stack is None: if cur_scope_stack is None:
__tl_scope__.cur_scope = list() __tl_scope__.cur_scope = list()
if len(__tl_scope__.cur_scope) == 0: if len(__tl_scope__.cur_scope) == 0:
__tl_scope__.cur_scope.append(paddle.v2.framework.core.Scope()) __tl_scope__.cur_scope.append(paddle.v2.fluid.core.Scope())
return __tl_scope__.cur_scope[-1] return __tl_scope__.cur_scope[-1]

@ -1,6 +1,6 @@
import paddle.v2.framework.op as op import paddle.v2.fluid.op as op
import numpy as np import numpy as np
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
def avg_accumulate(accumulated_var, per_eval, num_batches, place): def avg_accumulate(accumulated_var, per_eval, num_batches, place):
@ -22,7 +22,7 @@ class Evaluator(object):
NOTE: default run on CPUPlace(), running on GPUPlace doesn't improve performance much. NOTE: default run on CPUPlace(), running on GPUPlace doesn't improve performance much.
:param scope: the scope instance contains the input. :param scope: the scope instance contains the input.
:type scope: paddle.v2.framework.core.scope :type scope: paddle.v2.fluid.core.scope
:param operator: operator name for caculating the evaluation for each mini-batch. :param operator: operator name for caculating the evaluation for each mini-batch.
:type operator: string :type operator: string
:param input: output variable name of forward network. :param input: output variable name of forward network.

@ -1,5 +1,5 @@
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
from paddle.v2.framework.framework import Block, Program, g_main_program from paddle.v2.fluid.framework import Block, Program, g_main_program
g_scope = core.Scope() g_scope = core.Scope()

@ -1,5 +1,5 @@
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
import paddle.v2.framework.proto.framework_pb2 as framework_pb2 import paddle.v2.fluid.proto.framework_pb2 as framework_pb2
import collections import collections
import numpy as np import numpy as np
import copy import copy

@ -1,4 +1,4 @@
import paddle.v2.framework.framework as framework import paddle.v2.fluid.framework as framework
import numpy as np import numpy as np
__all__ = [ __all__ = [

@ -1,7 +1,7 @@
import os import os
import cPickle as pickle import cPickle as pickle
from paddle.v2.framework.framework import Program, Parameter, g_main_program, \ from paddle.v2.fluid.framework import Program, Parameter, g_main_program, \
Variable Variable
__all__ = [ __all__ = [

@ -1,9 +1,9 @@
import copy import copy
import itertools import itertools
from paddle.v2.framework.framework import Variable, g_main_program, \ from paddle.v2.fluid.framework import Variable, g_main_program, \
g_startup_program, unique_name, Program g_startup_program, unique_name, Program
from paddle.v2.framework.initializer import ConstantInitializer, \ from paddle.v2.fluid.initializer import ConstantInitializer, \
UniformInitializer, XavierInitializer UniformInitializer, XavierInitializer

@ -1,10 +1,10 @@
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
import paddle.v2.framework.proto.framework_pb2 as framework_pb2 import paddle.v2.fluid.proto.framework_pb2 as framework_pb2
from paddle.v2.framework.framework import OpProtoHolder, Variable, Program, \ from paddle.v2.fluid.framework import OpProtoHolder, Variable, Program, \
Operator Operator
from paddle.v2.framework.initializer import ConstantInitializer, \ from paddle.v2.fluid.initializer import ConstantInitializer, \
NormalInitializer NormalInitializer
from paddle.v2.framework.layer_helper import LayerHelper, unique_name from paddle.v2.fluid.layer_helper import LayerHelper, unique_name
import re import re
import cStringIO import cStringIO
@ -839,6 +839,23 @@ def batch_norm(input,
return helper.append_activation(batch_norm_out) return helper.append_activation(batch_norm_out)
def beam_search_decode(ids, scores, main_program=None, startup_program=None):
helper = LayerHelper('beam_search_decode', **locals())
sentence_ids = helper.create_tmp_variable(dtype=ids.data_type)
sentence_scores = helper.create_tmp_variable(dtype=ids.data_type)
helper.append_op(
type="beam_search_decode",
inputs={"Ids": ids,
"Scores": scores},
outputs={
"SentenceIds": sentence_ids,
"SentenceScores": sentence_scores
})
return sentence_ids, sentence_scores
class BlockGuard(object): class BlockGuard(object):
""" """
BlockGuard class. BlockGuard class.

@ -3,8 +3,8 @@ import json
import logging import logging
from collections import defaultdict from collections import defaultdict
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
import paddle.v2.framework.proto.framework_pb2 as framework_pb2 import paddle.v2.fluid.proto.framework_pb2 as framework_pb2
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.setLevel(logging.INFO) logger.setLevel(logging.INFO)

@ -1,4 +1,4 @@
import paddle.v2.framework.layers as layers import paddle.v2.fluid.layers as layers
__all__ = ["simple_img_conv_pool", "sequence_conv_pool"] __all__ = ["simple_img_conv_pool", "sequence_conv_pool"]

@ -1,5 +1,5 @@
import paddle.v2.framework.core as core import paddle.v2.fluid.core as core
import paddle.v2.framework.proto.framework_pb2 as framework_pb2 import paddle.v2.fluid.proto.framework_pb2 as framework_pb2
def get_all_op_protos(): def get_all_op_protos():

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save