Skip to content

Commit 0388d1c

Browse files
committed
some update
1 parent fab6287 commit 0388d1c

File tree

3 files changed

+18
-25
lines changed

3 files changed

+18
-25
lines changed

python/paddle/fluid/tests/demo/text_classification/convert_data_to_recordio.py renamed to python/paddle/fluid/tests/demo/file_reader/convert_data_to_recordio.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def load_vocab(filename):
5050
BATCH_SIZE = 128
5151
train_reader = paddle.batch(
5252
paddle.reader.shuffle(
53-
paddle.dataset.imdb.train(word_dict), buf_size=10000),
53+
paddle.dataset.imdb.train(word_dict), buf_size=25000),
5454
batch_size=BATCH_SIZE)
5555

5656
test_reader = paddle.batch(

python/paddle/fluid/tests/demo/text_classification/train.py renamed to python/paddle/fluid/tests/demo/file_reader/train.py

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
# hidden dim
2828
hid_dim = 128
2929

30-
# hidden dim2
31-
hid_dim2 = 96
32-
3330
# class num
3431
class_dim = 2
3532

@@ -42,36 +39,34 @@ def build_program(is_train):
4239
filenames=TRAIN_FILES if is_train else TEST_FILES,
4340
shapes=[[-1, 1], [-1, 1]],
4441
lod_levels=[1, 0],
45-
dtypes=['int64', 'int64'],
46-
thread_num=1)
47-
if is_train:
48-
file_obj = fluid.layers.io.shuffle(file_obj_handle, buffer_size=1000)
49-
else:
50-
file_obj = file_obj_handle
51-
file_obj = fluid.layers.io.double_buffer(file_obj)
42+
dtypes=['int64', 'int64'])
43+
44+
file_obj = fluid.layers.io.double_buffer(file_obj_handle)
5245

5346
with fluid.unique_name.guard():
5447

5548
data, label = fluid.layers.read_file(file_obj)
5649

5750
emb = fluid.layers.embedding(input=data, size=[DICT_DIM, emb_dim])
5851

59-
# sequence conv with window size = 3
60-
win_size = 3
6152
conv_3 = fluid.nets.sequence_conv_pool(
6253
input=emb,
6354
num_filters=hid_dim,
64-
filter_size=win_size,
55+
filter_size=3,
6556
act="tanh",
66-
pool_type="max")
57+
pool_type="sqrt")
6758

68-
# fc layer after conv
69-
fc_1 = fluid.layers.fc(input=[conv_3], size=hid_dim2)
59+
conv_4 = fluid.nets.sequence_conv_pool(
60+
input=emb,
61+
num_filters=hid_dim,
62+
filter_size=4,
63+
act="tanh",
64+
pool_type="sqrt")
7065

71-
# probability of each class
72-
prediction = fluid.layers.fc(input=[fc_1],
66+
prediction = fluid.layers.fc(input=[conv_3, conv_4],
7367
size=class_dim,
7468
act="softmax")
69+
7570
# cross entropy loss
7671
cost = fluid.layers.cross_entropy(input=prediction, label=label)
7772

@@ -117,11 +112,9 @@ def main():
117112
try:
118113
batch_id = 0
119114
while True:
120-
result = map(numpy.array,
121-
train_exe.run(fetch_list=fetch_var_list
122-
if batch_id % 10 == 0 else []))
123-
if len(result) != 0:
124-
print 'Train loss: ', result
115+
loss, acc = map(numpy.array,
116+
train_exe.run(fetch_list=fetch_var_list))
117+
print 'Train epoch', epoch_id, 'batch', batch_id, 'loss:', loss, 'acc:', acc
125118
batch_id += 1
126119
except fluid.core.EOFException:
127120
print 'End of epoch', epoch_id
@@ -138,7 +131,7 @@ def main():
138131
acc.append(acc_np[0])
139132
except:
140133
test_args['file'].reset()
141-
print 'TEST: ', numpy.mean(loss), numpy.mean(acc)
134+
print 'Test loss:', numpy.mean(loss), 'acc:', numpy.mean(acc)
142135

143136

144137
if __name__ == '__main__':

0 commit comments

Comments
 (0)