public abstract class Encoder extends AbstractBlock
Encoder
is an abstract block that be can used as encoder in encoder-decoder architecture.
This abstraction, along with Decoder
, 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, parameterShapeCallbacks, version
Constructor and Description |
---|
Encoder(byte version,
Block block)
Constructs a new instance of
Encoder with the given block. |
Modifier and Type | Method and Description |
---|---|
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Applies the operating function of the block once.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
abstract NDList |
getStates(NDList encoderOutput)
Gets the state of the encoder from the given encoder output.
|
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, addParameter, addParameter, beforeInitialize, cast, clear, describeInput, getChildren, getDirectParameters, getParameters, getParameterShape, initialize, isInitialized, loadMetadata, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, forward, validateLayout
protected Block block
public Encoder(byte version, Block block)
Encoder
with the given block.version
- the version to use for parameter and metadata serializationblock
- the encoder blockpublic abstract NDList getStates(NDList encoderOutput)
encoderOutput
- an NDList
that contains the encoder outputpublic NDList forward(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
parameterStore
- 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 AbstractBlock
manager
- the manager to use for initializationdataType
- the requested data typeinputShapes
- the expected input shapes for this blockpublic Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
manager
- an NDManagerinputShapes
- the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os) throws java.io.IOException
saveParameters
in interface Block
saveParameters
in class AbstractBlock
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
loadParameters
in interface Block
loadParameters
in class AbstractBlock
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