Skip to content

Commit fc6f203

Browse files
committed
Merge branch 'develop' of https://github.com/PaddlePaddle/Paddle into develop
2 parents 047f3a7 + 299e959 commit fc6f203

File tree

24 files changed

+1068
-325
lines changed

24 files changed

+1068
-325
lines changed

.gitmodules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
[submodule "book"]
22
path = book
33
url = https://github.com/PaddlePaddle/book.git
4+
branch = develop

book

Submodule book updated 113 files

demo/mnist/api_train_v2.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,14 @@ def event_handler(event):
122122
test_creator = paddle.dataset.mnist.test()
123123
test_data = []
124124
for item in test_creator():
125-
test_data.append(item[0])
125+
test_data.append((item[0], ))
126126
if len(test_data) == 100:
127127
break
128128

129129
# output is a softmax layer. It returns probabilities.
130130
# Shape should be (100, 10)
131-
probs = paddle.infer(output=predict, parameters=parameters, input=test_data)
131+
probs = paddle.infer(
132+
output_layer=predict, parameters=parameters, input=test_data)
132133
print probs.shape
133134

134135

demo/sentiment/train_v2.py

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
# limitations under the License.
1414

1515
import sys
16-
import paddle.trainer_config_helpers.attrs as attrs
17-
from paddle.trainer_config_helpers.poolings import MaxPooling
1816
import paddle.v2 as paddle
1917

2018

