public class GRU extends RecurrentCell
Reference paper - Gated Recurrent Unit - Cho et al. 2014. http://arxiv.org/abs/1406.1078. The definition of GRU here is slightly different from the paper but compatible with CUDNN.
$$ \begin{split}\begin{array}{ll} r_t = \mathrm{sigmoid}(W_{ir} x_t + b_{ir} + W_{hr} h_{(t-1)} + b_{hr}) \\ z_t = \mathrm{sigmoid}(W_{iz} x_t + b_{iz} + W_{hz} h_{(t-1)} + b_{hz}) \\ n_t = \tanh(W_{in} x_t + b_{in} + r_t * (W_{hn} h_{(t-1)}+ b_{hn})) \\ h_t = (1 - z_t) * n_t + z_t * h_{(t-1)} \\ \end{array}\end{split} $$
| Modifier and Type | Class and Description |
|---|---|
static class |
GRU.Builder
|
RecurrentCell.BaseBuilder<T extends RecurrentCell.BaseBuilder>dropRate, mode, numStackedLayers, stateOutputs, stateSize, useBidirectional, useSequenceLengthinputNames, inputShapes| Modifier and Type | Method and Description |
|---|---|
void |
beforeInitialize(Shape[] inputShapes)
Performs any action necessary before initialization.
|
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Applies the operating function of the block once.
|
java.util.List<Parameter> |
getDirectParameters()
Returns a list of all the direct parameters of the block.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputs)
Returns the expected output shapes of the block for the specified input shapes.
|
Shape |
getParameterShape(java.lang.String name,
Shape[] inputShapes)
Returns the shape of the specified direct parameter of this block given the shapes of the
input to the block.
|
void |
loadParameters(NDManager manager,
java.io.DataInputStream is)
Loads the parameters from the given input stream.
|
void |
saveParameters(java.io.DataOutputStream os)
Writes the parameters of the block to the given outputStream.
|
validateInputSizegetChildren, initialize, toStringcast, clear, describeInput, getParameters, isInitialized, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutpublic NDList forward(ParameterStore parameterStore, NDList inputs, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
parameterStore - the parameter storeinputs - the input NDListparams - optional parameterspublic Shape[] getOutputShapes(NDManager manager, Shape[] inputs)
manager - an NDManagerinputs - the shapes of the inputspublic java.util.List<Parameter> getDirectParameters()
Parameterpublic void beforeInitialize(Shape[] inputShapes)
beforeInitialize in class AbstractBlockinputShapes - the expected shapes of the inputpublic Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
name - the name of the parameterinputShapes - the shapes of the input to the blockpublic void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
os - the outputstream to save the parameters tojava.io.IOException - if an I/O error occurspublic void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
manager - an NDManager to create the parameter arraysis - the inputstream that stream the parameter valuesjava.io.IOException - if an I/O error occursMalformedModelException - if the model file is corrupted or unsupported