以下是参考官方文档实现一个模型的例子及说明
DL4J gives data scientists and developers tools to build a deep neural networks on a high level using concepts like layer
. It employs a builder pattern in order to build the neural net declaratively, as you can see in this (simplified) example:
MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder() .optimizationAlgo(OptimizationAlgorithm.STOCHASTIC_GRADIENT_DESCENT) .updater(new Nesterovs(learningRate, 0.9)) .list( new DenseLayer.Builder().nIn(numInputs).nOut(numHiddenNodes).activation("relu").build(), new OutputLayer.Builder(LossFunction.NEGATIVELOGLIKELIHOOD).activation("softmax").nIn(numHiddenNodes).nOut(numOutputs).build() ).backprop(true).build();
If you are familiar with other deep learning frameworks, you will notice that this looks a bit like Keras.
Unlike other frameworks, DL4J splits the optimization algorithm from the updater algorithm. This allows for flexibility as you seek a combination of optimizer and updater that works best for your data and problem.
Besides the DenseLayer and OutputLayer that you have seen in the example above, there are several other layer types, like GravesLSTM
, ConvolutionLayer
, RBM
, EmbeddingLayer
, etc. Using those layers you can define not only simple neural networks, but also recurrent and convolutional networks.