Package ai.djl.nn.core
Interface AbstractIndexedEmbedding<T>
-
- Type Parameters:
T
- the type of the item that should be embedded
- All Superinterfaces:
AbstractEmbedding<T>
- All Known Implementing Classes:
ConstantEmbedding
,Embedding
,Embedding.DefaultEmbedding
,Embedding.DefaultItem
,TrainableWordEmbedding
public interface AbstractIndexedEmbedding<T> extends AbstractEmbedding<T>
AnAbstractEmbedding
where each embedded item can be assigned an integer index.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description T
decode(byte[] byteArray)
Decodes the given byte array into an object of input parameter type.long
embed(T item)
Embeds an item.byte[]
encode(T input)
Encodes an object of input type into a byte array.java.util.Optional<T>
unembed(long index)
Returns the item corresponding to the given index.-
Methods inherited from interface ai.djl.nn.core.AbstractEmbedding
embed, hasItem
-
-
-
-
Method Detail
-
encode
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 theEmbedding
objects.- 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
T decode(byte[] byteArray) throws java.io.IOException
Decodes the given byte array into an object of input parameter type.- 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
-
embed
long embed(T item)
Embeds an item.- Parameters:
item
- the item to embed- Returns:
- the index of the item in the embedding
-
unembed
java.util.Optional<T> unembed(long index)
Returns the item corresponding to the given index.- Parameters:
index
- the index- Returns:
- the item corresponding to the given index
-
-