Skip to content

Commit 5f2cbce

Browse files
authored
Merge pull request #1558 from reyoung/add_comments_to_v2_module
(Partially) Complete V2 Documentation
2 parents 8bb2613 + 977fcef commit 5f2cbce

27 files changed

+522
-124
lines changed

doc/api/index_cn.rst

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
API
2-
===
2+
===
3+
4+
模型配置 API
5+
------------
6+
7+
.. toctree::
8+
:maxdepth: 1
9+
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

doc/api/index_en.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,20 @@ Model Config API
77
.. toctree::
88
:maxdepth: 1
99

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

doc/api/v2/data.rst

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
================
2+
Data Related API
3+
================
4+
5+
6+
#########
7+
DataTypes
8+
#########
9+
10+
.. automodule:: paddle.v2.data_type
11+
:members:
12+
13+
##########
14+
DataFeeder
15+
##########
16+
17+
.. automodule:: paddle.v2.data_feeder
18+
:members:
19+
20+
######
21+
Reader
22+
######
23+
24+
.. automodule:: paddle.v2.reader
25+
:members:
26+
27+
.. automodule:: paddle.v2.reader.creator
28+
:members:
29+
30+
#########
31+
minibatch
32+
#########
33+
34+
.. automodule:: paddle.v2.minibatch
35+
:members:
36+
37+
#######
38+
Dataset
39+
#######
40+
41+
.. automodule:: paddle.v2.dataset
42+
:members:
43+
44+
45+
mnist
46+
+++++
47+
48+
.. automodule:: paddle.v2.dataset.mnist
49+
:members:
50+
51+
52+
cifar
53+
+++++
54+
55+
.. automodule:: paddle.v2.dataset.cifar
56+
:members:
57+
58+
conll05
59+
+++++++
60+
61+
.. automodule:: paddle.v2.dataset.conll05
62+
:members:
63+
64+
imdb
65+
++++
66+
67+
.. automodule:: paddle.v2.dataset.imdb
68+
:members:
69+
70+
imikolov
71+
++++++++
72+
73+
.. automodule:: paddle.v2.dataset.imikolov
74+
:members:
75+
76+
movielens
77+
+++++++++
78+
79+
.. automodule:: paddle.v2.dataset.movielens
80+
:members:
81+
82+
sentiment
83+
+++++++++
84+
85+
.. automodule:: paddle.v2.dataset.sentiment
86+
:members:
87+
88+
uci_housing
89+
+++++++++++
90+
91+
.. automodule:: paddle.v2.dataset.uci_housing
92+
:members:
93+

doc/api/v2/model_configs.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#########################
2+
Configuration Related API
3+
#########################
4+
15
======
26
Layers
37
======
@@ -33,3 +37,10 @@ Networks
3337

3438
.. automodule:: paddle.v2.networks
3539
:members:
40+
41+
==========
42+
Optimizers
43+
==========
44+
45+
.. automodule:: paddle.v2.optimizer
46+
:members:

doc/api/v2/run_logic.rst

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
###########
2+
Trainer API
3+
###########
4+
5+
==========
6+
Parameters
7+
==========
8+
9+
.. automodule:: paddle.v2.parameters
10+
:members:
11+
12+
13+
=======
14+
Trainer
15+
=======
16+
17+
.. automodule:: paddle.v2.trainer
18+
:members:
19+
20+
21+
=====
22+
Event
23+
=====
24+
25+
.. automodule:: paddle.v2.event
26+
:members:

doc/design/reader/README.md

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@ An example implementation for single item data reader creator:
2323

2424
```python
2525
def reader_creator_random_image(width, height):
26-
def reader():
27-
while True:
28-
yield numpy.random.uniform(-1, 1, size=width*height)
29-
return reader
26+
def reader():
27+
while True:
28+
yield numpy.random.uniform(-1, 1, size=width*height)
29+
return reader
3030
```
3131

