Class Embedding.BaseBuilder<T,B extends Embedding.BaseBuilder<T,B>>

java.lang.Object
ai.djl.nn.core.Embedding.BaseBuilder<T,B>
Type Parameters:
T - the type of object to embed
Direct Known Subclasses:
TrainableWordEmbedding.Builder
Enclosing class:
Embedding<T>

public abstract static class Embedding.BaseBuilder<T,B extends Embedding.BaseBuilder<T,B>> extends Object
The Builder to construct a Embedding type of Block.
  • Field Details

    • embeddingType

      protected Class<T> embeddingType
    • numEmbeddings

      protected int numEmbeddings
    • embeddingSize

      protected int embeddingSize
    • useDefault

      protected boolean useDefault
    • defaultItem

      protected T defaultItem
    • fallthrough

      protected AbstractIndexedEmbedding<T> fallthrough
    • sparseFormat

      protected SparseFormat sparseFormat
  • Constructor Details

    • BaseBuilder

      protected BaseBuilder()
  • Method Details

    • getEmbeddingType

      public Class<T> getEmbeddingType()
      Returns the embedded type.
      Returns:
      the embedded type
    • setType

      protected abstract B setType(Class<T> embeddingType)
      Creates a new Embedding.BaseBuilder with the specified embedding type.
      Parameters:
      embeddingType - the embedding class
      Returns:
      a new Embedding.BaseBuilder class with the specified embedding type
    • setEmbeddingSize

      public B setEmbeddingSize(int embeddingSize)
      Sets the size of the embeddings.
      Parameters:
      embeddingSize - the size of the 1D embedding array
      Returns:
      this Builder
    • optNumEmbeddings

      public B optNumEmbeddings(int numEmbeddings)
      Sets the size of the dictionary of embeddings.
      Parameters:
      numEmbeddings - the size of the dictionary of embeddings
      Returns:
      this Builder
    • optUseDefault

      public B optUseDefault(boolean useDefault)
      Sets whether to use a default embedding for undefined items (default true).
      Parameters:
      useDefault - true to provide a default embedding and false to throw an IllegalArgumentException when the item can not be found
      Returns:
      this Builder
    • optDefaultItem

      public B optDefaultItem(T defaultItem)
      Sets whether to use a default item's embedding for undefined items.
      Parameters:
      defaultItem - the item to use as a default.
      Returns:
      this Builder
    • optFallthrough

      public B optFallthrough(AbstractIndexedEmbedding<T> fallthrough)
      Sets a custom handler for items not found in the embedding.

      See the standard fallthrough handlers optUseDefault(boolean) and optDefaultItem(Object).

      Parameters:
      fallthrough - the embedding to handle default cases.
      Returns:
      this Builder
    • optSparseFormat

      public B optSparseFormat(SparseFormat sparseFormat)
      Sets the optional parameter whether to compute row sparse gradient in the backward calculation. If set to True, the grad’s storage type is row_sparse.
      Parameters:
      sparseFormat - whether to compute row sparse gradient in the backward calculation
      Returns:
      this Builder
    • self

      protected abstract B self()
      Returns this {code Builder} object.
      Returns:
      this BaseBuilder