Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
Paddle
提交
b7a4e3d7
P
Paddle
项目概览
PaddlePaddle
/
Paddle
大约 1 年 前同步成功
通知
2299
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看板
提交
b7a4e3d7
编写于
11月 02, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rename some variables in ctc_edit_distance_op
上级
db694172
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
14 addition
and
19 deletion
+14
-19
paddle/operators/ctc_edit_distance_op.cc
paddle/operators/ctc_edit_distance_op.cc
+2
-2
paddle/operators/ctc_edit_distance_op.h
paddle/operators/ctc_edit_distance_op.h
+10
-11
python/paddle/v2/framework/tests/test_ctc_edit_distance.py
python/paddle/v2/framework/tests/test_ctc_edit_distance.py
+2
-6
未找到文件。
paddle/operators/ctc_edit_distance_op.cc
浏览文件 @
b7a4e3d7
...
@@ -38,11 +38,11 @@ class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -38,11 +38,11 @@ class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
"(2-D tensor with shape [M x 1]) The indices for "
"(2-D tensor with shape [M x 1]) The indices for "
"hypothesis string"
);
"hypothesis string"
);
AddInput
(
"X2"
,
AddInput
(
"X2"
,
"(2-D tensor with shape [
batch_size
x 1]) The indices "
"(2-D tensor with shape [
N
x 1]) The indices "
"for reference string."
);
"for reference string."
);
AddAttr
<
bool
>
(
"normalized"
,
AddAttr
<
bool
>
(
"normalized"
,
"(bool, default false) Indicated whether "
"(bool, default false) Indicated whether "
"normalize
.
the Output(Out) by the length of reference "
"normalize the Output(Out) by the length of reference "
"string (X2)."
)
"string (X2)."
)
.
SetDefault
(
false
);
.
SetDefault
(
false
);
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
...
...
paddle/operators/ctc_edit_distance_op.h
浏览文件 @
b7a4e3d7
...
@@ -47,20 +47,19 @@ class CTCEditDistanceKernel : public framework::OpKernel<T> {
...
@@ -47,20 +47,19 @@ class CTCEditDistanceKernel : public framework::OpKernel<T> {
auto
dist
=
dist_t
.
data
<
T
>
();
auto
dist
=
dist_t
.
data
<
T
>
();
auto
x1
=
x1_t
->
data
<
T
>
();
auto
x1
=
x1_t
->
data
<
T
>
();
auto
x2
=
x2_t
->
data
<
T
>
();
auto
x2
=
x2_t
->
data
<
T
>
();
for
(
in
t
i
=
0
;
i
<
m
+
1
;
++
i
)
{
for
(
size_
t
i
=
0
;
i
<
m
+
1
;
++
i
)
{
dist
[
i
*
(
n
+
1
)]
=
i
;
// dist[i][0] = i;
dist
[
i
*
(
n
+
1
)]
=
i
;
}
}
for
(
in
t
j
=
0
;
j
<
n
+
1
;
++
j
)
{
for
(
size_
t
j
=
0
;
j
<
n
+
1
;
++
j
)
{
dist
[
j
]
=
j
;
// dist[0][j] = j;
dist
[
j
]
=
j
;
}
}
for
(
in
t
i
=
1
;
i
<
m
+
1
;
++
i
)
{
for
(
size_
t
i
=
1
;
i
<
m
+
1
;
++
i
)
{
for
(
in
t
j
=
1
;
j
<
n
+
1
;
++
j
)
{
for
(
size_
t
j
=
1
;
j
<
n
+
1
;
++
j
)
{
int
cost
=
x1
[
i
-
1
]
==
x2
[
j
-
1
]
?
0
:
1
;
int
cost
=
x1
[
i
-
1
]
==
x2
[
j
-
1
]
?
0
:
1
;
int
deletions
=
dist
[(
i
-
1
)
*
(
n
+
1
)
+
j
]
+
1
;
int
dels
=
dist
[(
i
-
1
)
*
(
n
+
1
)
+
j
]
+
1
;
int
insertions
=
dist
[
i
*
(
n
+
1
)
+
(
j
-
1
)]
+
1
;
int
ins
=
dist
[
i
*
(
n
+
1
)
+
(
j
-
1
)]
+
1
;
int
substitutions
=
dist
[(
i
-
1
)
*
(
n
+
1
)
+
(
j
-
1
)]
+
cost
;
int
subs
=
dist
[(
i
-
1
)
*
(
n
+
1
)
+
(
j
-
1
)]
+
cost
;
dist
[
i
*
(
n
+
1
)
+
j
]
=
dist
[
i
*
(
n
+
1
)
+
j
]
=
std
::
min
(
dels
,
std
::
min
(
ins
,
subs
));
std
::
min
(
deletions
,
std
::
min
(
insertions
,
substitutions
));
}
}
}
}
distance
=
dist
[
m
*
(
n
+
1
)
+
n
];
distance
=
dist
[
m
*
(
n
+
1
)
+
n
];
...
...
python/paddle/v2/framework/tests/test_ctc_edit_distance.py
浏览文件 @
b7a4e3d7
...
@@ -6,9 +6,9 @@ from op_test import OpTest
...
@@ -6,9 +6,9 @@ from op_test import OpTest
def
Levenshtein
(
hyp
,
ref
):
def
Levenshtein
(
hyp
,
ref
):
""" Compute the Levenshtein distance between two strings.
""" Compute the Levenshtein distance between two strings.
:param hyp:
:param hyp:
hypothesis string in index
:type hyp: list
:type hyp: list
:param ref:
:param ref:
reference string in index
:type ref: list
:type ref: list
"""
"""
m
=
len
(
hyp
)
m
=
len
(
hyp
)
...
@@ -44,7 +44,6 @@ class TestCTCEditDistanceOp(OpTest):
...
@@ -44,7 +44,6 @@ class TestCTCEditDistanceOp(OpTest):
distance
=
Levenshtein
(
hyp
=
x1
,
ref
=
x2
)
distance
=
Levenshtein
(
hyp
=
x1
,
ref
=
x2
)
if
normalized
is
True
:
if
normalized
is
True
:
distance
=
distance
/
len
(
x2
)
distance
=
distance
/
len
(
x2
)
print
"distance = "
,
distance
self
.
attrs
=
{
'normalized'
:
normalized
}
self
.
attrs
=
{
'normalized'
:
normalized
}
self
.
inputs
=
{
'X1'
:
x1
,
'X2'
:
x2
}
self
.
inputs
=
{
'X1'
:
x1
,
'X2'
:
x2
}
self
.
outputs
=
{
'Out'
:
distance
}
self
.
outputs
=
{
'Out'
:
distance
}
...
@@ -54,7 +53,4 @@ class TestCTCEditDistanceOp(OpTest):
...
@@ -54,7 +53,4 @@ class TestCTCEditDistanceOp(OpTest):
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
#x1 = ['c', 'a', 'f', 'e']
#x2 = ['c', 'o', 'f', 'f', 'e', 'e']
#print Levenshtein(x1, x2)
unittest
.
main
()
unittest
.
main
()
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录