Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
deb75098
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看板
提交
deb75098
编写于
1月 23, 2018
作者:
Y
Yang Yu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'develop' of github.com:baidu/Paddle into feature/wrap_nce_loss
上级
df4133d0
59bcb589
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
22 deletion
+21
-22
paddle/operators/bipartite_match_op.cc
paddle/operators/bipartite_match_op.cc
+1
-2
python/paddle/v2/dataset/wmt16.py
python/paddle/v2/dataset/wmt16.py
+3
-3
python/paddle/v2/fluid/tests/test_bipartite_match_op.py
python/paddle/v2/fluid/tests/test_bipartite_match_op.py
+17
-17
未找到文件。
paddle/operators/bipartite_match_op.cc
浏览文件 @
deb75098
...
...
@@ -21,8 +21,6 @@ namespace operators {
using
Tensor
=
framework
::
Tensor
;
using
LoDTensor
=
framework
::
LoDTensor
;
constexpr
double
kEPS
=
1e-6
;
class
BipartiteMatchOp
:
public
framework
::
OperatorWithKernel
{
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
...
@@ -46,6 +44,7 @@ class BipartiteMatchKernel : public framework::OpKernel<T> {
// The match_dist must be initialized to 0 at first.
void
BipartiteMatch
(
const
Tensor
&
dist
,
int
*
match_indices
,
T
*
match_dist
)
const
{
constexpr
T
kEPS
=
static_cast
<
T
>
(
1e-6
);
PADDLE_ENFORCE_EQ
(
dist
.
dims
().
size
(),
2
,
"The rank of dist must be 2."
);
int64_t
row
=
dist
.
dims
()[
0
];
int64_t
col
=
dist
.
dims
()[
1
];
...
...
python/paddle/v2/dataset/wmt16.py
浏览文件 @
deb75098
...
...
@@ -305,9 +305,9 @@ def get_dict(lang, dict_size, reverse=False):
dict_path
=
os
.
path
.
join
(
paddle
.
v2
.
dataset
.
common
.
DATA_HOME
,
"wmt16/%s_%d.dict"
%
(
lang
,
dict_size
))
assert
(
os
.
path
.
exists
(
dict_path
),
"Word dictionary does not exist. "
"Please invoke paddle.dataset.wmt16.train/test/validation
"
"first to build the dictionary."
)
assert
os
.
path
.
exists
(
dict_path
),
"Word dictionary does not exist. "
"Please invoke paddle.dataset.wmt16.train/test/validation first
"
"to build the dictionary."
tar_file
=
os
.
path
.
join
(
paddle
.
v2
.
dataset
.
common
.
DATA_HOME
,
"wmt16.tar.gz"
)
return
__load_dict
(
tar_file
,
dict_size
,
lang
,
reverse
)
...
...
python/paddle/v2/fluid/tests/test_bipartite_match_op.py
浏览文件 @
deb75098
...
...
@@ -16,13 +16,13 @@ import numpy as np
from
op_test
import
OpTest
def
bipartite_match
(
distance
,
match_indices
,
match_dis
):
def
bipartite_match
(
distance
,
match_indices
,
match_dis
t
):
"""Bipartite Matching algorithm.
Arg:
distance (numpy.array) : The distance of two entries with shape [M, N].
match_indices (numpy.array): the matched indices from column to row
with shape [1, N], it must be initialized to -1.
match_dis (numpy.array): The matched distance from column to row
match_dis
t
(numpy.array): The matched distance from column to row
with shape [1, N], it must be initialized to 0.
"""
match_pair
=
[]
...
...
@@ -36,13 +36,13 @@ def bipartite_match(distance, match_indices, match_dis):
row_indices
=
-
1
*
np
.
ones
((
row
,
),
dtype
=
np
.
int
)
idx
=
0
for
i
,
j
,
dis
in
match_sorted
:
for
i
,
j
,
dis
t
in
match_sorted
:
if
idx
>=
row
:
break
if
match_indices
[
j
]
==
-
1
and
row_indices
[
i
]
==
-
1
and
dis
>
0
:
if
match_indices
[
j
]
==
-
1
and
row_indices
[
i
]
==
-
1
and
dis
t
>
0
:
match_indices
[
j
]
=
i
row_indices
[
i
]
=
j
match_dis
[
j
]
=
dis
match_dis
t
[
j
]
=
dist
idx
+=
1
...
...
@@ -55,24 +55,24 @@ def batch_bipartite_match(distance, lod):
n
=
len
(
lod
)
-
1
m
=
distance
.
shape
[
1
]
match_indices
=
-
1
*
np
.
ones
((
n
,
m
),
dtype
=
np
.
int
)
match_dis
=
np
.
zeros
((
n
,
m
),
dtype
=
np
.
float32
)
match_dis
t
=
np
.
zeros
((
n
,
m
),
dtype
=
np
.
float32
)
for
i
in
range
(
len
(
lod
)
-
1
):
bipartite_match
(
distance
[
lod
[
i
]:
lod
[
i
+
1
],
:],
match_indices
[
i
,
:],
match_dis
[
i
,
:])
return
match_indices
,
match_dis
match_dis
t
[
i
,
:])
return
match_indices
,
match_dis
t
class
TestBipartiteMatchOpForWithLoD
(
OpTest
):
def
setUp
(
self
):
self
.
op_type
=
'bipartite_match'
lod
=
[[
0
,
5
,
11
,
23
]]
dis
=
np
.
random
.
random
((
23
,
217
)).
astype
(
'float32'
)
match_indices
,
match_dis
=
batch_bipartite_match
(
dis
,
lod
[
0
])
dis
t
=
np
.
random
.
random
((
23
,
217
)).
astype
(
'float32'
)
match_indices
,
match_dis
t
=
batch_bipartite_match
(
dist
,
lod
[
0
])
self
.
inputs
=
{
'DistMat'
:
(
dis
,
lod
)}
self
.
inputs
=
{
'DistMat'
:
(
dis
t
,
lod
)}
self
.
outputs
=
{
'ColToRowMatchIndices'
:
(
match_indices
),
'ColToRowMatchDis'
:
(
match_dis
),
'ColToRowMatchDis'
:
(
match_dis
t
),
}
def
test_check_output
(
self
):
...
...
@@ -83,13 +83,13 @@ class TestBipartiteMatchOpWithoutLoD(OpTest):
def
setUp
(
self
):
self
.
op_type
=
'bipartite_match'
lod
=
[[
0
,
8
]]
dis
=
np
.
random
.
random
((
8
,
17
)).
astype
(
'float32'
)
match_indices
,
match_dis
=
batch_bipartite_match
(
dis
,
lod
[
0
])
dis
t
=
np
.
random
.
random
((
8
,
17
)).
astype
(
'float32'
)
match_indices
,
match_dis
t
=
batch_bipartite_match
(
dist
,
lod
[
0
])
self
.
inputs
=
{
'DistMat'
:
dis
}
self
.
inputs
=
{
'DistMat'
:
dis
t
}
self
.
outputs
=
{
'ColToRowMatchIndices'
:
(
match_indices
)
,
'ColToRowMatchDis'
:
(
match_dis
)
,
'ColToRowMatchIndices'
:
match_indices
,
'ColToRowMatchDis'
:
match_dist
,
}
def
test_check_output
(
self
):
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录