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, toString
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, validateLayout
protected 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 AbstractBlock
parameterStore
- the parameter storeinputs
- the input NDListtraining
- true for a training forward passparams
- optional parameterspublic Shape[] getOutputShapes(Shape[] inputShapes)
getOutputShapes
in interface Block
inputShapes
- the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
saveParameters
in interface Block
saveParameters
in class AbstractBlock
os
- the outputstream to save the parameters topublic void loadParameters(NDManager manager, java.io.DataInputStream is)
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)
unembed
in interface AbstractIndexedEmbedding
index
- the indexpublic byte[] encode(java.lang.Object input)
Embedding
objects.encode
in interface AbstractIndexedEmbedding
input
- the input object to be encodedpublic java.lang.Object decode(byte[] byteArray)
decode
in interface AbstractIndexedEmbedding
byteArray
- the byte array to be decodedpublic long embed(java.lang.Object item)
embed
in interface AbstractIndexedEmbedding
item
- the item to embedpublic NDArray embed(NDManager manager, java.lang.Object[] items)
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)
hasItem
in interface AbstractEmbedding
item
- the item to test