Change cos_sim to use CosSimLayer layer when size=1 and rename convex_comb_layer to linear_comb_layer
Also add an unittest for layers.py, currently for a few things. More need to be added later.avx_docs
parent
a2dfb1040b
commit
7481429f99
@ -0,0 +1,5 @@
|
||||
#################### test_config_parser #########################
|
||||
add_test(NAME layers_test
|
||||
COMMAND ${PROJ_ROOT}/paddle/.set_python_path.sh -d ${PROJ_ROOT}/python/
|
||||
python ${PROJ_ROOT}/python/paddle/trainer_config_helpers/tests/layers_test.py
|
||||
WORKING_DIRECTORY ${PROJ_ROOT}/python/paddle)
|
@ -0,0 +1,19 @@
|
||||
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
|
||||
#
|
||||
# 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.
|
||||
|
||||
from paddle.trainer.config_parser import parse_config_and_serialize
|
||||
|
||||
if __name__ == '__main__':
|
||||
parse_config_and_serialize(
|
||||
'trainer_config_helpers/tests/layers_test_config.py', '')
|
@ -0,0 +1,43 @@
|
||||
# Copyright (c) 2016 Baidu, Inc. All Rights Reserved
|
||||
#
|
||||
# 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.
|
||||
|
||||
from paddle.trainer_config_helpers import *
|
||||
|
||||
num_classes = 5
|
||||
|
||||
x = data_layer(name="input1", size=3)
|
||||
y = data_layer(name="input2", size=5)
|
||||
|
||||
x1 = fc_layer(input=x, size=5)
|
||||
y1 = fc_layer(input=y, size=5)
|
||||
y2 = fc_layer(input=y, size=15)
|
||||
|
||||
cos1 = cos_sim(a=x1, b=y1)
|
||||
cos3 = cos_sim(a=x1, b=y2, size=3)
|
||||
|
||||
linear_comb = linear_comb_layer(weights=x1, vectors=y2, size=3)
|
||||
|
||||
out = fc_layer(input=[cos1, cos3, linear_comb],
|
||||
size=num_classes,
|
||||
act=SoftmaxActivation())
|
||||
|
||||
outputs(classification_cost(out, data_layer(name="label", size=num_classes)))
|
||||
|
||||
settings(
|
||||
batch_size=10,
|
||||
learning_rate=2e-3,
|
||||
learning_method=AdamOptimizer(),
|
||||
regularization=L2Regularization(8e-4),
|
||||
gradient_clipping_threshold=25
|
||||
)
|
Loading…
Reference in new issue