Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
f3818bd3
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
f3818bd3
编写于
11月 14, 2017
作者:
X
xzl
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of
https://github.com/PaddlePaddle/Paddle
into add_dilation
上级
fbd8a330
7345de3a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
98 addition
and
2 deletion
+98
-2
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
paddle/pybind/pybind.cc
paddle/pybind/pybind.cc
+3
-0
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
浏览文件 @
f3818bd3
...
...
@@ -27,6 +27,7 @@ class BeamSearchDecodeOp : public framework::OperatorBase {
void
Run
(
const
framework
::
Scope
&
scope
,
const
platform
::
DeviceContext
&
dev_ctx
)
const
override
{
framework
::
ExecutionContext
ctx
(
*
this
,
scope
,
dev_ctx
);
const
LoDTensorArray
*
ids
=
ctx
.
Input
<
LoDTensorArray
>
(
"Ids"
);
const
LoDTensorArray
*
scores
=
ctx
.
Input
<
LoDTensorArray
>
(
"Scores"
);
const
size_t
step_num
=
ids
->
size
();
...
...
paddle/operators/l1_norm_op.h
浏览文件 @
f3818bd3
...
...
@@ -29,7 +29,7 @@ class L1NormKernel : public framework::OpKernel<T> {
Out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
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
>
();
out
.
device
(
place
)
=
x
.
abs
().
sum
();
...
...
paddle/operators/squared_l2_norm_op.h
浏览文件 @
f3818bd3
...
...
@@ -29,7 +29,7 @@ class SquaredL2NormKernel : public framework::OpKernel<T> {
Out
->
mutable_data
<
T
>
(
context
.
GetPlace
());
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
>
();
out
.
device
(
place
)
=
x
.
square
().
sum
();
...
...
paddle/pybind/pybind.cc
浏览文件 @
f3818bd3
...
...
@@ -42,6 +42,9 @@ limitations under the License. */
#include "paddle/platform/gpu_info.h"
#endif
// disable auto conversion to list in Python
PYBIND11_MAKE_OPAQUE
(
paddle
::
framework
::
LoDTensorArray
);
namespace
paddle
{
namespace
pybind
{
static
size_t
UniqueIntegerGenerator
(
const
std
::
string
&
prefix
)
{
...
...
python/paddle/v2/framework/layers.py
浏览文件 @
f3818bd3
...
...
@@ -839,6 +839,23 @@ def batch_norm(input,
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
):
"""
BlockGuard class.
...
...
python/paddle/v2/framework/tests/test_beam_search_decode_op.py
0 → 100644
浏览文件 @
f3818bd3
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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录