T
- the type of item that should be embedded and map to the arraypublic class Embedding<T> extends ParameterBlock
NDArray
s.Modifier and Type | Class and Description |
---|---|
static class |
Embedding.Builder<T>
|
inputNames, inputShapes
Constructor and Description |
---|
Embedding(NDArray embedding,
java.util.List<T> items)
Constructs a pretrained embedding.
|
Modifier and Type | Method and Description |
---|---|
static Embedding.Builder<?> |
builder()
Creates a builder to build an
Embedding . |
NDArray |
embed(NDManager manager,
T item)
Embeds an item.
|
NDArray |
embed(NDManager manager,
T[] items)
Embeds an array of items.
|
NDList |
forward(ParameterStore parameterStore,
NDList inputs,
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(T 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.
|
getChildren, initialize, toString
beforeInitialize, cast, clear, describeInput, getParameters, isInitialized, readInputShapes, saveInputShapes, setInitializer, setInitializer
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
forward, validateLayout
public static Embedding.Builder<?> builder()
Embedding
.public Shape[] getOutputShapes(NDManager manager, Shape[] inputShapes)
manager
- an NDManagerinputShapes
- the shapes of the inputspublic java.util.List<Parameter> getDirectParameters()
Parameter
public Shape getParameterShape(java.lang.String name, Shape[] inputShapes)
name
- the name of the parameterinputShapes
- the shapes of the input to the blockpublic NDList forward(ParameterStore parameterStore, NDList inputs, ai.djl.util.PairList<java.lang.String,java.lang.Object> params)
parameterStore
- the parameter storeinputs
- the input NDListparams
- optional parameterspublic void saveParameters(java.io.DataOutputStream os) throws java.io.IOException
os
- 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
manager
- 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 boolean hasItem(T item)
item
- the item to testpublic NDArray embed(NDManager manager, T[] items)
manager
- the manager for the new embeddingsitems
- the items to embedNDArray
of Shape(items.length)