🧹 NeuralNetwork cleanup pt. 3 -- tasks #1410
Open
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
Introduces a level of abstraction for the "task" of the neural network:
getTask.tsNNTaskwhich specifies what information a task needs to provide:noTrainingis set.name(not currently not used, possible 🪓)classification,regression, andimageClassification.imageClassificationuses some of the same functions asclassification.getSampleDatais only possible in a limited set of circumstances (see issue NN optionnoTrainingis undocumented and buggy #1409), so I'm throwing a lot of specific errors when those circumstances aren't met.getTaskto convert astringtask name into aNNTaskobject.NeuralNetwork/index.tsthis.taskwith the task object based onoptions.task. This defaults toregressionwhich seems to match what was in the default layers before.addDefaultLayers()andcompile()which was moved into the task objects. Now we call a function onthis.task:const layers = this.task.createLayers(inputUnits, hiddenUnits, outputUnits);const options = this.task.getCompileOptions(this.options.learningRate);NeuralNetwork/NeuralNetwork.tsoptimizer.call(this, learningRate)to set thethisArgon the optimizer doesn't actually make a difference? (Please correct me if I am wrong). I removedsetOptimizerFunction(), which, despite the name, just creates an optimizer and doesn't set anything. The instantiation of the optimizer is handled in thegetCompileOptions()function of the task, which gets thelearningRateas an argument.