Mutating arrays not supported toy problem

Hi Christopher!

I’m not sure what you want to achieve with this new prediction function, but there is a slight problem. Not only does predict ignore the values of W and b, it actually creates a new (randomly initialized) dense layer at each call. Which means you cannot learn the parameters because they keep changing :scream:

I suspect this is also the root of your mutation problem, because params(predict(x)) keeps being modified during each call to predict.

In Flux, the way to correct this would be to define the model outside of the prediction function. But since layers are callable, the syntax is actually very easy

predict = Dense(5, 2)

Note that it is very different from

predict(x) = Dense(5, 2)(x)

because in the second one, a new Dense(5, 2) object is created for each x.

Does that answer you question?

1 Like