Package ai.djl.modality.nlp.embedding
Class SimpleTextEmbedding
- java.lang.Object
-
- ai.djl.modality.nlp.embedding.SimpleTextEmbedding
-
- All Implemented Interfaces:
TextEmbedding
public class SimpleTextEmbedding extends java.lang.Object implements TextEmbedding
ATextEmbeddingthat applies aWordEmbeddingto each word independently.
-
-
Constructor Summary
Constructors Constructor Description SimpleTextEmbedding(WordEmbedding wordEmbedding)Constructs aSimpleTextEmbedding.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description NDArrayembedText(NDArray textIndices)Embeds the text after preprocessed usingTextEmbedding.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.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface ai.djl.modality.nlp.embedding.TextEmbedding
embedText, embedText
-
-
-
-
Constructor Detail
-
SimpleTextEmbedding
public SimpleTextEmbedding(WordEmbedding wordEmbedding)
Constructs aSimpleTextEmbedding.- Parameters:
wordEmbedding- the word embedding to embed each word
-
-
Method Detail
-
preprocessTextToEmbed
public long[] preprocessTextToEmbed(java.util.List<java.lang.String> text)
Preprocesses the text to embed into an array to pass into the model.Make sure to call
TextEmbedding.embedText(NDManager, long[])after this.- Specified by:
preprocessTextToEmbedin interfaceTextEmbedding- Parameters:
text- the text to embed- Returns:
- the indices of text that is ready to embed
-
embedText
public NDArray embedText(NDArray textIndices) throws EmbeddingException
Embeds the text after preprocessed usingTextEmbedding.preprocessTextToEmbed(List).- Specified by:
embedTextin interfaceTextEmbedding- Parameters:
textIndices- the indices of text to embed- Returns:
- the embedded text
- Throws:
EmbeddingException- if there is an error while trying to embed
-
unembedText
public java.util.List<java.lang.String> unembedText(NDArray textEmbedding)
Returns the closest matching text for a given embedding.- Specified by:
unembedTextin interfaceTextEmbedding- Parameters:
textEmbedding- the text embedding to find the matching string text for.- Returns:
- text similar to the passed in embedding
-
-