public class BertMaskedLanguageModelBlock extends AbstractBlock
children, inputNames, inputShapes, parameters, version
Constructor and Description |
---|
BertMaskedLanguageModelBlock(BertBlock bertBlock,
java.util.function.Function<NDArray,NDArray> hiddenActivation)
Creates a new block that applies the masked language task.
|
Modifier and Type | Method and Description |
---|---|
protected NDList |
forwardInternal(ParameterStore ps,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper for
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization. |
static NDArray |
gatherFromIndices(NDArray sequences,
NDArray indices)
Given a 3D array of shape (B, S, E) and a 2D array of shape (B, I) returns the flattened
lookup result of shape (B * I * E).
|
Shape[] |
getOutputShapes(Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
void |
initializeChildBlocks(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the Child blocks of this block.
|
addChildBlock, addParameter, beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getChildren, getDirectParameters, getParameters, initialize, isInitialized, loadMetadata, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, validateLayout
public BertMaskedLanguageModelBlock(BertBlock bertBlock, java.util.function.Function<NDArray,NDArray> hiddenActivation)
bertBlock
- the bert block to create the task forhiddenActivation
- the activation to use for the hidden layerpublic static NDArray gatherFromIndices(NDArray sequences, NDArray indices)
sequences
- Sequences of embeddingsindices
- Indices into the sequences. The indices are relative within each sequence,
i.e. [[0, 1],[0, 1]] would return the first two elements of two sequences.public 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 blockprotected NDList forwardInternal(ParameterStore ps, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Block.forward(ParameterStore, NDList, boolean, PairList)
after
initialization.forwardInternal
in class AbstractBlock
ps
- the parameter storeinputs
- the input NDListtraining
- true for a training forward passparams
- optional parameters