提交 f4cb25b4 编写于 作者: F frankwhzhang

fix youtube_dnn

上级 8407391f
...@@ -13,37 +13,42 @@ ...@@ -13,37 +13,42 @@
# limitations under the License. # limitations under the License.
train: workspace: "paddlerec.models.recall.youtube_dnn"
trainer:
# for cluster training
strategy: "async"
epochs: 3 dataset:
workspace: "paddlerec.models.recall.youtube_dnn" - name: dataset_train
device: cpu batch_size: 5
type: DataLoader
#type: QueueDataset
data_path: "{workspace}/data/train"
data_converter: "{workspace}/random_reader.py"
hyper_parameters:
watch_vec_size: 64
search_vec_size: 64
other_feat_size: 64
output_size: 100
layers: [128, 64, 32]
optimizer:
class: adam
learning_rate: 0.001
strategy: async
reader: mode: train_runner
batch_size: 2
class: "{workspace}/random_reader.py"
train_data_path: "{workspace}/data/train"
model: runner:
models: "{workspace}/model.py" - name: train_runner
hyper_parameters: class: single_train
watch_vec_size: 64 device: cpu
search_vec_size: 64 epochs: 3
other_feat_size: 64 save_checkpoint_interval: 2
output_size: 100 save_inference_interval: 4
layers: [128, 64, 32] save_checkpoint_path: "increment"
learning_rate: 0.01 save_inference_path: "inference"
optimizer: sgd print_interval: 10
save: phase:
increment: - name: train
dirname: "increment" model: "{workspace}/model.py"
epoch_interval: 2 dataset_name: dataset_train
save_last: True thread_num: 1
inference:
dirname: "inference"
epoch_interval: 4
save_last: True
...@@ -13,39 +13,64 @@ ...@@ -13,39 +13,64 @@
# limitations under the License. # limitations under the License.
import math import math
import numpy as np
import paddle.fluid as fluid import paddle.fluid as fluid
from paddlerec.core.utils import envs from paddlerec.core.utils import envs
from paddlerec.core.model import Model as ModelBase from paddlerec.core.model import Model as ModelBase
import numpy as np
class Model(ModelBase): 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.watch_vec_size = envs.get_global_env(
"hyper_parameters.watch_vec_size")
self.search_vec_size = envs.get_global_env(
"hyper_parameters.search_vec_size")
self.other_feat_size = envs.get_global_env(
"hyper_parameters.other_feat_size")
self.output_size = envs.get_global_env("hyper_parameters.output_size")
self.layers = envs.get_global_env("hyper_parameters.layers")
watch_vec_size = envs.get_global_env("hyper_parameters.watch_vec_size", def input_data(self, is_infer=False, **kwargs):
None, self._namespace)
search_vec_size = envs.get_global_env(
"hyper_parameters.search_vec_size", None, self._namespace)
other_feat_size = envs.get_global_env(
"hyper_parameters.other_feat_size", None, self._namespace)
watch_vec = fluid.data( watch_vec = fluid.data(
name="watch_vec", shape=[None, watch_vec_size], dtype="float32") name="watch_vec",
shape=[None, self.watch_vec_size],
dtype="float32")
search_vec = fluid.data( search_vec = fluid.data(
name="search_vec", shape=[None, search_vec_size], dtype="float32") name="search_vec",
shape=[None, self.search_vec_size],
dtype="float32")
other_feat = fluid.data( other_feat = fluid.data(
name="other_feat", shape=[None, other_feat_size], dtype="float32") name="other_feat",
shape=[None, self.other_feat_size],
dtype="float32")
label = fluid.data(name="label", shape=[None, 1], dtype="int64") label = fluid.data(name="label", shape=[None, 1], dtype="int64")
inputs = [watch_vec] + [search_vec] + [other_feat] + [label] inputs = [watch_vec] + [search_vec] + [other_feat] + [label]
self._data_var = inputs
return inputs return inputs
def fc(self, tag, data, out_dim, active='relu'): def net(self, inputs, is_infer=False):
concat_feats = fluid.layers.concat(input=inputs[:-1], axis=-1)
l1 = self._fc('l1', concat_feats, self.layers[0], 'relu')
l2 = self._fc('l2', l1, self.layers[1], 'relu')
l3 = self._fc('l3', l2, self.layers[2], 'relu')
l4 = self._fc('l4', l3, self.output_size, 'softmax')
num_seqs = fluid.layers.create_tensor(dtype='int64')
acc = fluid.layers.accuracy(input=l4, label=inputs[-1], total=num_seqs)
cost = fluid.layers.cross_entropy(input=l4, label=inputs[-1])
avg_cost = fluid.layers.mean(cost)
self._cost = avg_cost
self._metrics["acc"] = acc
def _fc(self, tag, data, out_dim, active='relu'):
init_stddev = 1.0 init_stddev = 1.0
scales = 1.0 / np.sqrt(data.shape[1]) scales = 1.0 / np.sqrt(data.shape[1])
...@@ -67,31 +92,3 @@ class Model(ModelBase): ...@@ -67,31 +92,3 @@ class Model(ModelBase):
bias_attr=b_attr, bias_attr=b_attr,
name=tag) name=tag)
return out return out
def net(self, inputs):
output_size = envs.get_global_env("hyper_parameters.output_size", None,
self._namespace)
layers = envs.get_global_env("hyper_parameters.layers", None,
self._namespace)
concat_feats = fluid.layers.concat(input=inputs[:-1], axis=-1)
l1 = self.fc('l1', concat_feats, layers[0], 'relu')
l2 = self.fc('l2', l1, layers[1], 'relu')
l3 = self.fc('l3', l2, layers[2], 'relu')
l4 = self.fc('l4', l3, output_size, 'softmax')
num_seqs = fluid.layers.create_tensor(dtype='int64')
acc = fluid.layers.accuracy(input=l4, label=inputs[-1], total=num_seqs)
cost = fluid.layers.cross_entropy(input=l4, label=inputs[-1])
avg_cost = fluid.layers.mean(cost)
self._cost = avg_cost
self._metrics["acc"] = acc
def train_net(self):
input_data = self.input_data()
self.net(input_data)
def infer_net(self):
pass
...@@ -13,22 +13,22 @@ ...@@ -13,22 +13,22 @@
# limitations under the License. # limitations under the License.
from __future__ import print_function from __future__ import print_function
import numpy as np
from paddlerec.core.reader import Reader from paddlerec.core.reader import Reader
from paddlerec.core.utils import envs from paddlerec.core.utils import envs
from collections import defaultdict from collections import defaultdict
import numpy as np
class TrainReader(Reader): class TrainReader(Reader):
def init(self): def init(self):
self.watch_vec_size = envs.get_global_env( self.watch_vec_size = envs.get_global_env(
"hyper_parameters.watch_vec_size", None, "train.model") "hyper_parameters.watch_vec_size")
self.search_vec_size = envs.get_global_env( self.search_vec_size = envs.get_global_env(
"hyper_parameters.search_vec_size", None, "train.model") "hyper_parameters.search_vec_size")
self.other_feat_size = envs.get_global_env( self.other_feat_size = envs.get_global_env(
"hyper_parameters.other_feat_size", None, "train.model") "hyper_parameters.other_feat_size")
self.output_size = envs.get_global_env("hyper_parameters.output_size", self.output_size = envs.get_global_env("hyper_parameters.output_size")
None, "train.model")
def generate_sample(self, line): def generate_sample(self, line):
""" """
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册