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 Detail

      • block

        protected Block block
    • Constructor Detail

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

      • 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