Deeplearning4j
Community ForumND4J JavadocDL4J Javadoc
EN 1.0.0-beta7
EN 1.0.0-beta7
  • Eclipse DeepLearning4J
  • Getting Started
    • Quickstart
      • Untitled
    • Tutorials
      • Quickstart with MNIST
      • MultiLayerNetwork And ComputationGraph
      • Logistic Regression
      • Built-in Data Iterators
      • Feed Forward Networks
      • Basic Autoencoder
      • Advanced Autoencoder
      • Convolutional Networks
      • Recurrent Networks
      • Early Stopping
      • Layers and Preprocessors
      • Hyperparameter Optimization
      • Using Multiple GPUs
      • Clinical Time Series LSTM
      • Sea Temperature Convolutional LSTM
      • Sea Temperature Convolutional LSTM 2
      • Instacart Multitask Example
      • Instacart Single Task Example
      • Cloud Detection Example
    • Core Concepts
    • Cheat Sheet
    • Examples Tour
    • Deep Learning Beginners
    • Build from Source
    • Contribute
      • Eclipse Contributors
    • Benchmark Guide
    • About
    • Release Notes
  • Configuration
    • Backends
      • CPU and AVX
      • cuDNN
      • Performance Issues
    • Memory Management
      • Memory Workspaces
    • Snapshots
    • Maven
    • SBT, Gradle, & Others
  • Models
    • Autoencoders
    • Multilayer Network
    • Computation Graph
    • Convolutional Neural Network
    • Recurrent Neural Network
    • Layers
    • Vertices
    • Iterators
    • Listeners
    • Custom Layers
    • Model Persistence
    • Activations
    • Updaters
  • Model Zoo
    • Overview
    • Zoo Models
  • ND4J
    • Overview
    • Quickstart
    • Basics
    • Elementwise Operations
    • Matrix Manipulation
    • Syntax
    • Tensors
  • SAMEDIFF
    • Importing TensorFlow models
    • Variables
    • Ops
    • Adding Ops
  • ND4J & SameDiff Ops
    • Overview
    • Bitwise
    • Linalg
    • Math
    • Random
    • BaseOps
    • CNN
    • Image
    • Loss
    • NN
    • RNN
  • Tuning & Training
    • Evaluation
    • Visualization
    • Trouble Shooting
    • Early Stopping
    • t-SNE Visualization
    • Transfer Learning
  • Keras Import
    • Overview
    • Get Started
    • Supported Features
      • Activations
      • Losses
      • Regularizers
      • Initializers
      • Constraints
      • Optimizers
    • Functional Model
    • Sequential Model
    • Custom Layers
    • API Reference
      • Core Layers
      • Convolutional Layers
      • Embedding Layers
      • Local Layers
      • Noise Layers
      • Normalization Layers
      • Pooling Layers
      • Recurrent Layers
      • Wrapper Layers
      • Advanced Activations
  • DISTRIBUTED DEEP LEARNING
    • Introduction/Getting Started
    • Technical Explanation
    • Spark Guide
    • Spark Data Pipelines Guide
    • API Reference
    • Parameter Server
  • Arbiter
    • Overview
    • Layer Spaces
    • Parameter Spaces
  • Datavec
    • Overview
    • Records
    • Reductions
    • Schema
    • Serialization
    • Transforms
    • Analysis
    • Readers
    • Conditions
    • Executors
    • Filters
    • Operations
    • Normalization
    • Visualization
  • Language Processing
    • Overview
    • Word2Vec
    • Doc2Vec
    • Sentence Iteration
    • Tokenization
    • Vocabulary Cache
  • Mobile (Android)
    • Setup
    • Tutorial: First Steps
    • Tutorial: Classifier
    • Tutorial: Image Classifier
    • FAQ
    • Press
    • Support
    • Why Deep Learning?
