public abstract class Decoder extends AbstractBlock
Decoder is an abstract block that be can used as decoder in encoder-decoder architecture.
This abstraction, along with Encoder, comes into play in the EncoderDecoder
class, and facilitate implementing encoder-decoder models for different tasks and inputs.| Modifier and Type | Field and Description |
|---|---|
protected Block |
block |
children, inputNames, inputShapes, parameters, version| Constructor and Description |
|---|
Decoder(byte version,
Block block)
Constructs a new instance of
Decoder with the given block. |
| Modifier and Type | Method and Description |
|---|---|
protected NDList |
forwardInternal(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper for
Block.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 |
initializeChildBlocks(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the Child blocks of this 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.
|
addChildBlock, addParameter, beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getChildren, getDirectParameters, getParameters, initialize, isInitialized, loadMetadata, prepare, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, setInitializer, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutprotected Block block
public Decoder(byte version,
Block block)
Decoder with the given block. Use this constructor if
you are planning to use pre-trained embeddings that don't need further training.block - the block to be used to decodeversion - the version to use for parameter and metadata serializationprotected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization.forwardInternal in class AbstractBlockparameterStore - the parameter storeinputs - the input NDListtraining - true for a training forward passparams - optional parameterspublic void initializeChildBlocks(NDManager manager, DataType dataType, Shape... inputShapes)
initializeChildBlocks in class AbstractBlockmanager - the manager to use for initializationdataType - the requested data typeinputShapes - the expected input shapes for this blockpublic Shape[] getOutputShapes(Shape[] inputShapes)
inputShapes - the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
saveParameters in interface BlocksaveParameters in class AbstractBlockos - 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
loadParameters in interface BlockloadParameters in class AbstractBlockmanager - 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