From what I understand, one of the big things to avoid in julia is to have stuff be in the global scope (at least unless they are declared constant).
In addition I don’t understand how i’m supposed to have several “instances” of the same model.
e.g. I want to build an encoder decoder RNN, and I have the following code layout inspired by the Flux docs:
@with_kw struct EncoderDecoder encoder = LSTM(2,10) decoder = Chain(LSTM(3,10),LSTM(10,10),Dense(10,3)) end Flux.@functor(EncoderDecoder) model = EncoderDecoder() function loss(enc_in,ys) encoder = model.encoder decoder = model.decoder [loss stuff...] return loss end function predict(enc_in) encoder = model.encoder decoder = model.decoder [predict stuff...] end
I did get the model to train and predict with this code, but say I now want two models model1::EncoderDecoder and model2::EncoderDecoder so I can train them with different learning parameters and then compare their performance. This would be impossible with the code above as all the relevant functions use the model that was declared in the beginning. Am I missing something?