49 Index embedding_dimension = 0,
50 const string&
label =
"embedding_layer");
87 void set(Index vocabulary_size = 0,
88 Index sequence_length = 0,
89 Index embedding_dimension = 0,
90 const string&
label =
"embedding_layer");
132 Index vocabulary_size = 0;
134 Index sequence_length = 0;
136 Index embedding_dimension = 0;
144 enum Forward {Input, Output};
146 enum Backward {OutputDelta};
void set_scale_embedding(bool enabled)
Enables Transformer-style sqrt(d_model) scaling on the embedding table output.
Definition embedding_layer.h:97
void back_propagate(ForwardPropagation &, BackPropagation &, size_t) const noexcept override
Backward pass: scatters output gradients into the embedding table rows referenced by the input ids.
void set_dropout_rate(float rate)
Sets the dropout rate applied at the layer output.
Definition embedding_layer.h:107
void read_JSON_body(const Json *) override
Reads the layer-specific JSON body (vocabulary size, sequence length, embedding dimension,...
Shape get_input_shape() const override
Returns the per-sample input shape (sequence_length,).
Definition embedding_layer.h:53
Index get_sequence_length() const
Sequence length expected at input.
Definition embedding_layer.h:63
void set_add_positional_encoding(bool enabled)
Enables addition of a sinusoidal positional encoding after lookup.
Definition embedding_layer.h:102
vector< pair< Shape, Type > > get_forward_specs(Index batch_size) const override
Specifications of the forward intermediate buffers.
vector< Operator * > get_operators() override
Returns the active operators in pipeline order.
Embedding(const Shape &input_shape={0, 0}, Index embedding_dimension=0, const string &label="embedding_layer")
Constructs an Embedding layer.
void set(Index vocabulary_size=0, Index sequence_length=0, Index embedding_dimension=0, const string &label="embedding_layer")
Re-initializes the layer.
Index get_vocabulary_size() const
Number of distinct tokens in the vocabulary.
Definition embedding_layer.h:61
Index get_embedding_dimension() const
Width of each embedding vector.
Definition embedding_layer.h:65
Shape get_output_shape() const override
Returns the per-sample output shape.
void write_JSON_body(JsonWriter &) const override
Writes the layer-specific JSON body (vocabulary size, sequence length, embedding dimension,...
Layer()=default
Default constructor; only invoked by subclasses.
string label
User-visible label for this layer instance (default "my_layer").
Definition layer.h:469
Declares the Layer abstract base class and the LayerType enumeration.
Definition adaptive_moment_estimation.h:19
Definition back_propagation.h:26
Definition operators.h:65
Definition operators.h:637
Definition forward_propagation.h:19
Definition tensor_utilities.h:46