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.inputNames, inputShapes| Constructor and Description |
|---|
TrainableTextEmbedding(TrainableWordEmbedding wordEmbedding)
Constructs a
SimpleTextEmbedding. |
| Modifier and Type | Method and Description |
|---|---|
NDArray |
embedText(NDManager manager,
int[] textIndices)
Embeds the text after preprocessed using
TextEmbedding.preprocessTextToEmbed(List). |
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Applies the operating function of the block once.
|
BlockList |
getChildren()
Returns a list of all the children of the block.
|
java.util.List<Parameter> |
getDirectParameters()
Returns a list of all the direct parameters of the block.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
Shape |
getParameterShape(java.lang.String name,
Shape[] inputShapes)
Returns the shape of the specified direct parameter of this block given the shapes of the
input to the block.
|
Shape[] |
initialize(NDManager manager,
DataType dataType,
Shape... inputShapes)
Initializes the parameters of the block.
|
void |
loadParameters(NDManager manager,
java.io.DataInputStream is)
Loads the parameters from the given input stream.
|
int[] |
preprocessTextToEmbed(java.util.List<java.lang.String> text)
Preprocesses the text to embed into an array to pass into the model.
|
void |
saveParameters(java.io.DataOutputStream os)
Writes the parameters of the block to the given outputStream.
|
java.util.List<java.lang.String> |
unembedText(NDArray textEmbedding)
Returns the closest matching text for a given embedding.
|
beforeInitialize, cast, clear, describeInput, getParameters, isInitialized, readInputShapes, saveInputShapes, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitembedTextforward, validateLayoutpublic TrainableTextEmbedding(TrainableWordEmbedding wordEmbedding)
SimpleTextEmbedding.wordEmbedding - the word embedding to embed each wordpublic int[] preprocessTextToEmbed(java.util.List<java.lang.String> text)
Make sure to call TextEmbedding.embedText(NDManager, int[]) after this.
preprocessTextToEmbed in interface TextEmbeddingtext - the text to embedpublic NDArray embedText(NDManager manager, int[] textIndices)
TextEmbedding.preprocessTextToEmbed(List).embedText in interface TextEmbeddingmanager - the manager to create the embedding arraytextIndices - the text 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.public NDList forward(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Blockpublic Shape[] initialize(NDManager manager, DataType dataType, Shape... inputShapes)
Blockinitialize in interface Blockmanager - the NDManager to initialize the parametersdataType - the datatype of the parametersinputShapes - the shapes of the inputs to the blockpublic BlockList getChildren()
BlockgetChildren in interface Blockpublic java.util.List<Parameter> getDirectParameters()
BlockgetDirectParameters in interface BlockParameterpublic Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
BlockgetParameterShape in interface Blockname - the name of the parameterinputShapes - the shapes of the input to the blockpublic Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
BlockgetOutputShapes in interface Blockmanager - an NDManagerinputShapes - the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
BlocksaveParameters in interface Blockos - the outputstream to save the parameters tojava.io.IOException - if an I/O error occurspublic void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
BlockloadParameters in interface Blockmanager - an NDManager to create the parameter arraysis - the inputstream that stream the parameter valuesjava.io.IOException - if an I/O error occursMalformedModelException - if the model file is corrupted or unsupported