Package ai.djl.nn.core
Class Embedding.DefaultItem
- java.lang.Object
-
- ai.djl.nn.core.Embedding.DefaultItem
-
- All Implemented Interfaces:
AbstractEmbedding<T>
,AbstractIndexedEmbedding<T>
protected class Embedding.DefaultItem extends java.lang.Object implements AbstractIndexedEmbedding<T>
-
-
Constructor Summary
Constructors Constructor Description DefaultItem(T defaultItem)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
decode(byte[] byteArray)
Decodes the given byte array into an object of input parameter type.NDArray
embed(NDManager manager, T[] items)
Embeds an array of items.long
embed(T item)
Embeds an item.byte[]
encode(T input)
Encodes an object of input type into a byte array.boolean
hasItem(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.
-
-
-
Constructor Detail
-
DefaultItem
public DefaultItem(T defaultItem)
-
-
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 theEmbedding
objects.- Specified by:
encode
in 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:
decode
in 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:
hasItem
in 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:
embed
in interfaceAbstractEmbedding<T>
- Parameters:
manager
- the manager for the new embeddingsitems
- the items to embed- Returns:
- the embedding
NDArray
of Shape(items.length, embeddingSize)
-
embed
public long embed(T item)
Embeds an item.- Specified by:
embed
in 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:
unembed
in interfaceAbstractIndexedEmbedding<T>
- Parameters:
index
- the index- Returns:
- the item corresponding to the given index
-
-