public interface TextEmbedding
NDArray
representations of multiple words.
A text embedding differs from a WordEmbedding
because
the text embedding does not have to be applied to each word independently.
A text embedding maps text to a NDArray
that attempts to represent the key ideas in
the words. Each of the values in the dimension can represent different pieces of meaning such as
young-old, object-living, etc.
These text embeddings can be used in two different ways in models. First, they can be used
purely for preprocessing the model. In this case, it is a requirement for most models that use
text as an input. The model is not trained. For this use case, use embedText(ai.djl.ndarray.NDManager, java.util.List<java.lang.String>)
.
In the second option, the embedding can be trained using the standard deep learning techniques
to better handle the current dataset. For this case, you need two methods. First, call preprocessTextToEmbed(List)
within your dataset. Then, the first step in your model should be
to call embedText(NDManager, long[])
.
Modifier and Type | Method and Description |
---|---|
NDArray |
embedText(NDArray textIndices)
Embeds the text after preprocessed using
preprocessTextToEmbed(List) . |
default NDArray |
embedText(NDManager manager,
java.util.List<java.lang.String> text)
Embeds a text.
|
default NDArray |
embedText(NDManager manager,
long[] textIndices)
Embeds the text after preprocessed using
preprocessTextToEmbed(List) . |
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.
|
long[] preprocessTextToEmbed(java.util.List<java.lang.String> text)
Make sure to call embedText(NDManager, long[])
after this.
text
- the text to embeddefault NDArray embedText(NDManager manager, java.util.List<java.lang.String> text) throws EmbeddingException
manager
- the manager for the embedding arraytext
- the text to embedEmbeddingException
- if there is an error while trying to embeddefault NDArray embedText(NDManager manager, long[] textIndices) throws EmbeddingException
preprocessTextToEmbed(List)
.manager
- the manager to create the embedding arraytextIndices
- the indices of text to embedEmbeddingException
- if there is an error while trying to embedNDArray embedText(NDArray textIndices) throws EmbeddingException
preprocessTextToEmbed(List)
.textIndices
- the indices of text to embedEmbeddingException
- if there is an error while trying to embedjava.util.List<java.lang.String> unembedText(NDArray textEmbedding) throws EmbeddingException
textEmbedding
- the text embedding to find the matching string text for.EmbeddingException
- if the input is not unembeddable