Package ai.djl.nn.core
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
public abstract static class Embedding.BaseBuilder<T,B extends Embedding.BaseBuilder<T,B>>
extends Object
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected T
protected int
protected AbstractIndexedEmbedding<T>
protected int
protected SparseFormat
protected boolean
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the embedded type.optDefaultItem
(T defaultItem) Sets whether to use a default item's embedding for undefined items.optFallthrough
(AbstractIndexedEmbedding<T> fallthrough) Sets a custom handler for items not found in the embedding.optNumEmbeddings
(int numEmbeddings) Sets the size of the dictionary of embeddings.optSparseFormat
(SparseFormat sparseFormat) Sets the optional parameter whether to compute row sparse gradient in the backward calculation.optUseDefault
(boolean useDefault) Sets whether to use a default embedding for undefined items (default true).protected abstract B
self()
Returns this {code Builder} object.setEmbeddingSize
(int embeddingSize) Sets the size of the embeddings.protected abstract B
Creates a newEmbedding.BaseBuilder
with the specified embedding type.
-
Field Details
-
embeddingType
-
numEmbeddings
protected int numEmbeddings -
embeddingSize
protected int embeddingSize -
useDefault
protected boolean useDefault -
defaultItem
-
fallthrough
-
sparseFormat
-
-
Constructor Details
-
BaseBuilder
protected BaseBuilder()
-
-
Method Details
-
getEmbeddingType
Returns the embedded type.- Returns:
- the embedded type
-
setType
Creates a newEmbedding.BaseBuilder
with the specified embedding type.- Parameters:
embeddingType
- the embedding class- Returns:
- a new
Embedding.BaseBuilder
class with the specified embedding type
-
setEmbeddingSize
Sets the size of the embeddings.- Parameters:
embeddingSize
- the size of the 1D embedding array- Returns:
- this Builder
-
optNumEmbeddings
Sets the size of the dictionary of embeddings.- Parameters:
numEmbeddings
- the size of the dictionary of embeddings- Returns:
- this Builder
-
optUseDefault
Sets whether to use a default embedding for undefined items (default true).- Parameters:
useDefault
- true to provide a default embedding and false to throw anIllegalArgumentException
when the item can not be found- Returns:
- this Builder
-
optDefaultItem
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
Sets a custom handler for items not found in the embedding.See the standard fallthrough handlers
optUseDefault(boolean)
andoptDefaultItem(Object)
.- Parameters:
fallthrough
- the embedding to handle default cases.- Returns:
- this Builder
-
optSparseFormat
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
Returns this {code Builder} object.- Returns:
- this
BaseBuilder
-