@@ -51,16 +49,14 @@ def stacked_lstm_net(input_dim,
5149
emb_dim: dimension of word embedding.
5250
hid_dim: dimension of hidden layer.
5351
stacked_num: number of stacked lstm-hidden layer.
54-
is_predict: is predicting or not.
55-
Some layers is not needed in network when predicting.
5652
"""
5753
assert stacked_num % 2 == 1
5854

59-
layer_attr = attrs.ExtraLayerAttribute(drop_rate=0.5)
60-
fc_para_attr = attrs.ParameterAttribute(learning_rate=1e-3)
61-
lstm_para_attr = attrs.ParameterAttribute(initial_std=0., learning_rate=1.)
55+
layer_attr = paddle.attr.Extra(drop_rate=0.5)
56+
fc_para_attr = paddle.attr.Param(learning_rate=1e-3)
57+
lstm_para_attr = paddle.attr.Param(initial_std=0., learning_rate=1.)
6258
para_attr = [fc_para_attr, lstm_para_attr]
63-
bias_attr = attrs.ParameterAttribute(initial_std=0., l2_rate=0.)
59+
bias_attr = paddle.attr.Param(initial_std=0., l2_rate=0.)
6460
relu = paddle.activation.Relu()
6561
linear = paddle.activation.Linear()
6662

@@ -90,8 +86,10 @@ def stacked_lstm_net(input_dim,
9086
layer_attr=layer_attr)
9187
inputs = [fc, lstm]
9288

93-
fc_last = paddle.layer.pooling(input=inputs[0], pooling_type=MaxPooling())
94-
lstm_last = paddle.layer.pooling(input=inputs[1], pooling_type=MaxPooling())
89+
fc_last = paddle.layer.pooling(
90+
input=inputs[0], pooling_type=paddle.pooling.Max())
91+
lstm_last = paddle.layer.pooling(
92+
input=inputs[1], pooling_type=paddle.pooling.Max())
9593
output = paddle.layer.fc(input=[fc_last, lstm_last],
9694
size=class_dim,
9795
act=paddle.activation.Softmax(),
@@ -105,14 +103,23 @@ def stacked_lstm_net(input_dim,
105103

106104
if __name__ == '__main__':
107105
# init
108-
paddle.init(use_gpu=False, trainer_count=4)
106+
paddle.init(use_gpu=False)
109107

110-
# network config
108+
#data
111109
print 'load dictionary...'
112110
word_dict = paddle.dataset.imdb.word_dict()
113111
dict_dim = len(word_dict)
114112
class_dim = 2
113+
train_reader = paddle.batch(
114+
paddle.reader.shuffle(
115+
lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),
116+
batch_size=100)
117+
test_reader = paddle.batch(
118+
lambda: paddle.dataset.imdb.test(word_dict), batch_size=100)
119+
120+
feeding = {'word': 0, 'label': 1}
115121

122+
# network config
116123
# Please choose the way to build the network
117124
# by uncommenting the corresponding line.
118125
cost = convolution_net(dict_dim, class_dim=class_dim)
@@ -137,12 +144,7 @@ def event_handler(event):
137144
sys.stdout.write('.')
138145
sys.stdout.flush()
139146
if isinstance(event, paddle.event.EndPass):
140-
result = trainer.test(
141-
reader=paddle.batch(
142-
lambda: paddle.dataset.imdb.test(word_dict),
143-
batch_size=128),
144-
feeding={'word': 0,
145-
'label': 1})
147+
result = trainer.test(reader=test_reader, feeding=feeding)
146148
print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics)
147149

148150
# create trainer
@@ -151,11 +153,7 @@ def event_handler(event):
151153
update_equation=adam_optimizer)
152154

153155
trainer.train(
154-
reader=paddle.batch(
155-
paddle.reader.shuffle(
156-
lambda: paddle.dataset.imdb.train(word_dict), buf_size=1000),
157-
batch_size=100),
156+
reader=train_reader,
158157
event_handler=event_handler,
159-
feeding={'word': 0,
160-
'label': 1},
161-
num_passes=10)
158+
feeding=feeding,
159+
num_passes=2)

demo/seqToseq/api_train_v2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import sys
12
import paddle.v2 as paddle
23

34

@@ -104,7 +105,9 @@ def main():
104105
parameters = paddle.parameters.create(cost)
105106

106107
# define optimize method and trainer
107-
optimizer = paddle.optimizer.Adam(learning_rate=1e-4)
108+
optimizer = paddle.optimizer.Adam(
109+
learning_rate=5e-5,
110+
regularization=paddle.optimizer.L2Regularization(rate=1e-3))
108111
trainer = paddle.trainer.SGD(cost=cost,
109112
parameters=parameters,
110113
update_equation=optimizer)
@@ -125,8 +128,11 @@ def main():
125128
def event_handler(event):
126129
if isinstance(event, paddle.event.EndIteration):
127130
if event.batch_id % 10 == 0:
128-
print "Pass %d, Batch %d, Cost %f, %s" % (
131+
print "\nPass %d, Batch %d, Cost %f, %s" % (
129132
event.pass_id, event.batch_id, event.cost, event.metrics)
133+
else:
134+
sys.stdout.write('.')
135+
sys.stdout.flush()
130136

131137
# start to train
132138
trainer.train(

doc/api/index_cn.rst

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
API
22
===
33

4-
模型配置 API
5-
------------
6-
74
.. toctree::
85
:maxdepth: 1
96

10-
v2/model_configs.rst
11-
12-
数据 API
13-
--------
14-
15-
.. toctree::
16-
:maxdepth: 1
17-
18-
v2/data.rst
19-
20-
训练 API
21-
--------
22-
23-
.. toctree::
24-
:maxdepth: 1
25-
26-
v2/run_logic.rst
7+
模型配置 <v2/model_configs.rst>
8+
数据访问 <v2/data.rst>
9+
训练与应用 <v2/run_logic.rst>

doc/api/index_en.rst

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,9 @@
11
API
22
===
33

4-
Model Config API
5-
----------------
6-
74
.. toctree::
85
:maxdepth: 1
96

107
v2/model_configs.rst
11-
12-
Data API
13-
--------
14-
15-
.. toctree::
16-
:maxdepth: 1
17-
188
v2/data.rst
19-
20-
Train API
21-
---------
22-
23-
.. toctree::
24-
:maxdepth: 1
25-
26-
v2/run_logic.rst
9+
v2/run_logic.rst

doc/api/v2/config/activation.rst

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
===========
2+
Activation
3+
===========
4+
5+
Abs
6+
===
7+
8+
.. automodule:: paddle.v2.activation
9+
:members: Abs
10+
:noindex:
11+
12+
Exp
13+
===
14+
15+
.. automodule:: paddle.v2.activation
16+
:members: Exp
17+
:noindex:
18+
19+
Identity
20+
========
21+
22+
.. automodule:: paddle.v2.activation
23+
:members: Identity
24+
:noindex:
25+
26+
Linear
27+
======
28+
29+
.. automodule:: paddle.v2.activation
30+
:members: Linear
31+
:noindex:
32+
33+
Log
34+
===
35+
36+
.. automodule:: paddle.v2.activation
37+
:members: Log
38+
:noindex:
39+
40+
Square
41+
======
42+
43+
.. automodule:: paddle.v2.activation
44+
:members: Square
45+
:noindex:
46+
47+
Sigmoid
48+
=======
49+
50+
.. automodule:: paddle.v2.activation
51+
:members: Sigmoid
52+
:noindex:
53+
54+
Softmax
55+
=======
56+
57+
.. automodule:: paddle.v2.activation
58+
:members: Softmax
59+
:noindex:
60+
61+
SequenceSoftmax
62+
===============
63+
64+
.. automodule:: paddle.v2.activation
65+
:members: SequenceSoftmax
66+
:noindex:
67+
68+
Relu
69+
====
70+
71+
.. automodule:: paddle.v2.activation
72+
:members: Relu
73+
:noindex:
74+
75+
BRelu
76+
=====
77+
78+
.. automodule:: paddle.v2.activation
79+
:members: BRelu
80+
:noindex:
81+
82+
SoftRelu
83+
========
84+
85+
.. automodule:: paddle.v2.activation
86+
:members: SoftRelu
87+
:noindex:
88+
89+
Tanh
90+
====
91+
92+
.. automodule:: paddle.v2.activation
93+
:members: Tanh
94+
:noindex:
95+
96+
STanh
97+
=====
98+
99+
.. automodule:: paddle.v2.activation
100+
:members: STanh
101+
:noindex:

doc/api/v2/config/attr.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Parameter Attribute
2+
===================
3+
4+
.. automodule:: paddle.v2.attr
5+
:members:
6+
:noindex:

0 commit comments

Comments
 (0)