public class ConstantEmbedding extends ParameterBlock implements AbstractIndexedEmbedding
AbstractIndexedEmbedding that always returns a constant value.| Modifier and Type | Field and Description |
|---|---|
protected NDArray |
embedding |
inputNames, inputShapes| 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.
|
int |
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.
|
java.util.List<Parameter> |
getDirectParameters()
Returns a list of all the direct parameters of the block.
|
Shape[] |
getOutputShapes(NDManager manager,
Shape[] inputShapes)
Returns the expected output shapes of the block for the specified input shapes.
|
Shape |
getParameterShape(java.lang.String name,
Shape[] inputShapes)
Returns the shape of the specified direct parameter of this block given the shapes of the
input to the block.
|
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(int index)
Returns the item corresponding to the given index.
|
getChildren, initialize, toStringbeforeInitialize, cast, clear, describeInput, getParameters, isInitialized, readInputShapes, saveInputShapes, setInitializer, setInitializerclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitforward, 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 java.util.List<Parameter> getDirectParameters()
BlockgetDirectParameters in interface BlockParameterpublic Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
BlockgetParameterShape in interface Blockname - the name of the parameterinputShapes - the shapes of the input to the blockpublic Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
BlockgetOutputShapes in interface Blockmanager - an NDManagerinputShapes - the shapes of the inputspublic void saveParameters(java.io.DataOutputStream os)
throws java.io.IOException
BlocksaveParameters in interface Blockos - the outputstream to save the parameters tojava.io.IOException - if an I/O error occurspublic void loadParameters(NDManager manager, java.io.DataInputStream is) throws java.io.IOException, MalformedModelException
BlockloadParameters in interface Blockmanager - an NDManager to create the parameter arraysis - the inputstream that stream the parameter valuesjava.io.IOException - if an I/O error occursMalformedModelException - if the model file is corrupted or unsupportedpublic java.util.Optional<?> unembed(int index)
AbstractIndexedEmbeddingunembed in interface AbstractIndexedEmbeddingindex - the indexpublic byte[] encode(java.lang.Object input)
throws java.io.IOException
AbstractIndexedEmbeddingEmbedding objects.encode in interface AbstractIndexedEmbeddinginput - the input object to be encodedjava.io.IOException - if there is an error while encodingpublic java.lang.Object decode(byte[] byteArray)
throws java.io.IOException
AbstractIndexedEmbeddingdecode in interface AbstractIndexedEmbeddingbyteArray - the byte array to be decodedjava.io.IOException - if there was an error while decodingpublic int embed(java.lang.Object item)
AbstractIndexedEmbeddingembed in interface AbstractIndexedEmbeddingitem - the item to embedNDArray of Shape()public 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