You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/08/21 22:56:06 UTC

[GitHub] hetong007 closed pull request #12263: [MXNET-628] Fix example on text classification using LSTMs on IMDB dataset

hetong007 closed pull request #12263: [MXNET-628] Fix example on text classification using LSTMs on IMDB dataset
URL: https://github.com/apache/incubator-mxnet/pull/12263
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/example/rnn/bucket_R/aclImdb_lstm_classification.R b/example/rnn/bucket_R/aclImdb_lstm_classification.R
index f8a55a4db50..f5e6659aada 100644
--- a/example/rnn/bucket_R/aclImdb_lstm_classification.R
+++ b/example/rnn/bucket_R/aclImdb_lstm_classification.R
@@ -40,20 +40,34 @@ optimizer <- mx.opt.create("adadelta", rho = 0.92, epsilon = 1e-06, wd = 2e-04,
 bucket_list <- unique(c(train.data$bucket.names, eval.data$bucket.names))
 
 symbol_buckets <- sapply(bucket_list, function(seq) {
-  rnn.graph(config = "seq-to-one", cell_type = "lstm", 
-            num_rnn_layer = 1, num_embed = 2, num_hidden = 6, 
-            num_decode = 2, input_size = vocab, dropout = 0.5, 
-            ignore_label = -1, loss_output = "softmax",
-            output_last_state = F, masking = T)
+  rnn.graph(config = "seq-to-one",
+            cell_type = "lstm",
+            num_rnn_layer = 1,
+            num_embed = 2,
+            num_hidden = 6,
+            num_decode = 2,
+            input_size = vocab,
+            dropout = 0.2,
+            ignore_label = -1,
+            loss_output = "softmax",
+            output_last_state = F,
+            masking = T)
 })
 
+# Accuracy on Training Data = 0.84066
 model_sentiment_lstm <- mx.model.buckets(symbol = symbol_buckets,
-                          train.data = train.data, eval.data = eval.data,
-                          num.round = num.round, ctx = devices, verbose = FALSE,
-                          metric = mx.metric.accuracy, optimizer = optimizer,  
-                          initializer = initializer,
-                          batch.end.callback = NULL, 
-                          epoch.end.callback = epoch.end.callback)
+                                         train.data = train.data,
+                                         eval.data = eval.data,
+                                         num.round = num.round,
+                                         ctx = devices,
+                                         verbose = FALSE,
+                                         metric = mx.metric.accuracy,
+                                         optimizer = optimizer,
+                                         initializer = mx.init.Xavier(rnd_type = "gaussian",
+                                                                      factor_type = "in",
+                                                                      magnitude = 2),
+                                         batch.end.callback = mx.callback.log.train.metric(period = 50),
+                                         epoch.end.callback = NULL)
 
 mx.model.save(model_sentiment_lstm, prefix = "model_sentiment_lstm", iteration = num.round)
 model <- mx.model.load("model_sentiment_lstm", iteration = num.round)
@@ -72,6 +86,7 @@ while (eval.data$iter.next()) {
 
 ylabel <- as.array(packer$get())
 
+# Accuracy on Test Data = 0.81194
 acc <- sum(ylabel == ypred)/length(ylabel)
 
 message(paste("Acc:", acc))


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services