From 26e1f22db217c87d8f986c7dc5c4043234e49e52 Mon Sep 17 00:00:00 2001 From: fengjiayi Date: Thu, 14 Sep 2017 10:41:03 -0700 Subject: [PATCH] Rebuild index.html --- 06.understand_sentiment/README.cn.md | 9 +- 06.understand_sentiment/README.md | 17 +- 06.understand_sentiment/index.cn.html | 450 -------------------------- 06.understand_sentiment/index.html | 412 ----------------------- 4 files changed, 14 insertions(+), 874 deletions(-) delete mode 100644 06.understand_sentiment/index.cn.html delete mode 100644 06.understand_sentiment/index.html diff --git a/06.understand_sentiment/README.cn.md b/06.understand_sentiment/README.cn.md index 695db8f..37f5d4e 100644 --- a/06.understand_sentiment/README.cn.md +++ b/06.understand_sentiment/README.cn.md @@ -164,7 +164,6 @@ def stacked_lstm_net(input_dim, """ assert stacked_num % 2 == 1 - layer_attr = paddle.attr.Extra(drop_rate=0.5) fc_para_attr = paddle.attr.Param(learning_rate=1e-3) lstm_para_attr = paddle.attr.Param(initial_std=0., learning_rate=1.) para_attr = [fc_para_attr, lstm_para_attr] @@ -181,7 +180,7 @@ def stacked_lstm_net(input_dim, act=linear, bias_attr=bias_attr) lstm1 = paddle.layer.lstmemory( - input=fc1, act=relu, bias_attr=bias_attr, layer_attr=layer_attr) + input=fc1, act=relu, bias_attr=bias_attr) inputs = [fc1, lstm1] for i in range(2, stacked_num + 1): @@ -194,8 +193,7 @@ def stacked_lstm_net(input_dim, input=fc, reverse=(i % 2) == 0, act=relu, - bias_attr=bias_attr, - layer_attr=layer_attr) + bias_attr=bias_attr) inputs = [fc, lstm] fc_last = paddle.layer.pooling(input=inputs[0], pooling_type=paddle.pooling.Max()) @@ -292,6 +290,9 @@ Paddle中提供了一系列优化算法的API,这里使用Adam优化算法。 sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + with open('./params_pass_%d.tar' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test(reader=test_reader, feeding=feeding) print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics) ``` diff --git a/06.understand_sentiment/README.md b/06.understand_sentiment/README.md index c264a65..adda2ff 100644 --- a/06.understand_sentiment/README.md +++ b/06.understand_sentiment/README.md @@ -136,7 +136,7 @@ def convolution_net(input_dim, class_dim=2, emb_dim=128, hid_dim=128): act=paddle.activation.Softmax()) lbl = paddle.layer.data("label", paddle.data_type.integer_value(2)) cost = paddle.layer.classification_cost(input=output, label=lbl) - return cost + return cost, output ``` 1. Define input data and its dimension @@ -175,7 +175,6 @@ def stacked_lstm_net(input_dim, """ assert stacked_num % 2 == 1 - layer_attr = paddle.attr.Extra(drop_rate=0.5) fc_para_attr = paddle.attr.Param(learning_rate=1e-3) lstm_para_attr = paddle.attr.Param(initial_std=0., learning_rate=1.) para_attr = [fc_para_attr, lstm_para_attr] @@ -192,7 +191,7 @@ def stacked_lstm_net(input_dim, act=linear, bias_attr=bias_attr) lstm1 = paddle.layer.lstmemory( - input=fc1, act=relu, bias_attr=bias_attr, layer_attr=layer_attr) + input=fc1, act=relu, bias_attr=bias_attr) inputs = [fc1, lstm1] for i in range(2, stacked_num + 1): @@ -205,8 +204,7 @@ def stacked_lstm_net(input_dim, input=fc, reverse=(i % 2) == 0, act=relu, - bias_attr=bias_attr, - layer_attr=layer_attr) + bias_attr=bias_attr) inputs = [fc, lstm] fc_last = paddle.layer.pooling( @@ -221,7 +219,7 @@ def stacked_lstm_net(input_dim, lbl = paddle.layer.data("label", paddle.data_type.integer_value(2)) cost = paddle.layer.classification_cost(input=output, label=lbl) - return cost + return cost, output ``` 1. Define input data and its dimension @@ -245,9 +243,9 @@ dict_dim = len(word_dict) class_dim = 2 # option 1 -cost = convolution_net(dict_dim, class_dim=class_dim) +[cost, output] = convolution_net(dict_dim, class_dim=class_dim) # option 2 -# cost = stacked_lstm_net(dict_dim, class_dim=class_dim, stacked_num=3) +# [cost, output] = stacked_lstm_net(dict_dim, class_dim=class_dim, stacked_num=3) ``` ## Model Training @@ -311,6 +309,9 @@ def event_handler(event): sys.stdout.write('.') sys.stdout.flush() if isinstance(event, paddle.event.EndPass): + with open('./params_pass_%d.tar' % event.pass_id, 'w') as f: + parameters.to_tar(f) + result = trainer.test(reader=test_reader, feeding=feeding) print "\nTest with Pass %d, %s" % (event.pass_id, result.metrics) ``` diff --git a/06.understand_sentiment/index.cn.html b/06.understand_sentiment/index.cn.html deleted file mode 100644 index fa5c01e..0000000 --- a/06.understand_sentiment/index.cn.html +++ /dev/null @@ -1,450 +0,0 @@ - - - - - - - - - - - - - - - - - -
-
- - - - - - - diff --git a/06.understand_sentiment/index.html b/06.understand_sentiment/index.html deleted file mode 100644 index 5790072..0000000 --- a/06.understand_sentiment/index.html +++ /dev/null @@ -1,412 +0,0 @@ - - - - - - - - - - - - - - - - - -
-
- - - - - - - -- GitLab