Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

format input data using mx.rnn #7446

Closed
ghost opened this issue Aug 13, 2017 · 3 comments
Closed

format input data using mx.rnn #7446

ghost opened this issue Aug 13, 2017 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 13, 2017

data_ex_git.zip
I've trying to forecast time-series using mx.rnn model but I can't shape the data to input format asked from mx.rnn. I want do predict a variable Q_t using some past values from itself and another variables. Using mx.model.FeedForward.create is very easy to define. I can't understand the "labels" input on mx.rnn model. This is my code:

load("data_ex_git.RData") # attached


train <- data[1:dias_train,]
test <- data[(dias_train+1):nrow(data),]

# Neural net fitting

# Scaling data for the NN
maxs <- apply(data, 2, max)
mins <- apply(data, 2, min)
scaled <- as.data.frame(scale(data, center = mins, scale = maxs - mins))

train_ <- scaled[1:dias_train,]
test_ <- scaled[(dias_train+1):nrow(data),]

library(mxnet)
train.x <- data.matrix(train_[,-1])
train.y <- train_[,1]
test.x <- data.matrix(test_[,-1])
test.y <- test_[,1]

X.train <- list(data=t(train.x), label=t(train.y))
X.val <- list(data=t(test.x), label=t(test.y))

batch.size = 5
seq.len = 5
num.hidden = 3
num.embed = 3
num.rnn.layer = 1
num.lstm.layer = 1
num.round = 1
update.period = 1
learning.rate= 0.1
wd=0.00001
clip_gradient=1

mx.set.seed(0)
model <- mx.rnn(X.train, NULL, num.rnn.layer=num.rnn.layer, seq.len=seq.len, num.hidden=num.hidden,
                num.embed=num.embed, num.label=5, batch.size=batch.size, input.size=5, ctx = mx.cpu(),
                num.round = num.round, update.period = update.period, initializer = mx.init.uniform(0.01),
                dropout = 0, optimizer = "sgd", batch.norm = FALSE,
                learning.rate=learning.rate, wd=wd, clip_gradient=clip_gradient)

preds = predict(model,t(test.x))

That's my error:

[19:10:06] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor\./matrix_op-inl.h:141: Using target_shape will be deprecated. [19:10:06] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor\./matrix_op-inl.h:141: Using target_shape will be deprecated. [19:10:06] d:\program files (x86)\jenkins\workspace\mxnet\mxnet\src\operator\tensor\./matrix_op-inl.h:141: Using target_shape will be deprecated. [19:10:06] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\dmlc-core\include\dmlc/logging.h:308: [19:10:06] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\src\ndarray\ndarray.cc:329: Check failed: from.shape() == to->shape() operands shape mismatchfrom.shape = (5,14) to.shape=(5,5) Error in exec$update.arg.arrays(arg.arrays, match.name, skip.null) : [19:10:06] D:\Program Files (x86)\Jenkins\workspace\mxnet\mxnet\src\ndarray\ndarray.cc:329: Check failed: from.shape() == to->shape() operands shape mismatchfrom.shape = (5,14) to.shape=(5,5)

@thirdwing thirdwing added the R label Aug 14, 2017
@jeremiedb
Copy link
Contributor

The answer to #7524 might answer some of your questions. In short, as I understand it the design of current RNN functionalities assume text data on which embedding is performed. There's a pull request open to help building more general RNN structures #7476.
You can look here for how to approach it. It requires training on GPU though.
As per your data design, you seem to have included different measuring lags of the features (like time minus 1, minus 2), which I'm not sure is appropriate given the RNN is meant to retain the relevant past info.

@ankkhedia
Copy link
Contributor

ankkhedia commented Aug 16, 2018

Hi @ArturIndio MXNet R package RNN API has undergone significant change in the last year and the API mx.rnn no more exist. However, there are various new functionalities added and you can check out nice examples of time series, language modeling and few other use cases here.
https://jeremiedb.github.io/mxnet_R_bucketing/LanguageModel_GPU.html

Please try out the latest API for your use case and let us know if you still need assistance regarding anything.

@sandeep-krishnamurthy @nswamy Could you please add the tag Pending Requester Info to this issue

@ankkhedia
Copy link
Contributor

@sandeep-krishnamurthy @nswamy Could you please close this issue due to inactivity

@ArturIndio Please feel free to reopen if closed in error

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants