Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
ERNIE
提交
5e23ec05
E
ERNIE
项目概览
PaddlePaddle
/
ERNIE
大约 1 年 前同步成功
通知
109
Star
5997
Fork
1270
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
29
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
ERNIE
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
29
Issue
29
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
5e23ec05
编写于
11月 05, 2019
作者:
C
chenxuyi
提交者:
Meiyim
1月 16, 2020
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix paddleTensor and paddleInference
上级
e5d95cb9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
11 addition
and
14 deletion
+11
-14
ernie/ernie_encoder.py
ernie/ernie_encoder.py
+6
-3
ernie/finetune/classifier.py
ernie/finetune/classifier.py
+1
-1
ernie/infer_classifyer.py
ernie/infer_classifyer.py
+3
-9
propeller/service/utils.py
propeller/service/utils.py
+1
-1
未找到文件。
ernie/ernie_encoder.py
浏览文件 @
5e23ec05
...
...
@@ -22,13 +22,16 @@ import argparse
import
numpy
as
np
import
multiprocessing
import
logging
import
paddle.fluid
as
fluid
import
reader.task_reader
as
task_reader
from
model.ernie
import
ErnieConfig
,
ErnieModel
from
utils.args
import
ArgumentGroup
,
print_arguments
from
model.ernie
_v1
import
ErnieConfig
,
ErnieModel
from
utils.args
import
ArgumentGroup
,
print_arguments
,
prepare_logger
from
utils.init
import
init_pretraining_params
log
=
logging
.
getLogger
()
# yapf: disable
parser
=
argparse
.
ArgumentParser
(
__doc__
)
model_g
=
ArgumentGroup
(
parser
,
"model"
,
"model configuration and paths."
)
...
...
@@ -67,7 +70,6 @@ def create_model(args, pyreader_name, ernie_config):
src_ids
=
src_ids
,
position_ids
=
pos_ids
,
sentence_ids
=
sent_ids
,
task_ids
=
task_ids
,
input_mask
=
input_mask
,
config
=
ernie_config
)
...
...
@@ -179,6 +181,7 @@ def main(args):
if
__name__
==
'__main__'
:
prepare_logger
(
log
)
args
=
parser
.
parse_args
()
print_arguments
(
args
)
...
...
ernie/finetune/classifier.py
浏览文件 @
5e23ec05
...
...
@@ -52,7 +52,7 @@ def create_model(args,
elif
is_regression
:
labels
=
fluid
.
layers
.
data
(
name
=
'6'
,
shape
=
[
-
1
,
1
],
dtype
=
'float32'
)
pyreader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
[
src_ids
,
sent_ids
,
pos_ids
,
task_ids
,
input_mask
,
qids
],
pyreader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
[
src_ids
,
sent_ids
,
pos_ids
,
task_ids
,
input_mask
,
labels
,
qids
],
capacity
=
70
,
iterable
=
False
)
...
...
ernie/infer_classifyer.py
浏览文件 @
5e23ec05
...
...
@@ -130,6 +130,7 @@ def main(args):
if
not
args
.
use_cuda
:
log
.
info
(
"disable gpu"
)
config
.
disable_gpu
()
config
.
switch_ir_optim
(
True
)
else
:
log
.
info
(
"using gpu"
)
config
.
enable_use_gpu
(
1024
)
...
...
@@ -162,8 +163,7 @@ def main(args):
# parse outputs
output
=
outputs
[
0
]
output_data
=
output
.
data
.
float_data
()
batch_result
=
np
.
array
(
output_data
).
reshape
(
output
.
shape
)
batch_result
=
output
.
as_ndarray
()
for
single_example_probs
in
batch_result
:
print
(
'
\t
'
.
join
(
map
(
str
,
single_example_probs
.
tolist
())))
index
+=
1
...
...
@@ -173,13 +173,7 @@ def main(args):
def
array2tensor
(
ndarray
):
""" convert numpy array to PaddleTensor"""
assert
isinstance
(
ndarray
,
np
.
ndarray
),
"input type must be np.ndarray"
if
ndarray
.
dtype
==
np
.
float32
:
dtype
=
PaddleDType
.
FLOAT32
elif
ndarray
.
dtype
==
np
.
int64
:
dtype
=
PaddleDType
.
INT64
else
:
raise
ValueError
(
"{} type ndarray is unsupported"
.
format
(
ndarray
.
dtype
))
tensor
=
PaddleTensor
(
data
=
ndarray
,
name
=
"data"
)
tensor
=
PaddleTensor
(
data
=
ndarray
)
return
tensor
if
__name__
==
'__main__'
:
...
...
propeller/service/utils.py
浏览文件 @
5e23ec05
...
...
@@ -73,7 +73,7 @@ def slot_to_paddlearray(slot):
raise
RuntimeError
(
'know type %s'
%
slot
.
type
)
num
=
len
(
slot
.
data
)
//
struct
.
calcsize
(
type_str
)
arr
=
struct
.
unpack
(
'%d%s'
%
(
num
,
type_str
),
slot
.
data
)
ret
=
core
.
PaddleTensor
(
n
ame
=
'1'
,
data
=
n
p
.
array
(
arr
,
dtype
=
dtype
).
reshape
(
slot
.
dims
))
ret
=
core
.
PaddleTensor
(
np
.
array
(
arr
,
dtype
=
dtype
).
reshape
(
slot
.
dims
))
return
ret
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录