public class TrainableTextEmbedding extends AbstractBlock implements TextEmbedding
TrainableTextEmbedding is an implementation of TextEmbedding based on TrainableWordEmbedding block. This TextEmbedding is ideal when there are no pre-trained
embeddings available, or when the pre-trained embedding needs to be further trained.children, inputNames, inputShapes, parameters, version| Constructor and Description |
|---|
TrainableTextEmbedding(TrainableWordEmbedding wordEmbedding)
Constructs a
TrainableTextEmbedding. |
| Modifier and Type | Method and Description |
|---|---|
NDArray |
embedText(NDArray textIndices)
Embeds the text after preprocessed using
TextEmbedding.preprocessTextToEmbed(List). |
protected NDList |
forwardInternal(ParameterStore parameterStore,
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. |
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.
|
long[] |
preprocessTextToEmbed(java.util.List<java.lang.String> text)
Preprocesses the text to embed into an array to pass into the model.
|
java.util.List<java.lang.String> |
unembedText(NDArray textEmbedding)
Returns the closest matching text for a given embedding.
|
addChildBlock, addParameter, beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getChildren, getDirectParameters, getParameters, initialize, isInitialized, loadMetadata, loadParameters, prepare, readInputShapes, saveInputShapes, saveMetadata, saveParameters, setInitializer, setInitializer, setInitializer, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitembedText, embedTextforward, validateLayoutpublic TrainableTextEmbedding(TrainableWordEmbedding wordEmbedding)
TrainableTextEmbedding.wordEmbedding - the word embedding to embed each wordpublic long[] preprocessTextToEmbed(java.util.List<java.lang.String> text)
Make sure to call TextEmbedding.embedText(NDManager, long[]) after this.
preprocessTextToEmbed in interface TextEmbeddingtext - the text to embedpublic NDArray embedText(NDArray textIndices) throws EmbeddingException
TextEmbedding.preprocessTextToEmbed(List).embedText in interface TextEmbeddingtextIndices - the indices of text to embedEmbeddingException - if there is an error while trying to embedpublic java.util.List<java.lang.String> unembedText(NDArray textEmbedding)
unembedText in interface TextEmbeddingtextEmbedding - the text embedding to find the matching string text for.protected NDList forwardInternal(ParameterStore parameterStore, 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 AbstractBlockparameterStore - the parameter storeinputs - the input NDListtraining - true for a training forward passparams - optional parameterspublic 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 blockpublic Shape[] getOutputShapes(Shape[] inputShapes)
getOutputShapes in interface BlockinputShapes - the shapes of the inputs