Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
机器未来
Paddle
提交
66b6ae16
P
Paddle
项目概览
机器未来
/
Paddle
与 Fork 源项目一致
Fork自
PaddlePaddle / Paddle
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
Paddle
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
66b6ae16
编写于
3月 02, 2017
作者:
Y
Yu Yang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Complete api_train_v2
上级
dd47da0d
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
57 addition
and
9 deletion
+57
-9
demo/recommendation/api_train_v2.py
demo/recommendation/api_train_v2.py
+31
-8
python/paddle/v2/dataset/movielens.py
python/paddle/v2/dataset/movielens.py
+26
-1
未找到文件。
demo/recommendation/api_train_v2.py
浏览文件 @
66b6ae16
import
paddle.v2
as
paddle
import
paddle.v2
as
paddle
import
cPickle
import
copy
def
main
():
def
main
():
paddle
.
init
(
use_gpu
=
False
,
trainer_count
=
3
)
paddle
.
init
(
use_gpu
=
False
)
movie_title_dict
=
paddle
.
dataset
.
movielens
.
get_movie_title_dict
()
movie_title_dict
=
paddle
.
dataset
.
movielens
.
get_movie_title_dict
()
uid
=
paddle
.
layer
.
data
(
uid
=
paddle
.
layer
.
data
(
name
=
'user_id'
,
name
=
'user_id'
,
...
@@ -86,19 +88,40 @@ def main():
...
@@ -86,19 +88,40 @@ def main():
if
event
.
batch_id
%
100
==
0
:
if
event
.
batch_id
%
100
==
0
:
print
"Pass %d Batch %d Cost %.2f"
%
(
print
"Pass %d Batch %d Cost %.2f"
%
(
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
)
event
.
pass_id
,
event
.
batch_id
,
event
.
cost
)
elif
isinstance
(
event
,
paddle
.
event
.
EndPass
):
result
=
trainer
.
test
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
dataset
.
movielens
.
test
(),
batch_size
=
256
))
print
result
.
cost
trainer
.
train
(
trainer
.
train
(
reader
=
paddle
.
reader
.
batched
(
reader
=
paddle
.
reader
.
batched
(
paddle
.
reader
.
shuffle
(
paddle
.
reader
.
firstn
(
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
paddle
.
reader
.
shuffle
(
paddle
.
dataset
.
movielens
.
train
(),
buf_size
=
8192
),
n
=
1000
),
batch_size
=
256
),
batch_size
=
256
),
event_handler
=
event_handler
,
event_handler
=
event_handler
,
reader_dict
=
reader_dict
,
reader_dict
=
reader_dict
,
num_passes
=
10
)
num_passes
=
1
)
user_id
=
234
movie_id
=
345
user
=
paddle
.
dataset
.
movielens
.
user_info
()[
user_id
]
movie
=
paddle
.
dataset
.
movielens
.
movie_info
()[
movie_id
]
feature
=
user
.
value
()
+
movie
.
value
()
def
reader
():
yield
feature
infer_dict
=
copy
.
copy
(
reader_dict
)
del
infer_dict
[
'score'
]
print
infer_dict
prediction
=
paddle
.
infer
(
output
=
inference
,
parameters
=
parameters
,
reader
=
paddle
.
reader
.
batched
(
reader
,
batch_size
=
32
),
reader_dict
=
infer_dict
)
print
prediction
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
...
...
python/paddle/v2/dataset/movielens.py
浏览文件 @
66b6ae16
...
@@ -6,7 +6,7 @@ import functools
...
@@ -6,7 +6,7 @@ import functools
__all__
=
[
__all__
=
[
'train'
,
'test'
,
'get_movie_title_dict'
,
'max_movie_id'
,
'max_user_id'
,
'train'
,
'test'
,
'get_movie_title_dict'
,
'max_movie_id'
,
'max_user_id'
,
'age_table'
,
'movie_categories'
,
'max_job_id'
'age_table'
,
'movie_categories'
,
'max_job_id'
,
'user_info'
,
'movie_info'
]
]
age_table
=
[
1
,
18
,
25
,
35
,
45
,
50
,
56
]
age_table
=
[
1
,
18
,
25
,
35
,
45
,
50
,
56
]
...
@@ -24,6 +24,13 @@ class MovieInfo(object):
...
@@ -24,6 +24,13 @@ class MovieInfo(object):
[
MOVIE_TITLE_DICT
[
w
.
lower
()]
for
w
in
self
.
title
.
split
()]
[
MOVIE_TITLE_DICT
[
w
.
lower
()]
for
w
in
self
.
title
.
split
()]
]
]
def
__str__
(
self
):
return
"<MovieInfo id(%d), title(%s), categories(%s)>"
%
(
self
.
index
,
self
.
title
,
self
.
categories
)
def
__repr__
(
self
):
return
self
.
__str__
()
class
UserInfo
(
object
):
class
UserInfo
(
object
):
def
__init__
(
self
,
index
,
gender
,
age
,
job_id
):
def
__init__
(
self
,
index
,
gender
,
age
,
job_id
):
...
@@ -35,6 +42,14 @@ class UserInfo(object):
...
@@ -35,6 +42,14 @@ class UserInfo(object):
def
value
(
self
):
def
value
(
self
):
return
[
self
.
index
,
0
if
self
.
is_male
else
1
,
self
.
age
,
self
.
job_id
]
return
[
self
.
index
,
0
if
self
.
is_male
else
1
,
self
.
age
,
self
.
job_id
]
def
__str__
(
self
):
return
"<UserInfo id(%d), gender(%s), age(%d), job(%d)>"
%
(
self
.
index
,
"M"
if
self
.
is_male
else
"F"
,
age_table
[
self
.
age
],
self
.
job_id
)
def
__repr__
(
self
):
return
str
(
self
)
MOVIE_INFO
=
None
MOVIE_INFO
=
None
MOVIE_TITLE_DICT
=
None
MOVIE_TITLE_DICT
=
None
...
@@ -152,6 +167,16 @@ def movie_categories():
...
@@ -152,6 +167,16 @@ def movie_categories():
return
CATEGORIES_DICT
return
CATEGORIES_DICT
def
user_info
():
__initialize_meta_info__
()
return
USER_INFO
def
movie_info
():
__initialize_meta_info__
()
return
MOVIE_INFO
def
unittest
():
def
unittest
():
for
train_count
,
_
in
enumerate
(
train
()()):
for
train_count
,
_
in
enumerate
(
train
()()):
pass
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录