Class Encoder

  • All Implemented Interfaces:
    Block

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

      • block

        protected Block block
    • Constructor Detail

      • Encoder

        public Encoder​(byte version,
                       Block block)
        Constructs a new instance of Encoder with the given block.
        Parameters:
        version - the version to use for parameter and metadata serialization
        block - the encoder block
    • Method Detail

      • getStates

        public abstract NDList getStates​(NDList encoderOutput)
        Gets the state of the encoder from the given encoder output.
        Parameters:
        encoderOutput - an NDList that contains the encoder output
        Returns:
        the state of the encoder
      • 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​(java.io.DataOutputStream os)
                            throws java.io.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:
        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 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:
        java.io.IOException - if an I/O error occurs
        MalformedModelException - if the model file is corrupted or unsupported