Open henkb1987 opened 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
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.
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
Here are the description of 2 consecutive model (initial & re-trained)
Inital List of 29 $ input_dim : int 4 $ hidden_dim : num 5 $ output_dim : int 1 $ synapse_dim : num [1:3] 4 5 1 $ time_dim : int 32 $ sigmoid : chr "logistic" $ network_type : chr "rnn" $ numepochs : num 1 $ batch_size : num 1 $ learningrate : num 0.2 $ learningrate_decay : num 1 $ momentum : num 0 $ update_rule : chr "sgd" $ use_bias : logi FALSE $ seq_to_seq_unsync : logi FALSE $ epoch_function :List of 2 ..$ :function (model) ..$ :function (model) $ loss_function :function (model) $ last_layer_error : num [1:8637, 1:32, 1] -0.501 0.568 -0.573 -0.446 0.437 ... $ last_layer_delta : num [1:8637, 1:32, 1] -0.125 0.139 -0.14 -0.11 0.107 ... $ store :List of 2 ..$ : num [1:8637, 1:32, 1:5] 0.338 0.261 0.211 0.26 0.34 ... ..$ : num [1:8637, 1:32, 1] 0.501 0.432 0.573 0.446 0.563 ... $ time_synapse :List of 2 ..$ : num [1:4, 1:5] -0.637 -0.1629 -0.0229 -0.225 -0.3313 ... ..$ : num [1:5, 1] -0.85 4.794 -0.744 -0.78 -2.605 $ recurrent_synapse :List of 1 ..$ : num [1:5, 1:5] 1.592 0.665 1.752 1.533 -0.28 ... $ bias_synapse :List of 2 ..$ : num [1:5] -0.085244 -0.038063 0.043454 0.000909 -0.0694 ..$ : num 5.89 $ time_synapse_update :List of 2 ..$ : num [1:4, 1:5] 0 0 0 0 0 0 0 0 0 0 ... ..$ : num [1:5, 1] 0 0 0 0 0 $ bias_synapse_update :List of 2 ..$ : num [1:5] 0 0 0 0 0 ..$ : num 0 $ recurrent_synapse_update:List of 1 ..$ : num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ... $ error : num [1:8637, 1] 0.941 1.233 1.148 0.908 0.875 ... $ current_epoch : int 1 $ store_best :List of 2 ..$ : num [1:8637, 1:32, 1:5] 0.338 0.261 0.211 0.26 0.34 ... ..$ : num [1:8637, 1:32, 1] 0.501 0.432 0.573 0.446 0.563 ...
Re-trained List of 30 $ model :List of 29 ..$ input_dim : int 4 ..$ hidden_dim : num 5 ..$ output_dim : int 1 ..$ synapse_dim : num [1:3] 4 5 1 ..$ time_dim : int 32 ..$ sigmoid : chr "logistic" ..$ network_type : chr "rnn" ..$ numepochs : num 1 ..$ batch_size : num 1 ..$ learningrate : num 0.2 ..$ learningrate_decay : num 1 ..$ momentum : num 0 ..$ update_rule : chr "sgd" ..$ use_bias : logi FALSE ..$ seq_to_seq_unsync : logi FALSE ..$ epoch_function :List of 2 .. ..$ :function (model) .. ..$ :function (model) ..$ loss_function :function (model) ..$ last_layer_error : num [1:8637, 1:32, 1] -0.501 0.568 -0.573 -0.446 0.437 ... ..$ last_layer_delta : num [1:8637, 1:32, 1] -0.125 0.139 -0.14 -0.11 0.107 ... ..$ store :List of 2 .. ..$ : num [1:8637, 1:32, 1:5] 0.338 0.261 0.211 0.26 0.34 ... .. ..$ : num [1:8637, 1:32, 1] 0.501 0.432 0.573 0.446 0.563 ... ..$ time_synapse :List of 2 .. ..$ : num [1:4, 1:5] -0.637 -0.1629 -0.0229 -0.225 -0.3313 ... .. ..$ : num [1:5, 1] -0.85 4.794 -0.744 -0.78 -2.605 ..$ recurrent_synapse :List of 1 .. ..$ : num [1:5, 1:5] 1.592 0.665 1.752 1.533 -0.28 ... ..$ bias_synapse :List of 2 .. ..$ : num [1:5] -0.085244 -0.038063 0.043454 0.000909 -0.0694 .. ..$ : num 5.89 ..$ time_synapse_update :List of 2 .. ..$ : num [1:4, 1:5] 0 0 0 0 0 0 0 0 0 0 ... .. ..$ : num [1:5, 1] 0 0 0 0 0 ..$ bias_synapse_update :List of 2 .. ..$ : num [1:5] 0 0 0 0 0 .. ..$ : num 0 ..$ recurrent_synapse_update:List of 1 .. ..$ : num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ... ..$ error : num [1:8637, 1] 0.941 1.233 1.148 0.908 0.875 ... ..$ current_epoch : int 1 ..$ store_best :List of 2 .. ..$ : num [1:8637, 1:32, 1:5] 0.338 0.261 0.211 0.26 0.34 ... .. ..$ : num [1:8637, 1:32, 1] 0.501 0.432 0.573 0.446 0.563 ... ..- attr(*, "error")= num 1.24 $ input_dim : int 4 $ hidden_dim : num 5 $ output_dim : int 1 $ synapse_dim : num [1:3] 4 5 1 $ time_dim : int 32 $ sigmoid : chr "logistic" $ network_type : chr "rnn" $ numepochs : num 1 $ batch_size : num 1 $ learningrate : num 0.2 $ learningrate_decay : num 1 $ momentum : num 0 $ update_rule : chr "sgd" $ use_bias : logi FALSE $ seq_to_seq_unsync : logi FALSE $ epoch_function :List of 2 ..$ :function (model) ..$ :function (model) $ loss_function :function (model) $ last_layer_error : num [1:143, 1:32, 1] 0.9279 0.8914 0.9227 0.8843 -0.0786 ... $ last_layer_delta : num [1:143, 1:32, 1] 0.06211 0.08631 0.06582 0.09048 -0.00569 ... $ store :List of 2 ..$ : num [1:143, 1:32, 1:5] 0.5 0.529 0.5 0.525 0.5 ... ..$ : num [1:143, 1:32, 1] 0.0721 0.1086 0.0773 0.1157 0.0786 ... $ time_synapse :List of 2 ..$ : num [1:4, 1:5] -0.5844 0.1364 0.0783 0.2251 0.8466 ... ..$ : num [1:5, 1] -0.854 -0.669 -1.231 -1.201 -1.055 $ recurrent_synapse :List of 1 ..$ : num [1:5, 1:5] 0.853 0.194 1.079 0.848 -0.734 ... $ bias_synapse :List of 2 ..$ : num [1:5] -0.085244 -0.038063 0.043454 0.000909 -0.0694 ..$ : num -0.352 $ time_synapse_update :List of 2 ..$ : num [1:4, 1:5] 0 0 0 0 0 0 0 0 0 0 ... ..$ : num [1:5, 1] 0 0 0 0 0 $ bias_synapse_update :List of 2 ..$ : num [1:5] 0 0 0 0 0 ..$ : num 0 $ recurrent_synapse_update:List of 1 ..$ : num [1:5, 1:5] 0 0 0 0 0 0 0 0 0 0 ... $ error : num [1:143, 1] 1.88 1.78 2.23 1.84 1.02 ... $ current_epoch : int 1 $ store_best :List of 2 ..$ : num [1:143, 1:32, 1:5] 0.5 0.529 0.5 0.525 0.5 ... ..$ : num [1:143, 1:32, 1] 0.0721 0.1086 0.0773 0.1157 0.0786 ...
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.
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.
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.