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,
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>
125 size_t embeddingSize;
128 OutputDataType weights;
131 OutputDataType delta;
134 OutputDataType gradient;
137 OutputDataType outputParameter;
141template<
typename MatType = arma::mat>
148#include "lookup_impl.hpp"
The Lookup class stores word embeddings and retrieves them using tokens.
OutputDataType const & Delta() const
Get the delta.
OutputDataType const & Parameters() const
Get the parameters.
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 & OutputParameter() const
Get the output parameter.
void Gradient(const arma::Mat< eT > &input, const arma::Mat< eT > &error, arma::Mat< eT > &gradient)
Calculate the gradient using the output delta and the input activation.
OutputDataType const & Gradient() const
Get the gradient.
OutputDataType & Gradient()
Modify the gradient.
size_t VocabSize() const
Get the size of the vocabulary.
Lookup(const size_t vocabSize=0, const size_t embeddingSize=0)
Create the Lookup object using the specified vocabulary and embedding size.
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 serialize(Archive &ar, const unsigned int)
Serialize the layer.
OutputDataType & Parameters()
Modify the parameters.
OutputDataType & Delta()
Modify the delta.
size_t EmbeddingSize() const
Get the length of each embedding vector.
Linear algebra utility functions, generally performed on matrices or vectors.
The core includes that mlpack expects; standard C++ includes and Armadillo.