Package ai.djl.modality.nlp
Class EncoderDecoder
- java.lang.Object
-
- ai.djl.nn.AbstractBaseBlock
-
- ai.djl.nn.AbstractBlock
-
- ai.djl.modality.nlp.EncoderDecoder
-
- All Implemented Interfaces:
Block
public class EncoderDecoder extends AbstractBlock
-
-
Field Summary
Fields Modifier and Type Field Description protected Decoder
decoder
protected Encoder
encoder
-
Fields inherited from class ai.djl.nn.AbstractBlock
children, parameters
-
Fields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, version
-
-
Constructor Summary
Constructors Constructor Description EncoderDecoder(Encoder encoder, Decoder decoder)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ai.djl.util.PairList<java.lang.String,Shape>
describeInput()
Returns aPairList
of input names, and shapes.NDList
forward(ParameterStore parameterStore, NDList data, NDList labels, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A forward call using both training data and labels.protected NDList
forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)
after initialization.Shape[]
getOutputShapes(Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.void
initialize(NDManager manager, DataType dataType, Shape... inputShapes)
Initializes the parameters of 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.-
Methods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addParameter, getChildren, getDirectParameters
-
Methods inherited from class ai.djl.nn.AbstractBaseBlock
beforeInitialize, cast, clear, forward, forwardInternal, getParameters, initializeChildBlocks, isInitialized, loadMetadata, prepare, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, setInitializer, toString
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ai.djl.nn.Block
forward, freezeParameters
-
-
-
-
Method Detail
-
describeInput
public ai.djl.util.PairList<java.lang.String,Shape> describeInput()
Returns aPairList
of input names, and shapes.- Specified by:
describeInput
in interfaceBlock
- Overrides:
describeInput
in classAbstractBaseBlock
- Returns:
- the
PairList
of input names, and shapes
-
forwardInternal
protected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)
after initialization.- Specified by:
forwardInternal
in classAbstractBaseBlock
- Parameters:
parameterStore
- the parameter storeinputs
- the input NDListtraining
- true for a training forward passparams
- optional parameters- Returns:
- the output of the forward pass
-
forward
public NDList forward(ParameterStore parameterStore, NDList data, NDList labels, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A forward call using both training data and labels.Within this forward call, it can be assumed that training is true.
- Specified by:
forward
in interfaceBlock
- Overrides:
forward
in classAbstractBaseBlock
- Parameters:
parameterStore
- the parameter storedata
- the input data NDListlabels
- the input labels NDListparams
- optional parameters- Returns:
- the output of the forward pass
- See Also:
Block.forward(ParameterStore, NDList, boolean, PairList)
-
initialize
public void initialize(NDManager manager, DataType dataType, Shape... inputShapes)
Initializes the parameters of the block. This method must be called before calling `forward`.This method assumes that inputShapes contains encoder and decoder inputs in index 0 and 1 respectively.
- Specified by:
initialize
in interfaceBlock
- Overrides:
initialize
in classAbstractBaseBlock
- Parameters:
manager
- the NDManager to initialize the parametersdataType
- the datatype of the parametersinputShapes
- the shapes of the inputs to the block
-
getOutputShapes
public Shape[] getOutputShapes(Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.- Parameters:
inputShapes
- the shapes of the inputs- Returns:
- the expected output shapes of the block
-
saveParameters
public void saveParameters(java.io.DataOutputStream os) throws java.io.IOException
Writes the parameters of the block to the given outputStream.- Specified by:
saveParameters
in interfaceBlock
- Overrides:
saveParameters
in classAbstractBaseBlock
- Parameters:
os
- the outputstream to save the parameters to- Throws:
java.io.IOException
- if an I/O error occurs
-
loadParameters
public void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
Loads the parameters from the given input stream.- Specified by:
loadParameters
in interfaceBlock
- Overrides:
loadParameters
in classAbstractBaseBlock
- Parameters:
manager
- an NDManager to create the parameter arraysis
- the inputstream that stream the parameter values- Throws:
java.io.IOException
- if an I/O error occursMalformedModelException
- if the model file is corrupted or unsupported
-
-