Skip to content
Snippets Groups Projects
Commit 1cf6cf2f authored by Franck Dary's avatar Franck Dary
Browse files

Deleted OneWordNetwork

parent b75be56d
No related branches found
No related tags found
No related merge requests found
#include "Classifier.hpp"
#include "util.hpp"
#include "OneWordNetwork.hpp"
#include "ConcatWordsNetwork.hpp"
#include "RLTNetwork.hpp"
#include "CNNNetwork.hpp"
......@@ -41,14 +40,6 @@ void Classifier::initNeuralNetwork(const std::string & topology)
this->nn.reset(new RandomNetworkImpl(this->transitionSet->size()));
}
},
{
std::regex("OneWord\\(([+\\-]?\\d+)\\)"),
"OneWord(focusedIndex) : Only use the word embedding of the focused word.",
[this,topology](auto sm)
{
this->nn.reset(new OneWordNetworkImpl(this->transitionSet->size(), std::stoi(sm.str(1))));
}
},
{
std::regex("ConcatWords\\(\\{(.*)\\},\\{(.*)\\}\\)"),
"ConcatWords({bufferContext},{stackContext}) : Concatenate embeddings of words in context.",
......
#ifndef ONEWORDNETWORK__H
#define ONEWORDNETWORK__H
#include "NeuralNetwork.hpp"
class OneWordNetworkImpl : public NeuralNetworkImpl
{
private :
torch::nn::Embedding wordEmbeddings{nullptr};
torch::nn::Linear linear{nullptr};
public :
OneWordNetworkImpl(int nbOutputs, int focusedIndex);
torch::Tensor forward(torch::Tensor input) override;
};
#endif
#include "OneWordNetwork.hpp"
OneWordNetworkImpl::OneWordNetworkImpl(int nbOutputs, int focusedIndex)
{
constexpr int embeddingsSize = 64;
setBufferContext({focusedIndex});
setStackContext({});
setColumns({"FORM", "UPOS"});
wordEmbeddings = register_module("word_embeddings", torch::nn::Embedding(torch::nn::EmbeddingOptions(50000, embeddingsSize)));
linear = register_module("linear", torch::nn::Linear(getContextSize()*embeddingsSize, nbOutputs));
}
torch::Tensor OneWordNetworkImpl::forward(torch::Tensor input)
{
if (input.dim() == 1)
input = input.unsqueeze(0);
auto wordAsEmb = wordEmbeddings(input).view({input.size(0),-1});
auto res = linear(wordAsEmb);
return res;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment