Class Embedding.DefaultItem

java.lang.Object
ai.djl.nn.core.Embedding.DefaultItem
All Implemented Interfaces:
AbstractEmbedding<T>, AbstractIndexedEmbedding<T>
Enclosing class:
Embedding<T>

protected class Embedding.DefaultItem extends Object implements AbstractIndexedEmbedding<T>
  • Constructor Details

    • DefaultItem

      public DefaultItem(T defaultItem)
  • Method Details

    • encode

      public byte[] encode(T input) throws IOException
      Encodes an object of input type into a byte array. This is used in saving and loading the Embedding objects.
      Specified by:
      encode in interface AbstractIndexedEmbedding<T>
      Parameters:
      input - the input object to be encoded
      Returns:
      the encoded byte array.
      Throws:
      IOException - if there is an error while encoding
    • decode

      public T decode(byte[] byteArray) throws IOException
      Decodes the given byte array into an object of input parameter type.
      Specified by:
      decode in interface AbstractIndexedEmbedding<T>
      Parameters:
      byteArray - the byte array to be decoded
      Returns:
      the decode object of input parameter type
      Throws:
      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 interface AbstractEmbedding<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 interface AbstractEmbedding<T>
      Parameters:
      manager - the manager for the new embeddings
      items - 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 interface AbstractIndexedEmbedding<T>
      Parameters:
      item - the item to embed
      Returns:
      the index of the item in the embedding
    • unembed

      public Optional<T> unembed(long index)
      Returns the item corresponding to the given index.
      Specified by:
      unembed in interface AbstractIndexedEmbedding<T>
      Parameters:
      index - the index
      Returns:
      the item corresponding to the given index