Skip to content

Commit 057d0cb

Browse files
committed
Complete networks.
1 parent 6dd2165 commit 057d0cb

File tree

3 files changed

+61
-1
lines changed

3 files changed

+61
-1
lines changed

python/paddle/v2/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@
2424
from . import reader
2525
import attr
2626
import pooling
27+
import networks
2728
import py_paddle.swig_paddle as api
2829

2930
__all__ = [
3031
'optimizer', 'layer', 'activation', 'parameters', 'init', 'trainer',
3132
'event', 'data_type', 'attr', 'pooling', 'data_feeder', 'dataset', 'reader',
32-
'topology'
33+
'topology', 'networks'
3334
]
3435

3536

python/paddle/v2/config_base.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
115
import collections
216

317
from paddle.trainer_config_helpers.default_decorators import wrap_name_default

python/paddle/v2/networks.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# Copyright (c) 2016 PaddlePaddle Authors. All Rights Reserved
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
import paddle.trainer_config_helpers.networks as conf_nw
16+
import inspect
17+
from config_base import __convert_to_v2__
18+
19+
__all__ = []
20+
21+
22+
def __initialize__():
23+
for each_subnetwork in conf_nw.__all__:
24+
if each_subnetwork in ['inputs', 'outputs']:
25+
continue
26+
func = getattr(conf_nw, each_subnetwork)
27+
if hasattr(func, 'argspec'):
28+
argspec = func.argspec
29+
else:
30+
argspec = inspect.getargspec(func)
31+
if each_subnetwork == 'simple_attention':
32+
parents = ['encoded_sequence', 'encoded_proj', 'decoder_state']
33+
else:
34+
parents = filter(lambda x: x.startswith('input'), argspec.args)
35+
assert len(parents) != 0, each_subnetwork
36+
v2_subnet = __convert_to_v2__(
37+
each_subnetwork,
38+
parent_names=parents,
39+
is_default_name='name' in argspec.args)
40+
globals()[each_subnetwork] = v2_subnet
41+
global __all__
42+
__all__.append(each_subnetwork)
43+
44+
45+
__initialize__()

0 commit comments

Comments
 (0)