Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
f319fb1c
P
Paddle
项目概览
PaddlePaddle
/
Paddle
1 年多 前同步成功
通知
2302
Star
20931
Fork
5422
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1423
列表
看板
标记
里程碑
合并请求
543
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1,423
Issue
1,423
列表
看板
标记
里程碑
合并请求
543
合并请求
543
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f319fb1c
编写于
11月 14, 2017
作者:
W
wanghaox
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/Paddle
into my_maxout_op
上级
f57cd1e0
f06d8f0d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
178 addition
and
65 deletion
+178
-65
paddle/operators/beam_search_decode_op.cc
paddle/operators/beam_search_decode_op.cc
+1
-0
paddle/operators/l1_norm_op.h
paddle/operators/l1_norm_op.h
+1
-1
paddle/operators/squared_l2_norm_op.h
paddle/operators/squared_l2_norm_op.h
+1
-1
python/paddle/trainer_config_helpers/layers.py
python/paddle/trainer_config_helpers/layers.py
+31
-27
python/paddle/trainer_config_helpers/networks.py
python/paddle/trainer_config_helpers/networks.py
+52
-36
python/paddle/v2/framework/layers.py
python/paddle/v2/framework/layers.py
+17
-0
python/paddle/v2/framework/tests/test_beam_search_decode_op.py
...n/paddle/v2/framework/tests/test_beam_search_decode_op.py
+75
-0
未找到文件。
paddle/operators/beam_search_decode_op.cc
浏览文件 @
f319fb1c
...
@@ -27,6 +27,7 @@ class BeamSearchDecodeOp : public framework::OperatorBase {
...
@@ -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
();
...
...
paddle/operators/l1_norm_op.h
浏览文件 @
f319fb1c
...
@@ -29,7 +29,7 @@ class L1NormKernel : public framework::OpKernel<T> {
...
@@ -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
::
Eigen
Vector
<
T
>::
Flatten
(
*
Out
);
auto
out
=
framework
::
Eigen
Scalar
<
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
();
...
...
paddle/operators/squared_l2_norm_op.h
浏览文件 @
f319fb1c
...
@@ -29,7 +29,7 @@ class SquaredL2NormKernel : public framework::OpKernel<T> {
...
@@ -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
::
Eigen
Vector
<
T
>::
Flatten
(
*
Out
);
auto
out
=
framework
::
Eigen
Scalar
<
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
();
...
...
python/paddle/trainer_config_helpers/layers.py
浏览文件 @
f319fb1c
...
@@ -3592,10 +3592,9 @@ def lstm_step_layer(input,
...
@@ -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,
...
@@ -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,
...
@@ -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,
...
@@ -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,
...
@@ -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,
...
@@ -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,
...
@@ -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,
...
@@ -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 th
e
parameter is set to False or
:param gate_bias_attr: The bias attribute of the gate. If th
is
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 th
e
parameter is set to True, the bias is initialized to zero.
If th
is
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,
...
@@ -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 th
e
parameter is set to False
:param inproj_bias_attr: The bias attribute of the projection. If th
is
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 th
e
parameter is set to True, the bias is initialized to zero.
If th
is
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.
...
...
python/paddle/trainer_config_helpers/networks.py
浏览文件 @
f319fb1c
...
@@ -681,34 +681,42 @@ def lstmemory_unit(input,
...
@@ -681,34 +681,42 @@ def lstmemory_unit(input,
state_act=TanhActivation())
state_act=TanhActivation())
:param input:
i
nput layer.
:param input:
I
nput 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,
...
@@ -786,34 +794,42 @@ def lstmemory_group(input,
gate_act=SigmoidActivation(),
gate_act=SigmoidActivation(),
state_act=TanhActivation())
state_act=TanhActivation())
:param input:
i
nput layer.
:param input:
I
nput 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:
p
rocess the input in a reverse order or not.
:param reverse:
P
rocess 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
...
...
python/paddle/v2/framework/layers.py
浏览文件 @
f319fb1c
...
@@ -839,6 +839,23 @@ def batch_norm(input,
...
@@ -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.
...
...
python/paddle/v2/framework/tests/test_beam_search_decode_op.py
0 → 100644
浏览文件 @
f319fb1c
import
unittest
import
numpy
as
np
import
paddle.v2.framework.core
as
core
from
paddle.v2.framework.op
import
Operator
class
TestBeamSearchDecodeOp
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
scope
=
core
.
Scope
()
self
.
cpu_place
=
core
.
CPUPlace
()
def
append_lod_tensor
(
self
,
tensor_array
,
lod
,
data
):
lod_tensor
=
core
.
LoDTensor
()
lod_tensor
.
set_lod
(
lod
)
lod_tensor
.
set
(
data
,
self
.
cpu_place
)
tensor_array
.
append
(
lod_tensor
)
def
test_get_set
(
self
):
ids
=
self
.
scope
.
var
(
"ids"
).
get_lod_tensor_array
()
self
.
append_lod_tensor
(
ids
,
[[
0
,
3
,
6
],
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]],
np
.
array
(
[
1
,
2
,
3
,
4
,
5
,
6
],
dtype
=
"int64"
))
self
.
append_lod_tensor
(
ids
,
[[
0
,
3
,
6
],
[
0
,
1
,
1
,
3
,
5
,
5
,
6
]],
np
.
array
(
[
0
,
1
,
2
,
3
,
4
,
5
],
dtype
=
"int64"
))
self
.
append_lod_tensor
(
ids
,
[[
0
,
3
,
6
],
[
0
,
0
,
1
,
2
,
3
,
4
,
5
]],
np
.
array
(
[
0
,
1
,
2
,
3
,
4
],
dtype
=
"int64"
))
scores
=
self
.
scope
.
var
(
"scores"
).
get_lod_tensor_array
()
self
.
append_lod_tensor
(
scores
,
[[
0
,
3
,
6
],
[
0
,
1
,
2
,
3
,
4
,
5
,
6
]],
np
.
array
(
[
1
,
2
,
3
,
4
,
5
,
6
],
dtype
=
"float32"
))
self
.
append_lod_tensor
(
scores
,
[[
0
,
3
,
6
],
[
0
,
1
,
1
,
3
,
5
,
5
,
6
]],
np
.
array
(
[
0
,
1
,
2
,
3
,
4
,
5
],
dtype
=
"float32"
))
self
.
append_lod_tensor
(
scores
,
[[
0
,
3
,
6
],
[
0
,
0
,
1
,
2
,
3
,
4
,
5
]],
np
.
array
(
[
0
,
1
,
2
,
3
,
4
],
dtype
=
"float32"
))
sentence_ids
=
self
.
scope
.
var
(
"sentence_ids"
).
get_tensor
()
sentence_scores
=
self
.
scope
.
var
(
"sentence_scores"
).
get_tensor
()
beam_search_decode_op
=
Operator
(
"beam_search_decode"
,
# inputs
Ids
=
"ids"
,
Scores
=
"scores"
,
# outputs
SentenceIds
=
"sentence_ids"
,
SentenceScores
=
"sentence_scores"
)
ctx
=
core
.
DeviceContext
.
create
(
self
.
cpu_place
)
beam_search_decode_op
.
run
(
self
.
scope
,
ctx
)
expected_lod
=
[[
0
,
4
,
8
],
[
0
,
1
,
3
,
6
,
9
,
10
,
13
,
16
,
19
]]
self
.
assertEqual
(
sentence_ids
.
lod
(),
expected_lod
)
self
.
assertEqual
(
sentence_scores
.
lod
(),
expected_lod
)
expected_data
=
np
.
array
(
[
2
,
1
,
0
,
3
,
1
,
0
,
3
,
2
,
1
,
5
,
4
,
3
,
2
,
4
,
4
,
3
,
6
,
5
,
4
],
"int64"
)
self
.
assertTrue
(
np
.
array_equal
(
np
.
array
(
sentence_ids
),
expected_data
))
self
.
assertTrue
(
np
.
array_equal
(
np
.
array
(
sentence_scores
),
expected_data
))
if
__name__
==
'__main__'
:
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录