Powered by GitBook
On this page
  • Operation classes
  • gru
  • gruCell
  • lstmCell
  • lstmLayer
  • lstmblock
  • sru
  • sruCell
  • Configuration Classes
  • LSTMConfiguration
  • LSTMLayerConfig
  • GRUWeights
  • SRUWeights
  • LSTMWeights
  • LSTMLayerWeights

Was this helpful?

Edit on Git
Export as PDF
  1. ND4J & SameDiff Ops

RNN

Operation classes

gru

INDArray gru(INDArray x, INDArray hLast, INDArray Wx, INDArray Wh, INDArray biases)

SDVariable gru(SDVariable x, SDVariable hLast, SDVariable Wx, SDVariable Wh, SDVariable biases)
SDVariable gru(String name, SDVariable x, SDVariable hLast, SDVariable Wx, SDVariable Wh, SDVariable biases)

The GRU operation. Gated Recurrent Unit - Cho et al. 2014.

  • x (NUMERIC) - input [time, bS, nIn]

  • hLast (NUMERIC) - initial cell output (at time step = 0) [bS, nOut]

  • Wx (NUMERIC) - input-to-hidden weights, [nIn, 3*nOut]

  • Wh (NUMERIC) - hidden-to-hidden weights, [nOut, 3*nOut]

  • biases (NUMERIC) - biases, [3*nOut]

gruCell

INDArray[] gruCell(INDArray x, INDArray hLast, GRUWeights gRUWeights)

SDVariable[] gruCell(SDVariable x, SDVariable hLast, GRUWeights gRUWeights)
SDVariable[] gruCell(String name, SDVariable x, SDVariable hLast, GRUWeights gRUWeights)

The GRU cell. Does a single time step operation

  • x (NUMERIC) - Input, with shape [batchSize, inSize]

  • hLast (NUMERIC) - Output of the previous cell/time step, with shape [batchSize, numUnits]

lstmCell

INDArray[] lstmCell(INDArray x, INDArray cLast, INDArray yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)

SDVariable[] lstmCell(SDVariable x, SDVariable cLast, SDVariable yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)
SDVariable[] lstmCell(String name, SDVariable x, SDVariable cLast, SDVariable yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)

The LSTM cell. Does a single time step operation.

  • x (NUMERIC) - Input, with shape [batchSize, inSize]

  • cLast (NUMERIC) - Previous cell state, with shape [batchSize, numUnits]

  • yLast (NUMERIC) - revious cell output, with shape [batchSize, numUnits]

lstmLayer

INDArray[] lstmLayer(INDArray x, INDArray cLast, INDArray yLast, INDArray maxTSLength, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)
INDArray[] lstmLayer(INDArray x, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)

SDVariable[] lstmLayer(SDVariable x, SDVariable cLast, SDVariable yLast, SDVariable maxTSLength, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)
SDVariable[] lstmLayer(SDVariable x, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)
SDVariable[] lstmLayer(String name, SDVariable x, SDVariable cLast, SDVariable yLast, SDVariable maxTSLength, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)
SDVariable[] lstmLayer(String name, SDVariable x, LSTMLayerWeights lSTMLayerWeights, LSTMLayerConfig lSTMLayerConfig)

Long Short-Term Memory layer - Hochreiter 1997.

SUPPORTS following data formats:

for unidirectional:

TNS: shapes [timeLength, numExamples, inOutSize]

NST: shapes [numExamples, inOutSize, timeLength]

NTS: shapes [numExamples, timeLength, inOutSize]

for bidirectional:

T2NS: shapes [timeLength, 2, numExamples, inOutSize] (for ONNX)

SUPPORTS following direction modes:

FWD: forward

BWD: backward

BIDIR_SUM: bidirectional sum

BIDIR_CONCAT: bidirectional concat

BIDIR_EXTRA_DIM: bidirectional extra output dim (in conjunction with format dataFormat - T2NS)

You may use different gate configurations:

specify gate/cell/out aplha/beta and numbers of activations for gate/cell/out described in activations enum

