12 #ifndef MLPACK_METHODS_ANN_LAYER_POSITIONAL_ENCODING_HPP 13 #define MLPACK_METHODS_ANN_LAYER_POSITIONAL_ENCODING_HPP 34 typename InputDataType = arma::mat,
35 typename OutputDataType = arma::mat
52 const size_t maxSequenceLength);
62 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
75 const arma::Mat<eT>& gy,
89 OutputDataType
const&
Delta()
const {
return delta; }
91 OutputDataType&
Delta() {
return delta; }
94 InputDataType
const&
Encoding()
const {
return positionalEncoding; }
96 size_t InputShape()
const 98 return embedDim * maxSequenceLength;
104 template<
typename Archive>
105 void serialize(Archive& ar,
const uint32_t );
111 void InitPositionalEncoding();
117 size_t maxSequenceLength;
120 InputDataType positionalEncoding;
123 OutputDataType delta;
126 InputDataType inputParameter;
129 OutputDataType outputParameter;
OutputDataType & OutputParameter()
Modify the output parameter.
Definition: positional_encoding.hpp:86
Linear algebra utility functions, generally performed on matrices or vectors.
Definition: cv.hpp:1
The core includes that mlpack expects; standard C++ includes and Armadillo.
void Forward(const arma::Mat< eT > &input, arma::Mat< eT > &output)
Ordinary feed forward pass of a neural network, evaluating the function f(x) by propagating the activ...
Definition: positional_encoding_impl.hpp:58
OutputDataType & Delta()
Modify the delta.
Definition: positional_encoding.hpp:91
Positional Encoding injects some information about the relative or absolute position of the tokens in...
Definition: positional_encoding.hpp:37
InputDataType & InputParameter()
Modify the input parameter.
Definition: positional_encoding.hpp:81
InputDataType const & Encoding() const
Get the positional encoding vector.
Definition: positional_encoding.hpp:94
OutputDataType const & Delta() const
Get the delta.
Definition: positional_encoding.hpp:89
InputDataType const & InputParameter() const
Get the input parameter.
Definition: positional_encoding.hpp:79
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
Definition: positional_encoding_impl.hpp:77
PositionalEncoding()
Create PositionalEncoding object.
Definition: positional_encoding_impl.hpp:23
OutputDataType const & OutputParameter() const
Get the output parameter.
Definition: positional_encoding.hpp:84
void Backward(const arma::Mat< eT > &, const arma::Mat< eT > &gy, arma::Mat< eT > &g)
Ordinary feed backward pass of a neural network, calculating the function f(x) by propagating x backw...
Definition: positional_encoding_impl.hpp:69