Package ai.djl.modality.nlp.embedding
Class ModelZooTextEmbedding
- java.lang.Object
-
- ai.djl.modality.nlp.embedding.ModelZooTextEmbedding
-
- All Implemented Interfaces:
TextEmbedding
,java.lang.AutoCloseable
public class ModelZooTextEmbedding extends java.lang.Object implements TextEmbedding, java.lang.AutoCloseable
AWordEmbedding
using aZooModel
.
-
-
Constructor Summary
Constructors Constructor Description ModelZooTextEmbedding(Model model)
Constructs aModelZooTextEmbedding
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
NDArray
embedText(NDArray indices)
Embeds the text after preprocessed usingTextEmbedding.preprocessTextToEmbed(List)
.long[]
preprocessTextToEmbed(java.util.List<java.lang.String> tokens)
Preprocesses the text to embed into an array to pass into the model.java.util.List<java.lang.String>
unembedText(NDArray word)
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
-
ModelZooTextEmbedding
public ModelZooTextEmbedding(Model model)
Constructs aModelZooTextEmbedding
.- Parameters:
model
- the model for the embedding. The model's block must consist of only anEmbedding
<String
>.
-
-
Method Detail
-
preprocessTextToEmbed
public long[] preprocessTextToEmbed(java.util.List<java.lang.String> tokens)
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:
preprocessTextToEmbed
in interfaceTextEmbedding
- Parameters:
tokens
- the text to embed- Returns:
- the indices of text that is ready to embed
-
embedText
public NDArray embedText(NDArray indices) throws EmbeddingException
Embeds the text after preprocessed usingTextEmbedding.preprocessTextToEmbed(List)
.- Specified by:
embedText
in interfaceTextEmbedding
- Parameters:
indices
- 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 word)
Returns the closest matching text for a given embedding.- Specified by:
unembedText
in interfaceTextEmbedding
- Parameters:
word
- the text embedding to find the matching string text for.- Returns:
- text similar to the passed in embedding
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
-
-