ml5-library
ml5-library copied to clipboard
NN option `noTraining` is undocumented and buggy
The NeuralNetwork supports a noTraining
option which is used in some of the NeuroEvolution examples to initialize a "brain" with dummy weights. This option does not appear anywhere in our documentation.
https://github.com/ml5js/ml5-library/blob/2c5cd1e9901d1d30ea592de01ca6ea28369888cb/src/NeuralNetwork/index.js#L128-L144
The implementation is very buggy as it relies on a lot of assumptions. It assumes that outputs
will be an array
if task === 'classification'
and uses outputs[i]
. That is not a valid assumption because we also support using a number
representing the number of classes. This will break:
const nn = ml5.neuralNetwork({
inputs: 3,
outputs: 2,
task: 'classification',
noTraining: true
});
It also assumes that the length of this output array will determine the output shape. Therefore it breaks if outputs
is an array of property names, like outputs: ['labels']
. I suspect that it is impossible to support a no-data approach in this situation because the shape of the output layer depends on the number of classes, and we wouldn't know the number of classes until there is data.
At the very least we should figure out when it does and doesn't work and put that in our documentation, like "if using noTraining
for a classification task, outputs
must be an array of class names."
If task !== 'classification'
then the code uses new Array(outputs).fill(0)
with I interpret as assuming that outputs
is a number
but I don't even know. Something like new Array([1,2,3]).fill(0)
is valid and returns [0]
.
It would make more sense to look at typeof outputs
or Array.isArray(outputs)
rather than assuming the shape based on the task.