trainer_config.py 1.6 KB
Newer Older
C
chengxingyi 已提交
1 2 3 4 5 6 7 8 9
#!/usr/bin/env/python
#-*python-*-
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 已提交
10 11
define_py_data_sources2(
    train_list=trn, test_list=tst, module="dataprovider", obj=process)
C
chengxingyi 已提交
12
################################### Parameter Configuaration #######################################
Y
Yu Yang 已提交
13 14 15 16
TERM_NUM = 24
FORECASTING_NUM = 25
emb_size = 16
batch_size = 128 if not is_predict else 1
C
chengxingyi 已提交
17
settings(
Y
Yu Yang 已提交
18 19 20
    batch_size=batch_size,
    learning_rate=1e-3,
    learning_method=RMSPropOptimizer())
C
chengxingyi 已提交
21 22 23 24 25 26 27
################################### 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 已提交
28 29 30
    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 已提交
31 32 33 34 35 36
    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 已提交
37 38 39
        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 已提交
40 41
        output_label.append(cls)
outputs(output_label)