Skip to content

Commit 88cb8ee

Browse files
committed
Complete documentation for v2.
1 parent fd41a87 commit 88cb8ee

23 files changed

+381
-109
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: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,11 @@ Data API
1616
:maxdepth: 1
1717

1818
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: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,80 @@
22
DataTypes
33
#########
44

5-
.. automodule:: paddle.v2.data_type
6-
:members:
5+
.. automodule:: paddle.v2.data_type
6+
:members:
7+
8+
##########
9+
DataFeeder
10+
##########
11+
12+
.. automodule:: paddle.v2.data_feeder
13+
:members:
14+
15+
######
16+
Reader
17+
######
18+
19+
.. automodule:: paddle.v2.reader
20+
:members:
21+
22+
.. automodule:: paddle.v2.reader.creator
23+
:members:
24+
25+
#######
26+
Dataset
27+
#######
28+
29+
.. automodule:: paddle.v2.dataset
30+
:members:
31+
32+
33+
mnist
34+
+++++
35+
36+
.. automodule:: paddle.v2.dataset.mnist
37+
:members:
38+
39+
40+
cifar
41+
+++++
42+
43+
.. automodule:: paddle.v2.dataset.cifar
44+
:members:
45+
46+
conll05
47+
+++++++
48+
49+
.. automodule:: paddle.v2.dataset.conll05
50+
:members:
51+
52+
imdb
53+
++++
54+
55+
.. automodule:: paddle.v2.dataset.imdb
56+
:members:
57+
58+
imikolov
59+
++++++++
60+
61+
.. automodule:: paddle.v2.dataset.imikolov
62+
:members:
63+
64+
movielens
65+
+++++++++
66+
67+
.. automodule:: paddle.v2.dataset.movielens
68+
:members:
69+
70+
sentiment
71+
+++++++++
72+
73+
.. automodule:: paddle.v2.dataset.sentiment
74+
:members:
75+
76+
uci_housing
77+
+++++++++++
78+
79+
.. automodule:: paddle.v2.dataset.uci_housing
80+
:members:
81+

doc/api/v2/model_configs.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,10 @@ Networks
3333

3434
.. automodule:: paddle.v2.networks
3535
:members:
36+
37+
==========
38+
Optimizers
39+
==========
40+
41+
.. automodule:: paddle.v2.optimizers
42+
:members:

doc/api/v2/run_logic.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
==========
2+
Parameters
3+
==========
4+
5+
.. automodule:: paddle.v2.parameters
6+
:members:
7+
8+
9+
=======
10+
Trainer
11+
=======
12+
13+
.. automodule:: paddle.v2.trainer
14+
:members:
15+
16+
17+
=====
18+
Event
19+
=====
20+
21+
.. automodule:: paddle.v2.event
22+
: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
```

python/paddle/v2/data_feeder.py

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from py_paddle import swig_paddle
1615
from py_paddle import DataProviderConverter
16+
1717
import data_type
1818

1919
__all__ = ['DataFeeder']
@@ -29,7 +29,10 @@ class DataFeeder(DataProviderConverter):
2929
to feed it to C++ interface.
3030
3131
The example usage:
32-
32+
33+
34+
.. code-block:: python
35+
3336
data_types = [('image', paddle.data_type.dense_vector(784)),
3437
('label', paddle.data_type.integer_value(10))]
3538
reader_dict = {'image':0, 'label':1}
@@ -43,20 +46,24 @@ class DataFeeder(DataProviderConverter):
4346
# [ [1.0,2.0,3.0,4.0], 5, [6,7,8] ] # second sample
4447
# ]
4548
arg = feeder(minibatch_data)
49+
50+
.. note::
51+
52+
This module is for internal use only. Users should use the `reader`
53+
interface.
54+
55+
56+
57+
:param data_types: A list to specify data name and type. Each item is
58+
a tuple of (data_name, data_type).
59+
60+
:type data_types: list
61+
:param reader_dict: A dictionary to specify the position of each data
62+
in the input data.
63+
:type reader_dict: dict
4664
"""
4765

4866
def __init__(self, data_types, reader_dict):
49-
"""
50-
:param data_types: A list to specify data name and type. Each item is
51-
a tuple of (data_name, data_type). For example:
52-
[('image', paddle.data_type.dense_vector(784)),
53-
('label', paddle.data_type.integer_value(10))]
54-
55-
:type data_types: A list of tuple
56-
:param reader_dict: A dictionary to specify the position of each data
57-
in the input data.
58-
:type reader_dict: dict()
59-
"""
6067
self.input_names = []
6168
input_types = []
6269
self.reader_dict = reader_dict
@@ -70,22 +77,12 @@ def convert(self, dat, argument=None):
7077
"""
7178
:param dat: A list of mini-batch data. Each sample is a list or tuple
7279
one feature or multiple features.
73-
for example:
74-
[
75-
([0.2, 0.2], ), # first sample
76-
([0.8, 0.3], ), # second sample
77-
]
78-
or,
79-
[
80-
[[0.2, 0.2], ], # first sample
81-
[[0.8, 0.3], ], # second sample
82-
]
83-
84-
:type dat: List
80+
81+
:type dat: list
8582
:param argument: An Arguments object contains this mini-batch data with
8683
one or multiple features. The Arguments definition is
8784
in the API.
88-
:type argument: swig_paddle.Arguments
85+
:type argument: py_paddle.swig_paddle.Arguments
8986
"""
9087

9188
def reorder_data(data):

python/paddle/v2/dataset/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
"""
15+
Dataset package.
16+
"""
1417

1518
import mnist
1619
import imikolov

python/paddle/v2/dataset/cifar.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
# limitations under the License.
1414
"""
1515
CIFAR dataset: https://www.cs.toronto.edu/~kriz/cifar.html
16+
17+
TODO(yuyang18): Complete the comments.
1618
"""
1719

1820
import cPickle

python/paddle/v2/dataset/conll05.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,17 @@
1616
import gzip
1717
import itertools
1818
from common import download
19-
20-
__all__ = ['test, get_dict', 'get_embedding']
2119
"""
2220
Conll 2005 dataset. Paddle semantic role labeling Book and demo use this
2321
dataset as an example. Because Conll 2005 is not free in public, the default
2422
downloaded URL is test set of Conll 2005 (which is public). Users can change
2523
URL and MD5 to their Conll dataset.
24+
25+
TODO(yuyang18): Complete comments.
2626
"""
2727

28+
__all__ = ['test, get_dict', 'get_embedding']
29+
2830
DATA_URL = 'http://www.cs.upc.edu/~srlconll/conll05st-tests.tar.gz'
2931
DATA_MD5 = '387719152ae52d60422c016e92a742fc'
3032
WORDDICT_URL = 'http://paddlepaddle.bj.bcebos.com/demo/srl_dict_and_embedding/wordDict.txt'

0 commit comments

Comments
 (0)