("RELU","SIGMOID","AFFINE","LEAKY_RELU","THRESHHOLD_RELU","SCALED_TAHN","HARD_SIGMOID","ELU","SOFTSIGN","SOFTPLUS")

Also this layer supports MKLDNN (DNNL) and cuDNN acceleration

  • x (NUMERIC) - Input, with shape dependent on the data format (in config).

  • cLast (NUMERIC) - Previous/initial cell state, with shape [batchSize, numUnits]

  • yLast (NUMERIC) - Previous/initial cell output, with shape [batchSize, numUnits]

  • maxTSLength (NUMERIC) - maxTSLength with shape [batchSize]

lstmblock

INDArray lstmblock(INDArray maxTSLength, INDArray x, INDArray cLast, INDArray yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)
INDArray lstmblock(INDArray x, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)

SDVariable lstmblock(SDVariable maxTSLength, SDVariable x, SDVariable cLast, SDVariable yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)
SDVariable lstmblock(SDVariable x, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)
SDVariable lstmblock(String name, SDVariable maxTSLength, SDVariable x, SDVariable cLast, SDVariable yLast, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)
SDVariable lstmblock(String name, SDVariable x, LSTMWeights lSTMWeights, LSTMConfiguration lSTMConfiguration)

The LSTM block

  • maxTSLength (NUMERIC) -

  • x (NUMERIC) - Input, with shape dependent on the data format (in config).

  • cLast (NUMERIC) - Previous/initial cell state, with shape [batchSize, numUnits]

  • yLast (NUMERIC) - Previous/initial cell output, with shape [batchSize, numUnits]

sru

INDArray sru(INDArray x, INDArray initialC, INDArray mask, SRUWeights sRUWeights)
INDArray sru(INDArray x, INDArray initialC, SRUWeights sRUWeights)

SDVariable sru(SDVariable x, SDVariable initialC, SDVariable mask, SRUWeights sRUWeights)
SDVariable sru(SDVariable x, SDVariable initialC, SRUWeights sRUWeights)
SDVariable sru(String name, SDVariable x, SDVariable initialC, SDVariable mask, SRUWeights sRUWeights)
SDVariable sru(String name, SDVariable x, SDVariable initialC, SRUWeights sRUWeights)

The SRU layer. Does a single time step operation.

  • x (NUMERIC) - Input, with shape [batchSize, inSize]

  • initialC (NUMERIC) - Initial cell state, with shape [batchSize, inSize]

  • mask (NUMERIC) - An optional dropout mask, with shape [batchSize, inSize]

sruCell

INDArray sruCell(INDArray x, INDArray cLast, SRUWeights sRUWeights)

SDVariable sruCell(SDVariable x, SDVariable cLast, SRUWeights sRUWeights)
SDVariable sruCell(String name, SDVariable x, SDVariable cLast, SRUWeights sRUWeights)

The SRU layer. Does a single time step operation.

  • x (NUMERIC) - Input, with shape [batchSize, inSize]

  • cLast (NUMERIC) - Previous cell state, with shape [batchSize, inSize]

Configuration Classes

LSTMConfiguration

  • RnnDataFormat (ENUM) - The data format of the input. Input shape depends on data format (in config):

    TNS -> [timeSteps, batchSize, inSize]

    NST -> [batchSize, inSize, timeSteps]

    NTS -> [batchSize, timeSteps, inSize]

  • peepHole (BOOL) - Whether to provide peephole connections

  • forgetBias (NUMERIC) - The bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training.

  • clippingCellValue (NUMERIC) - The bias added to forget gates in order to reduce the scale of forgetting in the beginning of the training.

