bquast / rnn

Recurrent Neural Networks in R
https://qua.st/rnn
73 stars 28 forks source link

Update code #30

Open henkb1987 opened 6 years ago

henkb1987 commented 6 years ago

Hi there,

Thanks for this great package. Would you happen to know if I can fit a model on a subset of data and then update that model with further data at a later time?

Thanks again.

DimitriF commented 6 years ago

late answer, there is a model argument in trainr that does exactly that, just supply the previously trained model and it will keep training

gyubaekkim commented 6 years ago

Hi there,

I want ask more about this issue. I implemented update(re-train) logic but it may not work properly. Please review the following code that excludes unnecessary part and tell me what's wrong.

require(rnn) require(caret)

if (file.exists(filename)) { : previous_model <- readRDS(filename) : model <- trainr(Y=T_Y, X=T_X, model=previous_model, learningrate = 0.2, hidden_dim=5, numepochs=1) :

} else { : model <- trainr(Y=T_Y, X=T_X, learningrate = 0.2, hidden_dim=5, numepochs=1) : } : P <- predictr(model, P_X) : saveRDS(model, filename) :

The above code is run daily so re-training is done with small data. I checked the size of saved model file and found the proportional increase. The issue is that accuracy of prediction using re-trained model was bad.

Thanks in advance.

DimitriF commented 6 years ago

Hi, Normally that would be the way to do it (without inputing again options which are ignored). Could you make str(model) for 2 consecutive days? Dimitri

gyubaekkim commented 6 years ago

Here are the description of 2 consecutive model (initial & re-trained)

DimitriF commented 6 years ago

The second model is a list of length 30, something is wrong.

If I do:

X1 = sample(0:127, 10000, replace=TRUE)
X2 = sample(0:127, 10000, replace=TRUE)
Y <- X1 + X2
X1 <- int2bin(X1, length=8)
X2 <- int2bin(X2, length=8)
Y  <- int2bin(Y,  length=8)
X <- array( c(X1,X2), dim=c(dim(X1),2) )
model <- trainr(Y=Y, X=X,learningrate   =  0.1,momentum = 0.5,
hidden_dim     = 16  ,numepochs = 1,batch_size = 20)
length(model)
model <- trainr(Y=Y,X=X,model=model)
length(model)

Both length are 29.

gyubaekkim commented 6 years ago

learningrate parameter for re-training is missing in your sample. But, in my case, it's not permitted so I found that library version was different. I re-installed the latest version from github. After that, the issue that I reported does not happen again. I don't know why. Anyway DimitriF 's comment was helpful. I appreciate.