Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
6d3433e3
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看板
未验证
提交
6d3433e3
编写于
8月 09, 2018
作者:
Y
Yibing Liu
提交者:
GitHub
8月 09, 2018
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1114 from kuke/text_cls_ce
Enable model ce for text_classification
上级
43b3541f
4f639a21
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
82 addition
and
9 deletion
+82
-9
fluid/sequence_tagging_for_ner/train.py
fluid/sequence_tagging_for_ner/train.py
+1
-1
fluid/text_classification/.run_ce.sh
fluid/text_classification/.run_ce.sh
+5
-0
fluid/text_classification/_ce.py
fluid/text_classification/_ce.py
+48
-0
fluid/text_classification/train.py
fluid/text_classification/train.py
+12
-0
fluid/text_classification/utils.py
fluid/text_classification/utils.py
+16
-8
未找到文件。
fluid/sequence_tagging_for_ner/train.py
浏览文件 @
6d3433e3
...
...
@@ -53,7 +53,7 @@ def main(train_data_file, test_data_file, vocab_file, target_file, emb_file,
chunk_scheme
=
"IOB"
,
num_chunk_types
=
int
(
math
.
ceil
((
label_dict_len
-
1
)
/
2.0
)))
inference_program
=
fluid
.
default_main_program
().
clone
()
inference_program
=
fluid
.
default_main_program
().
clone
(
for_test
=
True
)
with
fluid
.
program_guard
(
inference_program
):
test_target
=
chunk_evaluator
.
metrics
+
chunk_evaluator
.
states
inference_program
=
fluid
.
io
.
get_inference_program
(
test_target
)
...
...
fluid/text_classification/.run_ce.sh
0 → 100755
浏览文件 @
6d3433e3
###!/bin/bash
####This file is only used for continuous evaluation.
export
CE_MODE_X
=
1
python train.py cnn | python _ce.py
fluid/text_classification/_ce.py
0 → 100644
浏览文件 @
6d3433e3
####this file is only used for continuous evaluation test!
import
os
import
sys
sys
.
path
.
append
(
os
.
environ
[
'ceroot'
])
from
kpi
import
CostKpi
,
DurationKpi
,
AccKpi
#### NOTE kpi.py should shared in models in some way!!!!
train_acc_kpi
=
AccKpi
(
'train_acc'
,
0.005
,
actived
=
True
)
train_cost_kpi
=
CostKpi
(
'train_cost'
,
0.005
,
actived
=
True
)
train_duration_kpi
=
DurationKpi
(
'train_duration'
,
0.05
,
actived
=
True
)
tracking_kpis
=
[
train_acc_kpi
,
train_cost_kpi
,
train_duration_kpi
,
]
def
parse_log
(
log
):
for
line
in
log
.
split
(
'
\n
'
):
fs
=
line
.
strip
().
split
(
'
\t
'
)
print
(
fs
)
if
len
(
fs
)
==
3
and
fs
[
0
]
==
'kpis'
:
print
(
"-----%s"
%
fs
)
kpi_name
=
fs
[
1
]
kpi_value
=
float
(
fs
[
2
])
yield
kpi_name
,
kpi_value
def
log_to_ce
(
log
):
kpi_tracker
=
{}
for
kpi
in
tracking_kpis
:
kpi_tracker
[
kpi
.
name
]
=
kpi
for
(
kpi_name
,
kpi_value
)
in
parse_log
(
log
):
print
(
kpi_name
,
kpi_value
)
kpi_tracker
[
kpi_name
].
add_record
(
kpi_value
)
kpi_tracker
[
kpi_name
].
persist
()
if
__name__
==
'__main__'
:
log
=
sys
.
stdin
.
read
()
print
(
"*****"
)
print
(
log
)
print
(
"****"
)
log_to_ce
(
log
)
fluid/text_classification/train.py
浏览文件 @
6d3433e3
import
os
import
sys
import
time
import
unittest
...
...
@@ -53,8 +54,12 @@ def train(train_reader,
exe
=
fluid
.
Executor
(
place
)
feeder
=
fluid
.
DataFeeder
(
feed_list
=
[
data
,
label
],
place
=
place
)
# For internal continuous evaluation
if
'CE_MODE_X'
in
os
.
environ
:
fluid
.
default_startup_program
().
random_seed
=
110
exe
.
run
(
fluid
.
default_startup_program
())
for
pass_id
in
xrange
(
pass_num
):
pass_start
=
time
.
time
()
data_size
,
data_count
,
total_acc
,
total_cost
=
0
,
0
,
0.0
,
0.0
for
data
in
train_reader
():
avg_cost_np
,
avg_acc_np
=
exe
.
run
(
fluid
.
default_main_program
(),
...
...
@@ -73,6 +78,13 @@ def train(train_reader,
epoch_model
=
save_dirname
+
"/"
+
"epoch"
+
str
(
pass_id
)
fluid
.
io
.
save_inference_model
(
epoch_model
,
[
"words"
,
"label"
],
acc
,
exe
)
pass_end
=
time
.
time
()
# For internal continuous evaluation
if
'CE_MODE_X'
in
os
.
environ
:
print
(
"kpis train_acc %f"
%
avg_acc
)
print
(
"kpis train_cost %f"
%
avg_cost
)
print
(
"kpis train_duration %f"
%
(
pass_end
-
pass_start
))
def
train_net
():
word_dict
,
train_reader
,
test_reader
=
utils
.
prepare_data
(
...
...
fluid/text_classification/utils.py
浏览文件 @
6d3433e3
import
os
import
sys
import
time
import
numpy
as
np
...
...
@@ -64,15 +65,22 @@ def prepare_data(data_type="imdb",
raise
RuntimeError
(
"No such dataset"
)
if
data_type
==
"imdb"
:
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
imdb
.
train
(
word_dict
),
buf_size
=
buf_size
),
batch_size
=
batch_size
)
if
'CE_MODE_X'
in
os
.
environ
:
train_reader
=
paddle
.
batch
(
paddle
.
dataset
.
imdb
.
train
(
word_dict
),
batch_size
=
batch_size
)
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
imdb
.
test
(
word_dict
),
buf_size
=
buf_size
),
batch_size
=
batch_size
)
test_reader
=
paddle
.
batch
(
paddle
.
dataset
.
imdb
.
test
(
word_dict
),
batch_size
=
batch_size
)
else
:
train_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
imdb
.
train
(
word_dict
),
buf_size
=
buf_size
),
batch_size
=
batch_size
)
test_reader
=
paddle
.
batch
(
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
imdb
.
test
(
word_dict
),
buf_size
=
buf_size
),
batch_size
=
batch_size
)
else
:
raise
RuntimeError
(
"no such dataset"
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录