Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
models
提交
c4f3ebc3
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看板
未验证
提交
c4f3ebc3
编写于
2月 14, 2020
作者:
Z
zhengya01
提交者:
GitHub
2月 14, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
add ce for dygraph_sentiment (#4287)
上级
6c14f65e
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
23 addition
and
0 deletion
+23
-0
dygraph/sentiment/main.py
dygraph/sentiment/main.py
+15
-0
dygraph/sentiment/utils.py
dygraph/sentiment/utils.py
+8
-0
未找到文件。
dygraph/sentiment/main.py
浏览文件 @
c4f3ebc3
...
...
@@ -22,6 +22,7 @@ from paddle.fluid.dygraph.base import to_variable
import
nets
import
reader
from
utils
import
ArgumentGroup
from
utils
import
get_cards
parser
=
argparse
.
ArgumentParser
(
__doc__
)
model_g
=
ArgumentGroup
(
parser
,
"model"
,
"model configuration and paths."
)
...
...
@@ -148,6 +149,7 @@ def train():
steps
=
0
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
gru_hidden_data
=
np
.
zeros
((
args
.
batch_size
,
128
),
dtype
=
'float32'
)
ce_time
,
ce_infor
=
[],
[]
for
eop
in
range
(
args
.
epoch
):
time_begin
=
time
.
time
()
for
batch_id
,
data
in
enumerate
(
train_data_generator
()):
...
...
@@ -186,6 +188,8 @@ def train():
np
.
sum
(
total_cost
)
/
np
.
sum
(
total_num_seqs
),
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
),
args
.
skip_steps
/
used_time
))
ce_time
.
append
(
used_time
)
ce_infor
.
append
(
np
.
sum
(
total_acc
)
/
np
.
sum
(
total_num_seqs
))
total_cost
,
total_acc
,
total_num_seqs
=
[],
[],
[]
time_begin
=
time
.
time
()
...
...
@@ -247,6 +251,17 @@ def train():
if
enable_profile
:
print
(
'save profile result into /tmp/profile_file'
)
return
if
args
.
ce
:
card_num
=
get_cards
()
_acc
=
0
_time
=
0
try
:
_time
=
ce_time
[
-
1
]
_acc
=
ce_infor
[
-
1
]
except
:
print
(
"ce info error"
)
print
(
"kpis
\t
train_duration_card%s
\t
%s"
%
(
card_num
,
_time
))
print
(
"kpis
\t
train_acc_card%s
\t
%f"
%
(
card_num
,
_acc
))
def
infer
():
...
...
dygraph/sentiment/utils.py
浏览文件 @
c4f3ebc3
...
...
@@ -16,6 +16,7 @@ from __future__ import division
from
__future__
import
print_function
import
io
import
os
import
sys
import
random
...
...
@@ -80,3 +81,10 @@ def load_vocab(file_path):
wid
+=
1
vocab
[
"<unk>"
]
=
len
(
vocab
)
return
vocab
def
get_cards
():
num
=
0
cards
=
os
.
environ
.
get
(
'CUDA_VISIBLE_DEVICES'
,
''
)
if
cards
!=
''
:
num
=
len
(
cards
.
split
(
","
))
return
num
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录