public class BertMaskedLanguageModelBlock extends AbstractBlock
children, inputNames, inputShapes, parameters, parameterShapeCallbacks, 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 |
|---|---|
NDArray |
forward(ParameterStore ps,
NDArray sequenceOutput,
NDArray maskedIndices,
NDArray embeddingTable,
boolean training)
Calculates the result of the masked language task.
|
NDList |
forward(ParameterStore ps,
NDList inputs,
boolean training)
Applies the operating function of the block once.
|
protected NDList |
forwardInternal(ParameterStore ps,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params) |
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(NDManager manager,
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, addParameter, addParameter, beforeInitialize, cast, clear, describeInput, forward, getChildren, getDirectParameters, getParameters, getParameterShape, initialize, isInitialized, loadMetadata, loadParameters, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutpublic 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 AbstractBlockmanager - 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)
forwardInternal in class AbstractBlockpublic NDList forward(ParameterStore ps, NDList inputs, boolean training)
ps - the parameter storeinputs - the input NDListtraining - true for a training forward passpublic NDArray forward(ParameterStore ps, NDArray sequenceOutput, NDArray maskedIndices, NDArray embeddingTable, boolean training)
ps - the parameter storesequenceOutput - The sequence output of the bert model (B, S, E)maskedIndices - The indices of the tokens masked for pretraining (B, I)embeddingTable - The embedding table of the bert model (D, E)training - true=apply dropout etc.