public class ConstantEmbedding extends AbstractBlock implements AbstractIndexedEmbedding
AbstractIndexedEmbedding that always returns a constant value.| Modifier and Type | Field and Description |
|---|---|
protected NDArray |
embedding |
children, inputNames, inputShapes, parameters, parameterShapeCallbacks, version| Constructor and Description |
|---|
ConstantEmbedding(NDArray embedding)
Constructs a constant embedding with the given constant.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
decode(byte[] byteArray)
Decodes the given byte array into an object of input parameter type.
|
NDArray |
embed(NDManager manager,
java.lang.Object[] items)
Embeds an array of items.
|
long |
embed(java.lang.Object item)
Embeds an item.
|
byte[] |
encode(java.lang.Object input)
Encodes an object of input type into a byte array.
|
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Applies the operating function of the block once.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
boolean |
hasItem(java.lang.Object item)
Returns whether an item is in the embedding.
|
void |
loadParameters(NDManager manager,
java.io.DataInputStream is)
Loads the parameters from the given input stream.
|
void |
saveParameters(java.io.DataOutputStream os)
Writes the parameters of the block to the given outputStream.
|
java.util.Optional<?> |
unembed(long index)
Returns the item corresponding to the given index.
|
addChildBlock, addParameter, addParameter, addParameter, beforeInitialize, cast, clear, describeInput, getChildren, getDirectParameters, getParameters, getParameterShape, initialize, initializeChildBlocks, isInitialized, loadMetadata, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, forward, validateLayoutprotected NDArray embedding
public ConstantEmbedding(NDArray embedding)
embedding - the value to return for all embeddingspublic NDList forward(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Blockpublic Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
BlockgetOutputShapes in interface Blockmanager - an NDManagerinputShapes - the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
AbstractBlocksaveParameters in interface BlocksaveParameters in class AbstractBlockos - the outputstream to save the parameters topublic void loadParameters(NDManager manager, java.io.DataInputStream is)
AbstractBlockloadParameters in interface BlockloadParameters in class AbstractBlockmanager - an NDManager to create the parameter arraysis - the inputstream that stream the parameter valuespublic java.util.Optional<?> unembed(long index)
AbstractIndexedEmbeddingunembed in interface AbstractIndexedEmbeddingindex - the indexpublic byte[] encode(java.lang.Object input)
AbstractIndexedEmbeddingEmbedding objects.encode in interface AbstractIndexedEmbeddinginput - the input object to be encodedpublic java.lang.Object decode(byte[] byteArray)
AbstractIndexedEmbeddingdecode in interface AbstractIndexedEmbeddingbyteArray - the byte array to be decodedpublic long embed(java.lang.Object item)
AbstractIndexedEmbeddingembed in interface AbstractIndexedEmbeddingitem - the item to embedpublic NDArray embed(NDManager manager, java.lang.Object[] items)
AbstractEmbeddingembed in interface AbstractEmbeddingmanager - the manager for the new embeddingsitems - the items to embedNDArray of Shape(items.length, embeddingSize)public boolean hasItem(java.lang.Object item)
AbstractEmbeddinghasItem in interface AbstractEmbeddingitem - the item to test