trainer_config.py 2.2 KB
Newer Older
1
# Copyright (c) 2016 PaddlePaddle Authors, Inc. All Rights Reserved
Y
Yu Yang 已提交
2 3 4 5 6 7 8 9 10 11 12 13
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
C
chengxingyi 已提交
14 15 16 17 18 19 20
from paddle.trainer_config_helpers import *

################################### DATA Configuration #############################################
is_predict = get_config_arg('is_predict', bool, False)
trn = './data/train.list' if not is_predict else None
tst = './data/test.list' if not is_predict else './data/pred.list'
process = 'process' if not is_predict else 'process_predict'
Y
Yu Yang 已提交
21 22
define_py_data_sources2(
    train_list=trn, test_list=tst, module="dataprovider", obj=process)
C
chengxingyi 已提交
23
################################### Parameter Configuaration #######################################
Y
Yu Yang 已提交
24
TERM_NUM = 24
25
FORECASTING_NUM = 24
Y
Yu Yang 已提交
26 27
emb_size = 16
batch_size = 128 if not is_predict else 1
C
chengxingyi 已提交
28
settings(
Y
Yu Yang 已提交
29 30 31
    batch_size=batch_size,
    learning_rate=1e-3,
    learning_method=RMSPropOptimizer())
C
chengxingyi 已提交
32 33 34 35 36 37 38
################################### Algorithm Configuration ########################################

output_label = []

link_encode = data_layer(name='link_encode', size=TERM_NUM)
for i in xrange(FORECASTING_NUM):
    # Each task share same weight.
Y
Yu Yang 已提交
39 40 41
    link_param = ParamAttr(
        name='_link_vec.w', initial_max=1.0, initial_min=-1.0)
    link_vec = fc_layer(input=link_encode, size=emb_size, param_attr=link_param)
C
chengxingyi 已提交
42 43 44 45 46 47
    score = fc_layer(input=link_vec, size=4, act=SoftmaxActivation())
    if is_predict:
        maxid = maxid_layer(score)
        output_label.append(maxid)
    else:
        # Multi-task training.
Y
Yu Yang 已提交
48 49 50
        label = data_layer(name='label_%dmin' % ((i + 1) * 5), size=4)
        cls = classification_cost(
            input=score, name="cost_%dmin" % ((i + 1) * 5), label=label)
C
chengxingyi 已提交
51 52
        output_label.append(cls)
outputs(output_label)