Package ai.djl.nn.transformer
Class TransformerEncoderBlock
java.lang.Object
ai.djl.nn.AbstractBaseBlock
ai.djl.nn.AbstractBlock
ai.djl.nn.transformer.TransformerEncoderBlock
- All Implemented Interfaces:
- Block
Self-Attention based transformer encoder block.
- 
Field SummaryFields inherited from class ai.djl.nn.AbstractBlockchildren, parametersFields inherited from class ai.djl.nn.AbstractBaseBlockinputNames, inputShapes, outputDataTypes, version
- 
Constructor SummaryConstructorsConstructorDescriptionTransformerEncoderBlock(int embeddingSize, int headCount, int hiddenSize, float dropoutProbability, Function<NDList, NDList> activationFunction) Creates a transformer encoder block.
- 
Method SummaryModifier and TypeMethodDescriptionprotected NDListforwardInternal(ParameterStore ps, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.Shape[]getOutputShapes(Shape[] inputShapes) Returns the expected output shapes of the block for the specified input shapes.voidinitializeChildBlocks(NDManager manager, DataType dataType, Shape... inputShapes) Initializes the Child blocks of this block.Methods inherited from class ai.djl.nn.AbstractBlockaddChildBlock, addChildBlock, addChildBlockSingleton, addParameter, getChildren, getDirectParametersMethods inherited from class ai.djl.nn.AbstractBaseBlockbeforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getInputShapes, getOutputDataTypes, getParameters, initialize, isInitialized, loadMetadata, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ai.djl.nn.Blockforward, freezeParameters, freezeParameters, getOutputShapes
- 
Constructor Details- 
TransformerEncoderBlockpublic TransformerEncoderBlock(int embeddingSize, int headCount, int hiddenSize, float dropoutProbability, Function<NDList, NDList> activationFunction) Creates a transformer encoder block.- Parameters:
- embeddingSize- the embedding size for tokens
- headCount- number of attention blocks
- hiddenSize- the hidden size for fully connected networks
- dropoutProbability- dropout probability
- activationFunction- activation function
 
 
- 
- 
Method Details- 
getOutputShapesReturns 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
 
- 
initializeChildBlocksInitializes 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:
- initializeChildBlocksin class- AbstractBaseBlock
- Parameters:
- manager- the manager to use for initialization
- dataType- the requested data type
- inputShapes- the expected input shapes for this block
 
- 
forwardInternalprotected NDList forwardInternal(ParameterStore ps, NDList inputs, boolean training, ai.djl.util.PairList<String, Object> params) A helper forBlock.forward(ParameterStore, NDList, boolean, PairList)after initialization.- Specified by:
- forwardInternalin class- AbstractBaseBlock
- Parameters:
- ps- the parameter store
- inputs- the input NDList
- training- true for a training forward pass
- params- optional parameters
- Returns:
- the output of the forward pass
 
 
-