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

🧹 NeuralNetwork cleanup pt. 3 -- tasks #1410

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

lindapaiste
Copy link
Contributor

Introduces a level of abstraction for the "task" of the neural network:

getTask.ts

  • Define an interface NNTask which specifies what information a task needs to provide:
    • Its default layers.
    • Its compile options.
    • Any overrides to the NN default options.
    • How to create sample data to use when option noTraining is set.
    • Its name (not currently not used, possible 🪓)
  • Create three concrete implementations of that interface for the three tasks: classification, regression, and imageClassification.
    • imageClassification uses some of the same functions as classification.
    • getSampleData is only possible in a limited set of circumstances (see issue NN option noTraining is undocumented and buggy #1409), so I'm throwing a lot of specific errors when those circumstances aren't met.
  • Export a function getTask to convert a string task name into a NNTask object.

NeuralNetwork/index.ts

  • Constructor sets an instance property this.task with the task object based on options.task. This defaults to regression which seems to match what was in the default layers before.
  • Remove large blocks of code in addDefaultLayers() and compile() which was moved into the task objects. Now we call a function on this.task:
    • const layers = this.task.createLayers(inputUnits, hiddenUnits, outputUnits);
    • const options = this.task.getCompileOptions(this.options.learningRate);

NeuralNetwork/NeuralNetwork.ts

  • I'm like 99% sure that using optimizer.call(this, learningRate) to set the thisArg on the optimizer doesn't actually make a difference? (Please correct me if I am wrong). I removed setOptimizerFunction(), which, despite the name, just creates an optimizer and doesn't set anything. The instantiation of the optimizer is handled in the getCompileOptions() function of the task, which gets the learningRate as an argument.

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

Successfully merging this pull request may close these issues.

1 participant