3232
An example implementation for multiple item data reader creator:
3333
```python
34-
def reader_creator_random_imageand_label(widht, height, label):
35-
def reader():
36-
while True:
37-
yield numpy.random.uniform(-1, 1, size=width*height), label
38-
return reader
34+
def reader_creator_random_image_and_label(width, height, label):
35+
def reader():
36+
while True:
37+
yield numpy.random.uniform(-1, 1, size=width*height), label
38+
return reader
3939
```
4040

4141
## Batch Reader Interface
@@ -74,11 +74,11 @@ mnist_train_batch_reader = paddle.batch(mnist_train, 128)
7474
Also easy to create custom batch reader:
7575
```python
7676
def custom_batch_reader():
77-
while True:
78-
batch = []
79-
for i in xrange(128):
80-
batch.append((numpy.random.uniform(-1, 1, 28*28),)) # note that it's a tuple being appended.
81-
yield batch
77+
while True:
78+
batch = []
79+
for i in xrange(128):
80+
batch.append((numpy.random.uniform(-1, 1, 28*28),)) # note that it's a tuple being appended.
81+
yield batch
8282

8383
mnist_random_image_batch_reader = custom_batch_reader
8484
```
@@ -123,16 +123,16 @@ We can do:
123123

124124
```python
125125
def reader_creator_random_image(width, height):
126-
def reader():
127-
while True:
128-
yield numpy.random.uniform(-1, 1, size=width*height)
129-
return reader
126+
def reader():
127+
while True:
128+
yield numpy.random.uniform(-1, 1, size=width*height)
129+
return reader
130130

131131
def reader_creator_bool(t):
132-
def reader:
133-
while True:
134-
yield t
135-
return reader
132+
def reader:
133+
while True:
134+
yield t
135+
return reader
136136

137137
true_reader = reader_creator_bool(True)
138138
false_reader = reader_creator_bool(False)
@@ -172,18 +172,18 @@ We decided to use dictionary (`{"image":0, "label":1}`) instead of list (`["imag
172172

173173
```python
174174
def image_reader_creator(image_path, label_path, n):
175-
def reader():
176-
f = open(image_path)
177-
l = open(label_path)
178-
images = numpy.fromfile(
179-
f, 'ubyte', count=n * 28 * 28).reshape((n, 28 * 28)).astype('float32')
180-
images = images / 255.0 * 2.0 - 1.0
181-
labels = numpy.fromfile(l, 'ubyte', count=n).astype("int")
182-
for i in xrange(n):
183-
yield images[i, :], labels[i] # a single entry of data is created each time
184-
f.close()
185-
l.close()
186-
return reader
175+
def reader():
176+
f = open(image_path)
177+
l = open(label_path)
178+
images = numpy.fromfile(
179+
f, 'ubyte', count=n * 28 * 28).reshape((n, 28 * 28)).astype('float32')
180+
images = images / 255.0 * 2.0 - 1.0
181+
labels = numpy.fromfile(l, 'ubyte', count=n).astype("int")
182+
for i in xrange(n):
183+
yield images[i, :], labels[i] # a single entry of data is created each time
184+
f.close()
185+
l.close()
186+
return reader
187187

188188
# images_reader_creator creates a reader
189189
reader = image_reader_creator("/path/to/image_file", "/path/to/label_file", 1024)
@@ -196,7 +196,7 @@ An example implementation of paddle.train could be:
196196

197197
```python
198198
def train(batch_reader, mapping, batch_size, total_pass):
199-
for pass_idx in range(total_pass):
200-
for mini_batch in batch_reader(): # this loop will never end in online learning.
201-
do_forward_backward(mini_batch, mapping)
199+
for pass_idx in range(total_pass):
200+
for mini_batch in batch_reader(): # this loop will never end in online learning.
201+
do_forward_backward(mini_batch, mapping)
202202
```

0 commit comments

Comments
 (0)