Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
2c1adb06
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看板
提交
2c1adb06
编写于
12月 29, 2017
作者:
Y
Yibing Liu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Rename ctc_edit_distance_op to edit_distance_op
上级
36ec3e90
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
19 addition
and
21 deletion
+19
-21
paddle/operators/edit_distance_op.cc
paddle/operators/edit_distance_op.cc
+11
-13
paddle/operators/edit_distance_op.cu
paddle/operators/edit_distance_op.cu
+6
-6
paddle/operators/edit_distance_op.h
paddle/operators/edit_distance_op.h
+1
-1
python/paddle/v2/fluid/tests/test_edit_distance_op.py
python/paddle/v2/fluid/tests/test_edit_distance_op.py
+1
-1
未找到文件。
paddle/operators/
ctc_
edit_distance_op.cc
→
paddle/operators/edit_distance_op.cc
浏览文件 @
2c1adb06
...
@@ -12,12 +12,12 @@
...
@@ -12,12 +12,12 @@
See the License for the specific language governing permissions and
See the License for the specific language governing permissions and
limitations under the License. */
limitations under the License. */
#include "paddle/operators/
ctc_
edit_distance_op.h"
#include "paddle/operators/edit_distance_op.h"
namespace
paddle
{
namespace
paddle
{
namespace
operators
{
namespace
operators
{
class
CTC
EditDistanceOp
:
public
framework
::
OperatorWithKernel
{
class
EditDistanceOp
:
public
framework
::
OperatorWithKernel
{
public:
public:
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
using
framework
::
OperatorWithKernel
::
OperatorWithKernel
;
...
@@ -29,17 +29,16 @@ class CTCEditDistanceOp : public framework::OperatorWithKernel {
...
@@ -29,17 +29,16 @@ class CTCEditDistanceOp : public framework::OperatorWithKernel {
}
}
protected:
protected:
framework
::
OpKernelType
GetKernelType
(
framework
::
OpKernelType
Get
Actual
KernelType
(
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
const
framework
::
ExecutionContext
&
ctx
)
const
override
{
return
framework
::
OpKernelType
(
framework
::
DataType
::
FP32
,
return
framework
::
OpKernelType
(
framework
::
proto
::
DataType
::
FP32
,
ctx
.
device_context
());
ctx
.
device_context
());
}
}
};
};
class
CTC
EditDistanceOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
class
EditDistanceOpMaker
:
public
framework
::
OpProtoAndCheckerMaker
{
public:
public:
CTCEditDistanceOpMaker
(
framework
::
OpProto
*
proto
,
EditDistanceOpMaker
(
OpProto
*
proto
,
OpAttrChecker
*
op_checker
)
framework
::
OpAttrChecker
*
op_checker
)
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
:
OpProtoAndCheckerMaker
(
proto
,
op_checker
)
{
AddInput
(
"X1"
,
AddInput
(
"X1"
,
"(2-D tensor with shape [M x 1]) The indices for "
"(2-D tensor with shape [M x 1]) The indices for "
...
@@ -54,10 +53,10 @@ class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
...
@@ -54,10 +53,10 @@ class CTCEditDistanceOpMaker : public framework::OpProtoAndCheckerMaker {
.
SetDefault
(
false
);
.
SetDefault
(
false
);
AddOutput
(
"Out"
,
AddOutput
(
"Out"
,
"(2-D tensor with shape [1 x 1]) "
"(2-D tensor with shape [1 x 1]) "
"The output distance of
CTC
EditDistance operator."
);
"The output distance of EditDistance operator."
);
AddComment
(
R"DOC(
AddComment
(
R"DOC(
CTC
EditDistance operator computes the edit distance of two sequences, one named
EditDistance operator computes the edit distance of two sequences, one named
hypothesis with length M and another named reference with length N.
hypothesis with length M and another named reference with length N.
Edit distance, also called Levenshtein distance, measures how dissimilar two strings
Edit distance, also called Levenshtein distance, measures how dissimilar two strings
...
@@ -80,8 +79,7 @@ reference string N.
...
@@ -80,8 +79,7 @@ reference string N.
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP
_WITHOUT_GRADIENT
(
ctc_edit_distance
,
ops
::
CTCEditDistanceOp
,
REGISTER_OP
ERATOR
(
edit_distance
,
ops
::
EditDistanceOp
,
ops
::
EditDistanceOpMaker
,
ops
::
CTCEditDistance
OpMaker
);
paddle
::
framework
::
EmptyGrad
OpMaker
);
REGISTER_OP_CPU_KERNEL
(
REGISTER_OP_CPU_KERNEL
(
ctc_edit_distance
,
edit_distance
,
ops
::
EditDistanceKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
ops
::
CTCEditDistanceKernel
<
paddle
::
platform
::
CPUPlace
,
float
>
);
paddle/operators/
ctc_
edit_distance_op.cu
→
paddle/operators/edit_distance_op.cu
浏览文件 @
2c1adb06
...
@@ -65,7 +65,7 @@ __global__ void SetOutput(T* out, const T* dist, const int M, const int N,
...
@@ -65,7 +65,7 @@ __global__ void SetOutput(T* out, const T* dist, const int M, const int N,
}
}
template
<
typename
Place
,
typename
T
>
template
<
typename
Place
,
typename
T
>
class
CTC
EditDistanceGPUKernel
:
public
framework
::
OpKernel
<
T
>
{
class
EditDistanceGPUKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
*
out_t
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
out_t
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
...
@@ -110,8 +110,8 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel<T> {
...
@@ -110,8 +110,8 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel<T> {
int
z_n
=
slice
<
n
+
1
?
0
:
slice
-
n
;
int
z_n
=
slice
<
n
+
1
?
0
:
slice
-
n
;
int
size
=
slice
-
(
z_m
+
z_n
)
+
1
;
// number of elments in the same
int
size
=
slice
-
(
z_m
+
z_n
)
+
1
;
// number of elments in the same
// anti-diagonal line to update
// anti-diagonal line to update
int
start
=
slice
<
n
+
1
?
slice
:
z_n
*
(
n
+
1
)
-
1
;
// start index
// the start index at which computes from
int
start
=
slice
<
n
+
1
?
slice
:
(
z_n
+
1
)
*
(
n
+
1
)
-
1
;
Levenshtein
<
T
><<<
1
+
(
size
-
1
)
/
PADDLE_CUDA_NUM_THREADS
,
Levenshtein
<
T
><<<
1
+
(
size
-
1
)
/
PADDLE_CUDA_NUM_THREADS
,
PADDLE_CUDA_NUM_THREADS
,
0
,
stream
>>>
(
dist
,
x1
,
x2
,
m
,
PADDLE_CUDA_NUM_THREADS
,
0
,
stream
>>>
(
dist
,
x1
,
x2
,
m
,
n
,
start
);
n
,
start
);
...
@@ -126,6 +126,6 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel<T> {
...
@@ -126,6 +126,6 @@ class CTCEditDistanceGPUKernel : public framework::OpKernel<T> {
namespace
ops
=
paddle
::
operators
;
namespace
ops
=
paddle
::
operators
;
REGISTER_OP_
GPU
_KERNEL
(
REGISTER_OP_
CUDA
_KERNEL
(
ctc_
edit_distance
,
edit_distance
,
ops
::
CTCEditDistanceGPUKernel
<
paddle
::
platform
::
GPU
Place
,
float
>
);
ops
::
EditDistanceGPUKernel
<
paddle
::
platform
::
CUDA
Place
,
float
>
);
paddle/operators/
ctc_
edit_distance_op.h
→
paddle/operators/edit_distance_op.h
浏览文件 @
2c1adb06
...
@@ -21,7 +21,7 @@ namespace paddle {
...
@@ -21,7 +21,7 @@ namespace paddle {
namespace
operators
{
namespace
operators
{
template
<
typename
Place
,
typename
T
>
template
<
typename
Place
,
typename
T
>
class
CTC
EditDistanceKernel
:
public
framework
::
OpKernel
<
T
>
{
class
EditDistanceKernel
:
public
framework
::
OpKernel
<
T
>
{
public:
public:
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
void
Compute
(
const
framework
::
ExecutionContext
&
ctx
)
const
{
auto
*
out_t
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
auto
*
out_t
=
ctx
.
Output
<
framework
::
Tensor
>
(
"Out"
);
...
...
python/paddle/v2/fluid/tests/test_
ctc_
edit_distance_op.py
→
python/paddle/v2/fluid/tests/test_edit_distance_op.py
浏览文件 @
2c1adb06
...
@@ -36,7 +36,7 @@ def Levenshtein(hyp, ref):
...
@@ -36,7 +36,7 @@ def Levenshtein(hyp, ref):
class
TestCTCEditDistanceOp
(
OpTest
):
class
TestCTCEditDistanceOp
(
OpTest
):
def
setUp
(
self
):
def
setUp
(
self
):
self
.
op_type
=
"
ctc_
edit_distance"
self
.
op_type
=
"edit_distance"
normalized
=
True
normalized
=
True
x1
=
np
.
array
([
0
,
12
,
3
,
5
]).
astype
(
"int32"
)
x1
=
np
.
array
([
0
,
12
,
3
,
5
]).
astype
(
"int32"
)
x2
=
np
.
array
([
0
,
12
,
4
,
7
,
8
]).
astype
(
"int32"
)
x2
=
np
.
array
([
0
,
12
,
4
,
7
,
8
]).
astype
(
"int32"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录