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, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, forward, validateLayout
protected 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)
Block
public Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
Block
getOutputShapes
in interface Block
manager
- an NDManagerinputShapes
- the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
AbstractBlock
saveParameters
in interface Block
saveParameters
in class AbstractBlock
os
- the outputstream to save the parameters topublic void loadParameters(NDManager manager, java.io.DataInputStream is)
AbstractBlock
loadParameters
in interface Block
loadParameters
in class AbstractBlock
manager
- an NDManager to create the parameter arraysis
- the inputstream that stream the parameter valuespublic java.util.Optional<?> unembed(long index)
AbstractIndexedEmbedding
unembed
in interface AbstractIndexedEmbedding
index
- the indexpublic byte[] encode(java.lang.Object input)
AbstractIndexedEmbedding
Embedding
objects.encode
in interface AbstractIndexedEmbedding
input
- the input object to be encodedpublic java.lang.Object decode(byte[] byteArray)
AbstractIndexedEmbedding
decode
in interface AbstractIndexedEmbedding
byteArray
- the byte array to be decodedpublic long embed(java.lang.Object item)
AbstractIndexedEmbedding
embed
in interface AbstractIndexedEmbedding
item
- the item to embedpublic NDArray embed(NDManager manager, java.lang.Object[] items)
AbstractEmbedding
embed
in interface AbstractEmbedding
manager
- the manager for the new embeddingsitems
- the items to embedNDArray
of Shape(items.length, embeddingSize)public boolean hasItem(java.lang.Object item)
AbstractEmbedding
hasItem
in interface AbstractEmbedding
item
- the item to test