Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NN option noTraining is undocumented and buggy #1409

Open
lindapaiste opened this issue Jun 5, 2022 · 0 comments
Open

NN option noTraining is undocumented and buggy #1409

lindapaiste opened this issue Jun 5, 2022 · 0 comments

Comments

@lindapaiste
Copy link
Contributor

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.

createLayersNoTraining() {
// Create sample data based on options
const { inputs, outputs, task } = this.options;
if (task === 'classification') {
for (let i = 0; i < outputs.length; i += 1) {
const inputSample = new Array(inputs).fill(0);
this.addData(inputSample, [outputs[i]]);
}
} else {
const inputSample = new Array(inputs).fill(0);
const outputSample = new Array(outputs).fill(0);
this.addData(inputSample, outputSample);
}
this.neuralNetworkData.createMetadata(this.neuralNetworkData.data.raw);
this.addDefaultLayers(this.options.task, this.neuralNetworkData.meta);
}

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant