13 #ifndef MLPACK_METHODS_ANN_LAYER_LOOKUP_HPP 14 #define MLPACK_METHODS_ANN_LAYER_LOOKUP_HPP 38 typename InputDataType = arma::mat,
39 typename OutputDataType = arma::mat
50 Lookup(
const size_t vocabSize = 0,
const size_t embeddingSize = 0);
60 void Forward(
const arma::Mat<eT>& input, arma::Mat<eT>& output);
73 const arma::Mat<eT>& gy,
84 void Gradient(
const arma::Mat<eT>& input,
85 const arma::Mat<eT>& error,
86 arma::Mat<eT>& gradient);
89 OutputDataType
const&
Parameters()
const {
return weights; }
99 OutputDataType
const&
Delta()
const {
return delta; }
101 OutputDataType&
Delta() {
return delta; }
104 OutputDataType
const&
Gradient()
const {
return gradient; }
117 template<
typename Archive>
118 void serialize(Archive& ar,
const uint32_t );
125 size_t embeddingSize;
128 OutputDataType weights;
131 OutputDataType delta;
134 OutputDataType gradient;
137 OutputDataType outputParameter;
141 template<
typename MatType = arma::mat>
148 #include "lookup_impl.hpp"
Linear algebra utility functions, generally performed on matrices or vectors.
void serialize(Archive &ar, const uint32_t)
Serialize the layer.
OutputDataType const & Gradient() const
Get the gradient.
size_t VocabSize() const
Get the size of the vocabulary.
The core includes that mlpack expects; standard C++ includes and Armadillo.
OutputDataType & Parameters()
Modify the parameters.
Lookup(const size_t vocabSize=0, const size_t embeddingSize=0)
Create the Lookup object using the specified vocabulary and embedding size.
OutputDataType const & Delta() const
Get the delta.
size_t EmbeddingSize() const
Get the length of each embedding vector.
The Lookup class stores word embeddings and retrieves them using tokens.
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...
OutputDataType & OutputParameter()
Modify the output parameter.
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...
OutputDataType const & Parameters() const
Get the parameters.
OutputDataType & Gradient()
Modify the gradient.
OutputDataType & Delta()
Modify the delta.
OutputDataType const & OutputParameter() const
Get the output parameter.