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
-
Field Summary
FieldsFields inherited from class ai.djl.nn.AbstractBlock
children, parametersFields inherited from class ai.djl.nn.AbstractBaseBlock
inputNames, inputShapes, outputDataTypes, version -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns aPairListof input names, and shapes.forward(ParameterStore parameterStore, NDList data, NDList labels, ai.djl.util.PairList<String, Object> params) A forward call using both training data and labels.protected NDListforwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, 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.voidinitialize(NDManager manager, DataType dataType, Shape... inputShapes) Initializes the parameters of the block.voidloadParameters(NDManager manager, DataInputStream is) Loads the parameters from the given input stream.voidWrites the parameters of the block to the given outputStream.Methods inherited from class ai.djl.nn.AbstractBlock
addChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParametersMethods inherited from class ai.djl.nn.AbstractBaseBlock
beforeInitialize, cast, clear, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initializeChildBlocks, isInitialized, loadMetadata, prepare, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, setInitializer, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.djl.nn.Block
forward, freezeParameters, freezeParameters, getOutputShapes
-
Field Details
-
encoder
-
decoder
-
-
Constructor Details
-
Method Details
-
describeInput
Returns aPairListof input names, and shapes.- Specified by:
describeInputin interfaceBlock- Overrides:
describeInputin classAbstractBaseBlock- Returns:
- the
PairListof input names, and shapes
-
forwardInternal
protected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.- Specified by:
forwardInternalin 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<String, 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:
forwardin interfaceBlock- Overrides:
forwardin 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:
-
initialize
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:
initializein interfaceBlock- Overrides:
initializein classAbstractBaseBlock- Parameters:
manager- the NDManager to initialize the parametersdataType- the datatype of the parametersinputShapes- the shapes of the inputs to the block
-
getOutputShapes
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
Writes the parameters of the block to the given outputStream.- Specified by:
saveParametersin interfaceBlock- Overrides:
saveParametersin classAbstractBaseBlock- Parameters:
os- the outputstream to save the parameters to- Throws:
IOException- if an I/O error occurs
-
loadParameters
public void loadParameters(NDManager manager, DataInputStream is) throws IOException, MalformedModelException Loads the parameters from the given input stream.- Specified by:
loadParametersin interfaceBlock- Overrides:
loadParametersin classAbstractBaseBlock- Parameters:
manager- an NDManager to create the parameter arraysis- the inputstream that stream the parameter values- Throws:
IOException- if an I/O error occursMalformedModelException- if the model file is corrupted or unsupported
-