Package ai.djl.nn.core
Class Embedding.DefaultEmbedding
- java.lang.Object
-
- ai.djl.nn.core.Embedding.DefaultEmbedding
-
- All Implemented Interfaces:
AbstractEmbedding<T>,AbstractIndexedEmbedding<T>
protected class Embedding.DefaultEmbedding extends java.lang.Object implements AbstractIndexedEmbedding<T>
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedDefaultEmbedding()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tdecode(byte[] byteArray)Decodes the given byte array into an object of input parameter type.NDArrayembed(NDManager manager, T[] items)Embeds an array of items.longembed(T item)Embeds an item.byte[]encode(T input)Encodes an object of input type into a byte array.booleanhasItem(T item)Returns whether an item is in the embedding.java.util.Optional<T>unembed(long index)Returns the item corresponding to the given index.
-
-
-
Method Detail
-
encode
public byte[] encode(T input) throws java.io.IOException
Encodes an object of input type into a byte array. This is used in saving and loading theEmbeddingobjects.- Specified by:
encodein interfaceAbstractIndexedEmbedding<T>- Parameters:
input- the input object to be encoded- Returns:
- the encoded byte array.
- Throws:
java.io.IOException- if there is an error while encoding
-
decode
public T decode(byte[] byteArray) throws java.io.IOException
Decodes the given byte array into an object of input parameter type.- Specified by:
decodein interfaceAbstractIndexedEmbedding<T>- Parameters:
byteArray- the byte array to be decoded- Returns:
- the decode object of input parameter type
- Throws:
java.io.IOException- if there was an error while decoding
-
hasItem
public boolean hasItem(T item)
Returns whether an item is in the embedding.- Specified by:
hasItemin interfaceAbstractEmbedding<T>- Parameters:
item- the item to test- Returns:
- true if the item is in the embedding
-
embed
public NDArray embed(NDManager manager, T[] items)
Embeds an array of items.- Specified by:
embedin interfaceAbstractEmbedding<T>- Parameters:
manager- the manager for the new embeddingsitems- the items to embed- Returns:
- the embedding
NDArrayof Shape(items.length, embeddingSize)
-
embed
public long embed(T item)
Embeds an item.- Specified by:
embedin interfaceAbstractIndexedEmbedding<T>- Parameters:
item- the item to embed- Returns:
- the index of the item in the embedding
-
unembed
public java.util.Optional<T> unembed(long index)
Returns the item corresponding to the given index.- Specified by:
unembedin interfaceAbstractIndexedEmbedding<T>- Parameters:
index- the index- Returns:
- the item corresponding to the given index
-
-