For the complete documentation index, see llms.txt. This page is also available as Markdown.

Cheat Sheet

Quick reference cheat sheet for Deeplearning4j — common configurations, layer types, and API patterns

Quick reference for the most common DL4J API patterns. Entries are organized by task.


Network Builder Patterns

MultiLayerNetwork (Sequential)

MultiLayerConfiguration conf = new NeuralNetConfiguration.Builder()
    .seed(123)
    .updater(new Adam(1e-3))
    .weightInit(WeightInit.XAVIER)
    .l2(1e-4)
    .list()
    .layer(new DenseLayer.Builder().nOut(256).activation(Activation.RELU).build())
    .layer(new DropoutLayer(0.5))
    .layer(new DenseLayer.Builder().nOut(128).activation(Activation.RELU).build())
    .layer(new OutputLayer.Builder(LossFunctions.LossFunction.MCXENT)
           .activation(Activation.SOFTMAX).nOut(10).build())
    .setInputType(InputType.feedForward(784))  // infers nIn automatically
    .build();

MultiLayerNetwork net = new MultiLayerNetwork(conf);
net.init();
net.setListeners(new ScoreIterationListener(10));

ComputationGraph (DAG)

Training Loop


Layer Quick Reference

Feed-Forward Layers

Layer
Key Config Options

DenseLayer

nIn, nOut, activation

EmbeddingLayer

nIn (vocab size), nOut (embedding dim) — input as integer index

EmbeddingSequenceLayer

same as Embedding but outputs 3D (sequence)

ActivationLayer

activation only — no weights

DropoutLayer

dropOut rate (fraction retained)

BatchNormalization

nIn, decay, eps

Output Layers

Layer
Use Case

OutputLayer

Multi-class or regression; has built-in dense connection

LossLayer

No weights; input size must equal output size

RnnOutputLayer

Time-series classification/regression (3D output)

CnnLossLayer

Per-pixel prediction (segmentation); no weights

Yolo2OutputLayer

Object detection

Convolutional Layers

Use .setInputType(InputType.convolutional(height, width, channels)) on the network builder to avoid manually setting nIn on conv layers.

Recurrent Layers

Layer
Notes

LSTM

Standard LSTM; supports CuDNN

GravesLSTM

LSTM with peephole connections; no CuDNN support

SimpleRnn

Vanilla RNN; rarely used for long sequences

Bidirectional

Wrapper around any RNN layer

LastTimeStep

Wrapper that extracts the last time step from a 3D RNN output

Utility Layers

Layer
Purpose

GlobalPoolingLayer

Collapses spatial or time dimensions (max, avg, sum)

LocalResponseNormalization

LRN for older CNN architectures

FrozenLayer

Wraps a layer and freezes its parameters (transfer learning)

ZeroPaddingLayer

Pad spatial dimensions with zeros

Graph Vertices (ComputationGraph Only)

Vertex
Purpose

ElementWiseVertex(Op.Add)

Element-wise addition (residual connections)

MergeVertex

Concatenate along channel/feature dimension

SubsetVertex

Extract a slice along dimension 1

ScaleVertex(scalar)

Multiply all activations by a constant

L2NormalizeVertex

Normalize each example to unit L2 norm

UnstackVertex

Split minibatch along batch dimension


Updater (Optimizer) Selection

Typical starting learning rates: 1e-3 for Adam/RMSProp, 1e-2 for Nesterovs/SGD.


Learning Rate Schedules

Pass any ISchedule as the learning rate argument to an updater:


Activation and Loss Pairings

Task
Output Activation
Loss Function

Multi-class classification

SOFTMAX

MCXENT or NEGATIVELOGLIKELIHOOD

Binary classification (single output)

SIGMOID

XENT

Multi-label classification

SIGMOID

XENT

Regression

IDENTITY

MSE

Regression (bounded 0–1)

SIGMOID

MSE

Autoencoder reconstruction

SIGMOID or IDENTITY

MSE or RECONSTRUCTION_CROSSENTROPY


Weight Initialization


Regularization


Data Pipeline

CSV Data

Image Data

Normalization

Save and restore normalizer with model:

MultiDataSet (Multiple Inputs/Outputs)


Evaluation

Classification

Regression

Binary Classification (ROC / AUC)

Multi-class ROC

ComputationGraph


Model Save and Load

Using ModelSerializer directly:

The model file is a ZIP archive. You can inspect its contents with any ZIP tool.


Transfer Learning


Training Listeners


Early Stopping


Useful ND4J Snippets


Common Import Packages

Last updated

Was this helpful?