LSTMLayerConfig

  • LSTMDataFormat (ENUM) - for unidirectional: TNS: shape [timeLength, numExamples, inOutSize] - sometimes referred to as "time major"

    NST: shape [numExamples, inOutSize, timeLength]

    NTS: shape [numExamples, timeLength, inOutSize] - TF "time_major=false" layout for bidirectional:

    T2NS: 3 = [timeLength, 2, numExamples, inOutSize] (for ONNX)

  • LSTMDirectionMode (ENUM) - direction

    FWD: 0 = fwd

    BWD: 1 = bwd

    BIDIR_SUM: 2 = bidirectional sum

    BIDIR_CONCAT: 3 = bidirectional concat

    BIDIR_EXTRA_DIM: 4 = bidirectional extra output dim (in conjunction with format dataFormat = 3)

  • gateAct (ENUM) - Activations

  • cellAct (ENUM) - Activations

  • outAct (ENUM) - Activations

  • retFullSequence (BOOL) - indicates whether to return whole time sequence h {h_0, h_1, ... , h_sL-1} - default = true

  • retLastH (BOOL) - indicates whether to return output at last time step only,

    in this case shape would be [bS, nOut] (exact shape depends on dataFormat argument) - default = false

  • retLastC (BOOL) - indicates whether to return cells state at last time step only,

    in this case shape would be [bS, nOut] (exact shape depends on dataFormat argument) - default = false

  • cellClip (NUMERIC) - Cell clipping value, if it = 0 then do not apply clipping - default = 0.0

  • gateAlpha (NUMERIC) - null - default = 0.0

  • gateBeta (NUMERIC) - null - default = 0.0

  • cellAlpha (NUMERIC) - null - default = 0.0

  • cellBeta (NUMERIC) - null - default = 0.0

  • outAlpha (NUMERIC) - null - default = 0.0

  • outBeta (NUMERIC) - null - default = 0.0

GRUWeights

  • ruWeight- null (NUMERIC type)

  • cWeight- null (NUMERIC type)

  • ruBias- null (NUMERIC type)

  • cBias- null (NUMERIC type)

SRUWeights

  • weights- null (NUMERIC type)

  • bias- null (NUMERIC type)

LSTMWeights

  • ruWeight- null (NUMERIC type)

  • inputPeepholeWeights- null (NUMERIC type)

  • forgetPeepholeWeights- null (NUMERIC type)

  • outputPeepholeWeights- null (NUMERIC type)

  • bias- null (NUMERIC type)

LSTMLayerWeights

  • inputWeights- input weights Wx:

    1) shapes [nIn, 4*nOut] for FWD,BWD 2) shapes [2, nIn, 4*nOut] BIDIR_SUM, BIDIR_CONCAT and BIDIR_EXTRA_DIM (NUMERIC type)

  • recurrentWeights- recurrent weights Wr:

    1) shapes [nIn, 4*nOut] for FWD, BWD 2) shapes [2, nIn, 4*nOut] BIDIR_SUM, BIDIR_CONCAT and BIDIR_EXTRA_DIM (NUMERIC type)

  • biases- biases

    1) shapes [4*nOut] for FWD, BWD 2) shapes [2, 4*nOut] for BIDIR_SUM, BIDIR_CONCAT and BIDIR_EXTRA_DIM (NUMERIC type)

  • peepholeWeights- peephole weights Wp:

    1) [3*nOut] when directionMode < 2

    2) [2, 3*nOut] when directionMode >= 2 (NUMERIC type)

PreviousNNNextEvaluation

Last updated 5 years ago

Was this helpful?

GRUWeights - see

LSTMWeights - see

LSTMConfiguration - see

LSTMLayerWeights - see

LSTMLayerConfig - see

LSTMWeights - see

LSTMConfiguration - see

SRUWeights - see

SRUWeights - see

Used in these ops:

Used in these ops:

Used in these ops:

Used in these ops:

Used in these ops:

Used in these ops:

GRUWeights
LSTMWeights
LSTMConfiguration
LSTMLayerWeights
LSTMLayerConfig
LSTMWeights
LSTMConfiguration
SRUWeights
SRUWeights
lstmCell
lstmblock
lstmLayer
gruCell
sru
sruCell
lstmCell
lstmblock
lstmLayer