@@ -24,28 +24,32 @@ class DataFeedDesc(object):
24
24
currently only used for AsyncExecutor (See comments for class AsyncExecutor
25
25
for a brief introduction)
26
26
27
- DataFeedDesc shall be initialized from a valid protobuf message from disk:
28
- >>> data_feed = fluid.DataFeedDesc('data.proto')
27
+ DataFeedDesc shall be initialized from a valid protobuf message from disk.
29
28
30
29
See :code:`paddle/fluid/framework/data_feed.proto` for message definition.
31
30
A typical message might look like:
32
31
33
- >>> name: "MultiSlotDataFeed"
34
- >>> batch_size: 2
35
- >>> multi_slot_desc {
36
- >>> slots {
37
- >>> name: "words"
38
- >>> type: "uint64"
39
- >>> is_dense: false
40
- >>> is_used: true
41
- >>> }
42
- >>> slots {
43
- >>> name: "label"
44
- >>> type: "uint64"
45
- >>> is_dense: false
46
- >>> is_used: true
47
- >>> }
48
- >>> }
32
+ .. code-block:: python
33
+
34
+ f = open("data.proto", "w")
35
+ print >> f, 'name: "MultiSlotDataFeed"'
36
+ print >> f, 'batch_size: 2'
37
+ print >> f, 'multi_slot_desc {'
38
+ print >> f, ' slots {'
39
+ print >> f, ' name: "words"'
40
+ print >> f, ' type: "uint64"'
41
+ print >> f, ' is_dense: false'
42
+ print >> f, ' is_used: true'
43
+ print >> f, ' }'
44
+ print >> f, ' slots {'
45
+ print >> f, ' name: "label"'
46
+ print >> f, ' type: "uint64"'
47
+ print >> f, ' is_dense: false'
48
+ print >> f, ' is_used: true'
49
+ print >> f, ' }'
50
+ print >> f, '}'
51
+ f.close()
52
+ data_feed = fluid.DataFeedDesc('data.proto')
49
53
50
54
However, users usually shouldn't care about the message format; instead,
51
55
they are encouragd to use :code:`Data Generator` as a tool to generate a
@@ -54,16 +58,23 @@ class DataFeedDesc(object):
54
58
55
59
DataFeedDesc can also be changed during runtime. Once you got familiar with
56
60
what each field mean, you can modify it to better suit your need. E.g.:
57
- >>> data_feed.set_batch_size(128)
58
- >>> data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
59
- >>> data_feed.set_use_slots('wd') # The slot named 'wd' will be used
61
+
62
+ .. code-block:: python
63
+
64
+ data_feed = fluid.DataFeedDesc('data.proto')
65
+ data_feed.set_batch_size(128)
66
+ data_feed.set_dense_slots('wd') # The slot named 'wd' will be dense
67
+ data_feed.set_use_slots('wd') # The slot named 'wd' will be used
60
68
61
69
Finally, the content can be dumped out for debugging purpose:
62
- >>> print(data_feed.desc())
70
+
71
+ .. code-block:: python
72
+
73
+ print(data_feed.desc())
63
74
64
75
Args:
65
76
proto_file(string): Disk file containing a data feed description.
66
-
77
+
67
78
"""
68
79
69
80
def __init__ (self , proto_file ):
@@ -82,8 +93,28 @@ def set_batch_size(self, batch_size):
82
93
Set batch size. Will be effective during training
83
94
84
95
Example:
85
- >>> data_feed = fluid.DataFeedDesc('data.proto')
86
- >>> data_feed.set_batch_size(128)
96
+ .. code-block:: python
97
+
98
+ f = open("data.proto", "w")
99
+ print >> f, 'name: "MultiSlotDataFeed"'
100
+ print >> f, 'batch_size: 2'
101
+ print >> f, 'multi_slot_desc {'
102
+ print >> f, ' slots {'
103
+ print >> f, ' name: "words"'
104
+ print >> f, ' type: "uint64"'
105
+ print >> f, ' is_dense: false'
106
+ print >> f, ' is_used: true'
107
+ print >> f, ' }'
108
+ print >> f, ' slots {'
109
+ print >> f, ' name: "label"'
110
+ print >> f, ' type: "uint64"'
111
+ print >> f, ' is_dense: false'
112
+ print >> f, ' is_used: true'
113
+ print >> f, ' }'
114
+ print >> f, '}'
115
+ f.close()
116
+ data_feed = fluid.DataFeedDesc('data.proto')
117
+ data_feed.set_batch_size(128)
87
118
88
119
Args:
89
120
batch_size: batch size
@@ -98,8 +129,28 @@ def set_dense_slots(self, dense_slots_name):
98
129
sparse slot will be fed into a LoDTensor
99
130
100
131
Example:
101
- >>> data_feed = fluid.DataFeedDesc('data.proto')
102
- >>> data_feed.set_dense_slots(['words'])
132
+ .. code-block:: python
133
+
134
+ f = open("data.proto", "w")
135
+ print >> f, 'name: "MultiSlotDataFeed"'
136
+ print >> f, 'batch_size: 2'
137
+ print >> f, 'multi_slot_desc {'
138
+ print >> f, ' slots {'
139
+ print >> f, ' name: "words"'
140
+ print >> f, ' type: "uint64"'
141
+ print >> f, ' is_dense: false'
142
+ print >> f, ' is_used: true'
143
+ print >> f, ' }'
144
+ print >> f, ' slots {'
145
+ print >> f, ' name: "label"'
146
+ print >> f, ' type: "uint64"'
147
+ print >> f, ' is_dense: false'
148
+ print >> f, ' is_used: true'
149
+ print >> f, ' }'
150
+ print >> f, '}'
151
+ f.close()
152
+ data_feed = fluid.DataFeedDesc('data.proto')
153
+ data_feed.set_dense_slots(['words'])
103
154
104
155
Args:
105
156
dense_slots_name: a list of slot names which will be set dense
@@ -109,7 +160,7 @@ def set_dense_slots(self, dense_slots_name):
109
160
"""
110
161
if self .proto_desc .name != "MultiSlotDataFeed" :
111
162
raise ValueError (
112
- "Only MultiSlotDataFeed need set_dense_slots, pls check your datafeed.proto"
163
+ "Only MultiSlotDataFeed needs set_dense_slots, please check your datafeed.proto"
113
164
)
114
165
for name in dense_slots_name :
115
166
self .proto_desc .multi_slot_desc .slots [self .__name_to_index [
@@ -122,8 +173,28 @@ def set_use_slots(self, use_slots_name):
122
173
ones will be used for a specific model.
123
174
124
175
Example:
125
- >>> data_feed = fluid.DataFeedDesc('data.proto')
126
- >>> data_feed.set_use_slots(['words'])
176
+ .. code-block:: python
177
+
178
+ f = open("data.proto", "w")
179
+ print >> f, 'name: "MultiSlotDataFeed"'
180
+ print >> f, 'batch_size: 2'
181
+ print >> f, 'multi_slot_desc {'
182
+ print >> f, ' slots {'
183
+ print >> f, ' name: "words"'
184
+ print >> f, ' type: "uint64"'
185
+ print >> f, ' is_dense: false'
186
+ print >> f, ' is_used: true'
187
+ print >> f, ' }'
188
+ print >> f, ' slots {'
189
+ print >> f, ' name: "label"'
190
+ print >> f, ' type: "uint64"'
191
+ print >> f, ' is_dense: false'
192
+ print >> f, ' is_used: true'
193
+ print >> f, ' }'
194
+ print >> f, '}'
195
+ f.close()
196
+ data_feed = fluid.DataFeedDesc('data.proto')
197
+ data_feed.set_use_slots(['words'])
127
198
128
199
Args:
129
200
use_slots_name: a list of slot names which will be used in training
@@ -133,7 +204,7 @@ def set_use_slots(self, use_slots_name):
133
204
"""
134
205
if self .proto_desc .name != "MultiSlotDataFeed" :
135
206
raise ValueError (
136
- "Only MultiSlotDataFeed need set_use_slots, pls check your datafeed.proto"
207
+ "Only MultiSlotDataFeed needs set_use_slots, please check your datafeed.proto"
137
208
)
138
209
for name in use_slots_name :
139
210
self .proto_desc .multi_slot_desc .slots [self .__name_to_index [
@@ -144,8 +215,28 @@ def desc(self):
144
215
Returns a protobuf message for this DataFeedDesc
145
216
146
217
Example:
147
- >>> data_feed = fluid.DataFeedDesc('data.proto')
148
- >>> print(data_feed.desc())
218
+ .. code-block:: python
219
+
220
+ f = open("data.proto", "w")
221
+ print >> f, 'name: "MultiSlotDataFeed"'
222
+ print >> f, 'batch_size: 2'
223
+ print >> f, 'multi_slot_desc {'
224
+ print >> f, ' slots {'
225
+ print >> f, ' name: "words"'
226
+ print >> f, ' type: "uint64"'
227
+ print >> f, ' is_dense: false'
228
+ print >> f, ' is_used: true'
229
+ print >> f, ' }'
230
+ print >> f, ' slots {'
231
+ print >> f, ' name: "label"'
232
+ print >> f, ' type: "uint64"'
233
+ print >> f, ' is_dense: false'
234
+ print >> f, ' is_used: true'
235
+ print >> f, ' }'
236
+ print >> f, '}'
237
+ f.close()
238
+ data_feed = fluid.DataFeedDesc('data.proto')
239
+ print(data_feed.desc())
149
240
150
241
Returns:
151
242
A string message
0 commit comments