Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PaddleRec
提交
8407391f
P
PaddleRec
项目概览
PaddlePaddle
/
PaddleRec
通知
68
Star
12
Fork
5
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
27
列表
看板
标记
里程碑
合并请求
10
Wiki
1
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PaddleRec
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
27
Issue
27
列表
看板
标记
里程碑
合并请求
10
合并请求
10
Pages
分析
分析
仓库分析
DevOps
Wiki
1
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
8407391f
编写于
5月 29, 2020
作者:
F
frankwhzhang
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix ncf
上级
93e5453c
变更
4
展开全部
隐藏空白更改
内联
并排
Showing
4 changed file
with
72 addition
and
65 deletion
+72
-65
models/multitask/esmm/data/train/small.txt
models/multitask/esmm/data/train/small.txt
+10
-0
models/recall/ncf/config.yaml
models/recall/ncf/config.yaml
+48
-34
models/recall/ncf/model.py
models/recall/ncf/model.py
+13
-30
models/recall/ncf/movielens_infer_reader.py
models/recall/ncf/movielens_infer_reader.py
+1
-1
未找到文件。
models/multitask/esmm/data/train/small.txt
0 → 100644
浏览文件 @
8407391f
此差异已折叠。
点击以展开。
models/recall/ncf/config.yaml
浏览文件 @
8407391f
...
@@ -12,42 +12,56 @@
...
@@ -12,42 +12,56 @@
# See the License for the specific language governing permissions and
# See the License for the specific language governing permissions and
# limitations under the License.
# limitations under the License.
evaluate
:
workspace
:
"
paddlerec.models.recall.ncf"
reader
:
batch_size
:
1
class
:
"
{workspace}/movielens_infer_reader.py"
test_data_path
:
"
{workspace}/data/test"
train
:
dataset
:
trainer
:
-
name
:
dataset_train
# for cluster training
batch_size
:
5
strategy
:
"
async"
type
:
QueueDataset
data_path
:
"
{workspace}/data/train"
data_converter
:
"
{workspace}/movielens_reader.py"
-
name
:
dataset_infer
batch_size
:
5
type
:
QueueDataset
data_path
:
"
{workspace}/data/test"
data_converter
:
"
{workspace}/movielens_infer_reader.py"
epochs
:
3
hyper_parameters
:
workspace
:
"
paddlerec.models.recall.ncf"
num_users
:
6040
device
:
cpu
num_items
:
3706
latent_dim
:
8
layers
:
[
64
,
32
,
16
,
8
]
optimizer
:
class
:
adam
learning_rate
:
0.001
strategy
:
async
reader
:
#use infer_runner mode and modify 'phase' below if infer
batch_size
:
2
mode
:
train_runner
class
:
"
{workspace}/movielens_reader.py"
#mode: infer_runner
train_data_path
:
"
{workspace}/data/train"
model
:
runner
:
models
:
"
{workspace}/model.py"
-
name
:
train_runner
hyper_parameters
:
class
:
single_train
num_users
:
6040
device
:
cpu
num_items
:
3706
epochs
:
3
latent_dim
:
8
save_checkpoint_interval
:
2
layers
:
[
64
,
32
,
16
,
8
]
save_inference_interval
:
4
learning_rate
:
0.001
save_checkpoint_path
:
"
increment"
optimizer
:
adam
save_inference_path
:
"
inference"
print_interval
:
10
-
name
:
infer_runner
class
:
single_infer
init_model_path
:
"
increment/0"
device
:
cpu
epochs
:
3
sav
e
:
phas
e
:
increment
:
-
name
:
train
dirname
:
"
increment
"
model
:
"
{workspace}/model.py
"
epoch_interval
:
2
dataset_name
:
dataset_train
save_last
:
True
thread_num
:
1
inference
:
#- name: infer
dirname
:
"
inference
"
# model: "{workspace}/model.py
"
epoch_interval
:
4
# dataset_name: dataset_infer
save_last
:
True
# thread_num: 1
models/recall/ncf/model.py
浏览文件 @
8407391f
...
@@ -24,7 +24,13 @@ class Model(ModelBase):
...
@@ -24,7 +24,13 @@ class Model(ModelBase):
def
__init__
(
self
,
config
):
def
__init__
(
self
,
config
):
ModelBase
.
__init__
(
self
,
config
)
ModelBase
.
__init__
(
self
,
config
)
def
input_data
(
self
,
is_infer
=
False
):
def
_init_hyper_parameters
(
self
):
self
.
num_users
=
envs
.
get_global_env
(
"hyper_parameters.num_users"
)
self
.
num_items
=
envs
.
get_global_env
(
"hyper_parameters.num_items"
)
self
.
latent_dim
=
envs
.
get_global_env
(
"hyper_parameters.latent_dim"
)
self
.
layers
=
envs
.
get_global_env
(
"hyper_parameters.layers"
)
def
input_data
(
self
,
is_infer
=
False
,
**
kwargs
):
user_input
=
fluid
.
data
(
user_input
=
fluid
.
data
(
name
=
"user_input"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
,
lod_level
=
0
)
name
=
"user_input"
,
shape
=
[
-
1
,
1
],
dtype
=
"int64"
,
lod_level
=
0
)
item_input
=
fluid
.
data
(
item_input
=
fluid
.
data
(
...
@@ -35,45 +41,35 @@ class Model(ModelBase):
...
@@ -35,45 +41,35 @@ class Model(ModelBase):
inputs
=
[
user_input
]
+
[
item_input
]
inputs
=
[
user_input
]
+
[
item_input
]
else
:
else
:
inputs
=
[
user_input
]
+
[
item_input
]
+
[
label
]
inputs
=
[
user_input
]
+
[
item_input
]
+
[
label
]
self
.
_data_var
=
inputs
return
inputs
return
inputs
def
net
(
self
,
inputs
,
is_infer
=
False
):
def
net
(
self
,
inputs
,
is_infer
=
False
):
num_users
=
envs
.
get_global_env
(
"hyper_parameters.num_users"
,
None
,
num_layer
=
len
(
self
.
layers
)
#Number of layers in the MLP
self
.
_namespace
)
num_items
=
envs
.
get_global_env
(
"hyper_parameters.num_items"
,
None
,
self
.
_namespace
)
latent_dim
=
envs
.
get_global_env
(
"hyper_parameters.latent_dim"
,
None
,
self
.
_namespace
)
layers
=
envs
.
get_global_env
(
"hyper_parameters.layers"
,
None
,
self
.
_namespace
)
num_layer
=
len
(
layers
)
#Number of layers in the MLP
MF_Embedding_User
=
fluid
.
embedding
(
MF_Embedding_User
=
fluid
.
embedding
(
input
=
inputs
[
0
],
input
=
inputs
[
0
],
size
=
[
num_users
,
latent_dim
],
size
=
[
self
.
num_users
,
self
.
latent_dim
],
param_attr
=
fluid
.
initializer
.
Normal
(
param_attr
=
fluid
.
initializer
.
Normal
(
loc
=
0.0
,
scale
=
0.01
),
loc
=
0.0
,
scale
=
0.01
),
is_sparse
=
True
)
is_sparse
=
True
)
MF_Embedding_Item
=
fluid
.
embedding
(
MF_Embedding_Item
=
fluid
.
embedding
(
input
=
inputs
[
1
],
input
=
inputs
[
1
],
size
=
[
num_items
,
latent_dim
],
size
=
[
self
.
num_items
,
self
.
latent_dim
],
param_attr
=
fluid
.
initializer
.
Normal
(
param_attr
=
fluid
.
initializer
.
Normal
(
loc
=
0.0
,
scale
=
0.01
),
loc
=
0.0
,
scale
=
0.01
),
is_sparse
=
True
)
is_sparse
=
True
)
MLP_Embedding_User
=
fluid
.
embedding
(
MLP_Embedding_User
=
fluid
.
embedding
(
input
=
inputs
[
0
],
input
=
inputs
[
0
],
size
=
[
num_users
,
int
(
layers
[
0
]
/
2
)],
size
=
[
self
.
num_users
,
int
(
self
.
layers
[
0
]
/
2
)],
param_attr
=
fluid
.
initializer
.
Normal
(
param_attr
=
fluid
.
initializer
.
Normal
(
loc
=
0.0
,
scale
=
0.01
),
loc
=
0.0
,
scale
=
0.01
),
is_sparse
=
True
)
is_sparse
=
True
)
MLP_Embedding_Item
=
fluid
.
embedding
(
MLP_Embedding_Item
=
fluid
.
embedding
(
input
=
inputs
[
1
],
input
=
inputs
[
1
],
size
=
[
num_items
,
int
(
layers
[
0
]
/
2
)],
size
=
[
self
.
num_items
,
int
(
self
.
layers
[
0
]
/
2
)],
param_attr
=
fluid
.
initializer
.
Normal
(
param_attr
=
fluid
.
initializer
.
Normal
(
loc
=
0.0
,
scale
=
0.01
),
loc
=
0.0
,
scale
=
0.01
),
is_sparse
=
True
)
is_sparse
=
True
)
...
@@ -94,7 +90,7 @@ class Model(ModelBase):
...
@@ -94,7 +90,7 @@ class Model(ModelBase):
for
i
in
range
(
1
,
num_layer
):
for
i
in
range
(
1
,
num_layer
):
mlp_vector
=
fluid
.
layers
.
fc
(
mlp_vector
=
fluid
.
layers
.
fc
(
input
=
mlp_vector
,
input
=
mlp_vector
,
size
=
layers
[
i
],
size
=
self
.
layers
[
i
],
act
=
'relu'
,
act
=
'relu'
,
param_attr
=
fluid
.
ParamAttr
(
param_attr
=
fluid
.
ParamAttr
(
initializer
=
fluid
.
initializer
.
TruncatedNormal
(
initializer
=
fluid
.
initializer
.
TruncatedNormal
(
...
@@ -126,16 +122,3 @@ class Model(ModelBase):
...
@@ -126,16 +122,3 @@ class Model(ModelBase):
self
.
_cost
=
avg_cost
self
.
_cost
=
avg_cost
self
.
_metrics
[
"cost"
]
=
avg_cost
self
.
_metrics
[
"cost"
]
=
avg_cost
def
train_net
(
self
):
input_data
=
self
.
input_data
()
self
.
net
(
input_data
)
def
infer_net
(
self
):
self
.
_infer_data_var
=
self
.
input_data
(
is_infer
=
True
)
self
.
_infer_data_loader
=
fluid
.
io
.
DataLoader
.
from_generator
(
feed_list
=
self
.
_infer_data_var
,
capacity
=
64
,
use_double_buffer
=
False
,
iterable
=
False
)
self
.
net
(
self
.
_infer_data_var
,
is_infer
=
True
)
models/recall/ncf/movielens_infer_reader.py
浏览文件 @
8407391f
...
@@ -19,7 +19,7 @@ from collections import defaultdict
...
@@ -19,7 +19,7 @@ from collections import defaultdict
import
numpy
as
np
import
numpy
as
np
class
Evaluate
Reader
(
Reader
):
class
Train
Reader
(
Reader
):
def
init
(
self
):
def
init
(
self
):
pass
pass
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录