projections.py 2.3 KB
Newer Older
D
dzhwinter 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13
#  Copyright (c) 2018 PaddlePaddle Authors. All Rights Reserve.
#
#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.
14 15 16 17 18
'''
Test mixed layer, projections and operators.
'''
from paddle.trainer_config_helpers import *

Q
qijun 已提交
19
settings(batch_size=1000, learning_rate=1e-4)
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41

din = data_layer(name='test', size=100)

din = embedding_layer(input=din, size=256)

with mixed_layer(size=100) as m1:
    m1 += full_matrix_projection(input=din)

with mixed_layer(size=100) as m2:
    m2 += table_projection(input=m1)

with mixed_layer(size=100) as m3:
    m3 += identity_projection(input=m2)

with mixed_layer(size=100) as m4:
    m4 += dotmul_projection(input=m3)

with mixed_layer() as m5:
    m5 += context_projection(input=m4, context_len=3)

with mixed_layer() as m6:
    m6 += dotmul_operator(a=m3, b=m4)
X
xuwei06 已提交
42
    m6 += scaling_projection(m3)
43

Q
qijun 已提交
44 45
img = data_layer(name='img', size=32 * 32)
flt = data_layer(name='filter', size=3 * 3 * 1 * 64)
46 47

with mixed_layer() as m7:
Q
qijun 已提交
48 49
    m7 += conv_operator(
        img=img, filter=flt, num_filters=64, num_channels=1, filter_size=3)
50
    m7 += conv_projection(img, filter_size=3, num_filters=64, num_channels=1)
Q
qijun 已提交
51

52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
with mixed_layer() as m8:
    m8 += conv_operator(
        img=img,
        filter=flt,
        num_filters=64,
        num_channels=1,
        filter_size=3,
        stride=2,
        padding=1,
        trans=True)
    m8 += conv_projection(
        img,
        filter_size=3,
        num_filters=64,
        num_channels=1,
        stride=2,
        padding=1,
        trans=True)
Q
qijun 已提交
70 71 72
end = mixed_layer(
    input=[
        full_matrix_projection(input=m5),
73 74
        trans_full_matrix_projection(input=m6),
        full_matrix_projection(input=m7), full_matrix_projection(input=m8)
Q
qijun 已提交
75 76 77 78
    ],
    size=100,
    layer_attr=ExtraAttr(
        drop_rate=0.5, error_clipping_threshold=40))
79 80

outputs(end)