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, 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.
|
protected NDList |
forwardInternal(ParameterStore parameterStore,
NDList inputs,
boolean training,
ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
A helper for
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization. |
Shape[] |
getOutputShapes(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, beforeInitialize, cast, clear, describeInput, forward, forward, forwardInternal, getChildren, getDirectParameters, getParameters, initialize, initializeChildBlocks, isInitialized, loadMetadata, prepare, readInputShapes, saveInputShapes, saveMetadata, setInitializer, setInitializer, setInitializer, toStringclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, validateLayoutprotected NDArray embedding
public ConstantEmbedding(NDArray embedding)
embedding - the value to return for all embeddingsprotected NDList forwardInternal(ParameterStore parameterStore, NDList inputs, boolean training, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
Block.forward(ParameterStore, NDList, boolean, PairList) after
initialization.forwardInternal in class AbstractBlockparameterStore - the parameter storeinputs - the input NDListtraining - true for a training forward passparams - optional parameterspublic Shape[] getOutputShapes(Shape[] inputShapes)
getOutputShapes in interface BlockinputShapes - the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
saveParameters in interface BlocksaveParameters in class AbstractBlockos - the outputstream to save the parameters topublic void loadParameters(NDManager manager, java.io.DataInputStream is)
loadParameters 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)
unembed in interface AbstractIndexedEmbeddingindex - the indexpublic byte[] encode(java.lang.Object input)
Embedding objects.encode in interface AbstractIndexedEmbeddinginput - the input object to be encodedpublic java.lang.Object decode(byte[] byteArray)
decode in interface AbstractIndexedEmbeddingbyteArray - the byte array to be decodedpublic long embed(java.lang.Object item)
embed in interface AbstractIndexedEmbeddingitem - the item to embedpublic NDArray embed(NDManager manager, java.lang.Object[] items)
embed 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)
hasItem in interface AbstractEmbeddingitem - the item to test