Neural Network Model
Build neural networks using Morph's built-in NN module.
Model Structure
A neural network model is a class with a Forward method:
module NN;
Classifier class {
layer1 is NN.Linear(784, 128);
layer2 is NN.Linear(128, 10);
Forward method(input as Tensor<float>) as Tensor<float> {
x is NN.ReLU(layer1.Forward(input));
return NN.Softmax(layer2.Forward(x));
}
}
Creating a Model
model is Classifier();
output is model.Forward(inputData);
Module Import
module NN;
This provides access to layers, optimizers, activation functions, and the training API.
Self-Test
Verify the NN runtime is working:
module NN;
Init method() {
result is NN.SelfTest();
if (result == 1) {
Print("NN self-test passed.");
}
}