From 3a5f98c36a13a4c027ee87461f52b49ebb6b6002 Mon Sep 17 00:00:00 2001 From: hedaoyuan Date: Wed, 1 Mar 2017 18:59:00 +0800 Subject: [PATCH] Add reader.shuffle --- demo/sentiment/train_with_new_api.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/demo/sentiment/train_with_new_api.py b/demo/sentiment/train_with_new_api.py index f937b0290..59a303c0d 100644 --- a/demo/sentiment/train_with_new_api.py +++ b/demo/sentiment/train_with_new_api.py @@ -134,7 +134,6 @@ def data_reader(): for i, line in enumerate(fdict): dictionary[line.split('\t')[0]] = i - print('dict len : %d' % (len(dictionary))) for line_count, line in enumerate(fdata): label, comment = line.strip().split('\t\t') label = int(label) @@ -165,7 +164,7 @@ if __name__ == '__main__': def event_handler(event): if isinstance(event, paddle.event.EndIteration): - if event.batch_id % 1 == 0: + if event.batch_id % 100 == 0: print "Pass %d, Batch %d, Cost %f, %s" % ( event.pass_id, event.batch_id, event.cost, event.metrics) @@ -175,7 +174,8 @@ if __name__ == '__main__': trainer.train( reader=paddle.reader.batched( - data_reader, batch_size=128), + paddle.reader.shuffle( + data_reader, buf_size=4096), batch_size=128), event_handler=event_handler, reader_dict={'word': 0, 'label': 1}, -- GitLab