diff --git a/06.understand_sentiment/train_conv.py b/06.understand_sentiment/train_conv.py index ee613975607740e29c045ef3746d3bffd4904442..dfee8d7698863f7a8b21096fdc2d387d380d9c3c 100644 --- a/06.understand_sentiment/train_conv.py +++ b/06.understand_sentiment/train_conv.py @@ -14,6 +14,10 @@ from __future__ import print_function +import time +start = time.time() + + import os import paddle import paddle.fluid as fluid @@ -133,8 +137,16 @@ def infer(use_cuda, inference_program, params_dirname=None): # Note that lod info should be a list of lists. reviews_str = [ - 'read the book forget the movie', 'this is a great movie', - 'this is very bad' + 'read the book forget the movie', + 'this is a great movie', + 'this is very bad', + 'the movie makes me sick', + 'you can never find a worse movie', + 'what a masterpiece', + 'it deserves any compliment', + 'no movie this year could be better than this one', + 'i would rather die', + 'the movie should be burned in hell' ] reviews = [c.split() for c in reviews_str] @@ -157,10 +169,16 @@ def main(use_cuda): if use_cuda and not fluid.core.is_compiled_with_cuda(): return params_dirname = "understand_sentiment_conv.inference.model" + import pdb;pdb.set_trace() train(use_cuda, train_program, params_dirname) infer(use_cuda, inference_program, params_dirname) + finish = time.time() + elapsed = finish - start + print(elapsed) + if __name__ == '__main__': use_cuda = False # set to True if training with GPU main(use_cuda) + diff --git a/06.understand_sentiment/train_dyn_rnn.py b/06.understand_sentiment/train_dyn_rnn.py index e8d2690452b691c3b00eabf3ffdee078ddb8876c..5b32857f3562cbe7eabec04e02fb0c4354518338 100644 --- a/06.understand_sentiment/train_dyn_rnn.py +++ b/06.understand_sentiment/train_dyn_rnn.py @@ -14,6 +14,9 @@ from __future__ import print_function +import time +start = time.time() + import os import paddle import paddle.fluid as fluid @@ -123,7 +126,7 @@ def train(use_cuda, train_program, params_dirname): trainer.save_params(params_dirname) trainer.train( - num_epochs=1, + num_epochs=2, event_handler=event_handler, reader=train_reader, feed_order=feed_order) @@ -150,8 +153,16 @@ def infer(use_cuda, inference_program, params_dirname=None): # Note that lod info should be a list of lists. reviews_str = [ - 'read the book forget the movie', 'this is a great movie', - 'this is very bad' + 'read the book forget the movie', + 'this is a great movie', + 'this is very bad', + 'the movie makes me sick', + 'you can never find a worse movie', + 'what a masterpiece', + 'it deserves any compliment', + 'no movie this year could be better than this one', + 'i would rather die', + 'the movie should be burned in hell' ] reviews = [c.split() for c in reviews_str] @@ -177,6 +188,9 @@ def main(use_cuda): train(use_cuda, train_program, params_dirname) infer(use_cuda, inference_program, params_dirname) + finish = time.time() + elapsed = finish - start + print(elapsed) if __name__ == '__main__': use_cuda = False # set to True if training with GPU diff --git a/06.understand_sentiment/train_stacked_lstm.py b/06.understand_sentiment/train_stacked_lstm.py index 708c4851eeba4b37b675b4ba196ffbf3524b7eb3..28bd2848ef9ac05584f683f71aab2de25f5e39ef 100644 --- a/06.understand_sentiment/train_stacked_lstm.py +++ b/06.understand_sentiment/train_stacked_lstm.py @@ -14,6 +14,9 @@ from __future__ import print_function +import time +start = time.time() + import os import paddle import paddle.fluid as fluid @@ -114,7 +117,7 @@ def train(use_cuda, train_program, params_dirname): trainer.save_params(params_dirname) trainer.train( - num_epochs=1, + num_epochs=4, event_handler=event_handler, reader=train_reader, feed_order=feed_order) @@ -141,8 +144,16 @@ def infer(use_cuda, inference_program, params_dirname=None): # Note that lod info should be a list of lists. reviews_str = [ - 'read the book forget the movie', 'this is a great movie', - 'this is very bad' + 'read the book forget the movie', + 'this is a great movie', + 'this is very bad', + 'the movie makes me sick', + 'you can never find a worse movie', + 'what a masterpiece', + 'it deserves any compliment', + 'no movie this year could be better than this one', + 'i would rather die', + 'the movie should be burned in hell' ] reviews = [c.split() for c in reviews_str] @@ -168,6 +179,9 @@ def main(use_cuda): train(use_cuda, train_program, params_dirname) infer(use_cuda, inference_program, params_dirname) + finish = time.time() + elapsed = finish - start + print(elapsed) if __name__ == '__main__': use_cuda = False # set to True if training with GPU