Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleHub
提交
63192b42
P
PaddleHub
项目概览
PaddlePaddle
/
PaddleHub
大约 1 年 前同步成功
通知
282
Star
12117
Fork
2091
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
200
列表
看板
标记
里程碑
合并请求
4
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleHub
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
200
Issue
200
列表
看板
标记
里程碑
合并请求
4
合并请求
4
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
63192b42
编写于
1月 23, 2019
作者:
W
wuzewu
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/PaddlePaddle/PaddleHub
上级
17b54bfe
4fbe2611
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
52 addition
and
31 deletion
+52
-31
tests/test_downloader.py
tests/test_downloader.py
+1
-1
tests/test_export_n_load_module.py
tests/test_export_n_load_module.py
+26
-22
tests/test_module.py
tests/test_module.py
+25
-8
未找到文件。
tests/test_downloader.py
浏览文件 @
63192b42
...
...
@@ -18,7 +18,7 @@ import paddle_hub as hub
class
TestDownloader
(
unittest
.
TestCase
):
def
test_download
(
self
):
link
=
"http
://paddlehub.bj.bcebos.com/word2vec/word2vec-dim16-simple-example-2
.tar.gz"
link
=
"http
s://paddlehub.cdn.bcebos.com/word2vec/word2vec_test_module
.tar.gz"
module_path
=
hub
.
download_and_uncompress
(
link
)
...
...
tests/test_export_n_load_module.py
浏览文件 @
63192b42
...
...
@@ -154,36 +154,40 @@ def test_create_w2v_module(use_gpu=False):
main_program
.
global_block
().
var
(
"fourthw"
),
]
signature
=
hub
.
create_signature
(
"default"
,
inputs
=
module_inputs
,
outputs
=
[
pred_prob
])
"default"
,
inputs
=
module_inputs
,
outputs
=
[
pred_prob
],
feed_names
=
[
"firstw"
,
"secondw"
,
"thirdw"
,
"fourthw"
],
fetch_names
=
[
"pred_prob"
])
hub
.
create_module
(
sign_arr
=
signature
,
program
=
fluid
.
default_main_program
(),
module_dir
=
saved_module_dir
,
word_dict
=
dictionary
)
sign_arr
=
signature
,
module_dir
=
saved_module_dir
,
word_dict
=
dictionary
)
def
test_load_w2v_module
(
use_gpu
=
False
):
saved_module_dir
=
"./tmp/word2vec_test_module"
w2v_module
=
hub
.
Module
(
module_dir
=
saved_module_dir
)
feed_
list
,
fetch_list
,
program
,
generator
=
w2v_module
(
feed_
dict
,
fetch_dict
,
program
=
w2v_module
(
sign_name
=
"default"
,
trainable
=
False
)
with
fluid
.
program_guard
(
main_program
=
program
):
with
fluid
.
unique_name
.
guard
(
generator
):
pred_prob
=
fetch_list
[
0
]
pred_word
=
fluid
.
layers
.
argmax
(
x
=
pred_prob
,
axis
=
1
)
# set place, executor, datafeeder
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
feed_list
)
word_ids
=
[[
1
,
2
,
3
,
4
]]
result
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
feeder
.
feed
(
word_ids
),
fetch_list
=
[
pred_word
],
return_numpy
=
True
)
print
(
result
)
pred_prob
=
fetch_dict
[
"pred_prob"
]
pred_word
=
fluid
.
layers
.
argmax
(
x
=
pred_prob
,
axis
=
1
)
# set place, executor, datafeeder
place
=
fluid
.
CUDAPlace
(
0
)
if
use_gpu
else
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
feed_vars
=
[
feed_dict
[
"firstw"
],
feed_dict
[
"secondw"
],
feed_dict
[
"thirdw"
],
feed_dict
[
"fourthw"
]
]
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
feed_vars
)
word_ids
=
[[
1
,
2
,
3
,
4
]]
result
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
feeder
.
feed
(
word_ids
),
fetch_list
=
[
pred_word
],
return_numpy
=
True
)
print
(
result
)
if
__name__
==
"__main__"
:
...
...
tests/test_module.py
浏览文件 @
63192b42
...
...
@@ -15,19 +15,36 @@
import
unittest
import
paddle_hub
as
hub
import
paddle.fluid
as
fluid
class
TestModule
(
unittest
.
TestCase
):
#TODO(ZeyuChen): add setup for test envrinoment prepration
def
test_word2vec_module_usage
(
self
):
pass
# url = "http://paddlehub.cdn.bcebos.com/word2vec/word2vec-dim16-simple-example-2.tar.gz"
# module = Module(module_url=url)
# inputs = [["it", "is", "new"], ["hello", "world"]]
# tensor = module._process_input(inputs)
# print(tensor)
# result = module(inputs)
# print(result)
url
=
"https://paddlehub.cdn.bcebos.com/word2vec/word2vec_test_module.tar.gz"
w2v_module
=
hub
.
Module
(
module_url
=
url
)
feed_dict
,
fetch_dict
,
program
=
w2v_module
(
sign_name
=
"default"
,
trainable
=
False
)
with
fluid
.
program_guard
(
main_program
=
program
):
pred_prob
=
fetch_dict
[
"pred_prob"
]
pred_word
=
fluid
.
layers
.
argmax
(
x
=
pred_prob
,
axis
=
1
)
# set place, executor, datafeeder
place
=
fluid
.
CPUPlace
()
exe
=
fluid
.
Executor
(
place
)
feed_vars
=
[
feed_dict
[
"firstw"
],
feed_dict
[
"secondw"
],
feed_dict
[
"thirdw"
],
feed_dict
[
"fourthw"
]
]
feeder
=
fluid
.
DataFeeder
(
place
=
place
,
feed_list
=
feed_vars
)
word_ids
=
[[
1
,
2
,
3
,
4
]]
result
=
exe
.
run
(
fluid
.
default_main_program
(),
feed
=
feeder
.
feed
(
word_ids
),
fetch_list
=
[
pred_word
],
return_numpy
=
True
)
self
.
assertEqual
(
result
[
0
],
5
)
def
test_senta_module_usage
(
self
):
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录