Class Decoder

All Implemented Interfaces:
Block

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.
  • Field Details

    • block

      protected Block block
  • Constructor Details

    • Decoder

      public Decoder(byte version, Block block)
      Constructs a new instance of Decoder with the given block. Use this constructor if you are planning to use pre-trained embeddings that don't need further training.
      Parameters:
      block - the block to be used to decode
      version - the version to use for parameter and metadata serialization
  • Method Details

    • forwardInternal

      protected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<String,Object> params)
      Specified by:
      forwardInternal in class AbstractBaseBlock
      Parameters:
      parameterStore - the parameter store
      inputs - the input NDList
      training - true for a training forward pass
      params - optional parameters
      Returns:
      the output of the forward pass
    • initializeChildBlocks

      public void initializeChildBlocks(NDManager manager, DataType dataType, Shape... inputShapes)
      Initializes the Child blocks of this block. You need to override this method if your subclass has child blocks. Used to determine the correct input shapes for child blocks based on the requested input shape for this block.
      Overrides:
      initializeChildBlocks in class AbstractBaseBlock
      Parameters:
      manager - the manager to use for initialization
      dataType - the requested data type
      inputShapes - the expected input shapes for this 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(DataOutputStream os) throws IOException
      Writes the parameters of the block to the given outputStream.
      Specified by:
      saveParameters in interface Block
      Overrides:
      saveParameters in class AbstractBaseBlock
      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:
      loadParameters in interface Block
      Overrides:
      loadParameters in class AbstractBaseBlock
      Parameters:
      manager - an NDManager to create the parameter arrays
      is - the inputstream that stream the parameter values
      Throws:
      IOException - if an I/O error occurs
      MalformedModelException - if the model file is corrupted or unsupported