Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
1fbae957
M
models
项目概览
PaddlePaddle
/
models
大约 1 年 前同步成功
通知
222
Star
6828
Fork
2962
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
602
列表
看板
标记
里程碑
合并请求
255
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
models
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
602
Issue
602
列表
看板
标记
里程碑
合并请求
255
合并请求
255
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
1fbae957
编写于
8月 21, 2018
作者:
B
bingyanghuang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix chinese_ner inference appearing linear_chain_crf_grad op
上级
beb4dfbe
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
25 addition
and
5 deletion
+25
-5
fluid/chinese_ner/infer.py
fluid/chinese_ner/infer.py
+20
-1
fluid/chinese_ner/train.py
fluid/chinese_ner/train.py
+5
-4
未找到文件。
fluid/chinese_ner/infer.py
浏览文件 @
1fbae957
...
@@ -61,6 +61,21 @@ def load_reverse_dict(dict_path):
...
@@ -61,6 +61,21 @@ def load_reverse_dict(dict_path):
return
dict
((
idx
,
line
.
strip
().
split
(
"
\t
"
)[
0
])
return
dict
((
idx
,
line
.
strip
().
split
(
"
\t
"
)[
0
])
for
idx
,
line
in
enumerate
(
open
(
dict_path
,
"r"
).
readlines
()))
for
idx
,
line
in
enumerate
(
open
(
dict_path
,
"r"
).
readlines
()))
def
to_lodtensor
(
data
,
place
):
seq_lens
=
[
len
(
seq
)
for
seq
in
data
]
cur_len
=
0
lod
=
[
cur_len
]
for
l
in
seq_lens
:
cur_len
+=
l
lod
.
append
(
cur_len
)
flattened_data
=
np
.
concatenate
(
data
,
axis
=
0
).
astype
(
"int64"
)
flattened_data
=
flattened_data
.
reshape
([
len
(
flattened_data
),
1
])
res
=
fluid
.
LoDTensor
()
res
.
set
(
flattened_data
,
place
)
res
.
set_lod
([
lod
])
return
res
def
infer
(
args
):
def
infer
(
args
):
word
=
fluid
.
layers
.
data
(
name
=
'word'
,
shape
=
[
1
],
dtype
=
'int64'
,
lod_level
=
1
)
word
=
fluid
.
layers
.
data
(
name
=
'word'
,
shape
=
[
1
],
dtype
=
'int64'
,
lod_level
=
1
)
...
@@ -93,9 +108,13 @@ def infer(args):
...
@@ -93,9 +108,13 @@ def infer(args):
profiler
.
reset_profiler
()
profiler
.
reset_profiler
()
iters
=
0
iters
=
0
for
data
in
test_data
():
for
data
in
test_data
():
word
=
to_lodtensor
(
map
(
lambda
x
:
x
[
0
],
data
),
place
)
mention
=
to_lodtensor
(
map
(
lambda
x
:
x
[
1
],
data
),
place
)
start
=
time
.
time
()
start
=
time
.
time
()
crf_decode
=
exe
.
run
(
inference_program
,
crf_decode
=
exe
.
run
(
inference_program
,
feed
=
feeder
.
feed
(
data
),
feed
=
{
"word"
:
word
,
"mention"
:
mention
},
fetch_list
=
fetch_targets
,
fetch_list
=
fetch_targets
,
return_numpy
=
False
)
return_numpy
=
False
)
batch_time
=
time
.
time
()
-
start
batch_time
=
time
.
time
()
-
start
...
...
fluid/chinese_ner/train.py
浏览文件 @
1fbae957
...
@@ -266,12 +266,13 @@ def main(args):
...
@@ -266,12 +266,13 @@ def main(args):
with
fluid
.
program_guard
(
main
,
startup
):
with
fluid
.
program_guard
(
main
,
startup
):
avg_cost
,
feature_out
,
word
,
mention
,
target
=
ner_net
(
avg_cost
,
feature_out
,
word
,
mention
,
target
=
ner_net
(
args
.
word_dict_len
,
args
.
label_dict_len
)
args
.
word_dict_len
,
args
.
label_dict_len
)
sgd_optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
1e-3
)
sgd_optimizer
.
minimize
(
avg_cost
)
crf_decode
=
fluid
.
layers
.
crf_decoding
(
crf_decode
=
fluid
.
layers
.
crf_decoding
(
input
=
feature_out
,
param_attr
=
fluid
.
ParamAttr
(
name
=
'crfw'
))
input
=
feature_out
,
param_attr
=
fluid
.
ParamAttr
(
name
=
'crfw'
))
sgd_optimizer
=
fluid
.
optimizer
.
SGD
(
learning_rate
=
1e-3
)
sgd_optimizer
.
minimize
(
avg_cost
)
(
precision
,
recall
,
f1_score
,
num_infer_chunks
,
num_label_chunks
,
(
precision
,
recall
,
f1_score
,
num_infer_chunks
,
num_label_chunks
,
num_correct_chunks
)
=
fluid
.
layers
.
chunk_eval
(
num_correct_chunks
)
=
fluid
.
layers
.
chunk_eval
(
input
=
crf_decode
,
input
=
crf_decode
,
...
@@ -348,8 +349,8 @@ def main(args):
...
@@ -348,8 +349,8 @@ def main(args):
+
str
(
f1
))
+
str
(
f1
))
save_dirname
=
os
.
path
.
join
(
args
.
model_save_dir
,
save_dirname
=
os
.
path
.
join
(
args
.
model_save_dir
,
"params_pass_%d"
%
pass_id
)
"params_pass_%d"
%
pass_id
)
fluid
.
io
.
save_inference_model
(
fluid
.
io
.
save_inference_model
(
save_dirname
,
[
'word'
,
'mention'
],
save_dirname
,
[
'word'
,
'mention'
,
'target'
],
[
crf_decode
],
exe
)
[
crf_decode
],
exe
)
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录