From b8e657ce3f87b8316e8bf95a9b22226749561a67 Mon Sep 17 00:00:00 2001 From: hartbook <franck.dary@etu.univ-amu.fr> Date: Mon, 2 Jul 2018 15:58:15 +0200 Subject: [PATCH] Started decoder --- CMakeLists.txt | 2 ++ MLP/src/MLP.cpp | 3 +-- decoder/CMakeLists.txt | 4 ++++ decoder/include/Decoder.hpp | 22 ++++++++++++++++++++++ decoder/src/Decoder.cpp | 12 ++++++++++++ tape_machine/include/Classifier.hpp | 2 ++ tape_machine/src/Classifier.cpp | 15 +++++++++++++++ trainer/include/Trainer.hpp | 1 - trainer/src/Trainer.cpp | 19 ++----------------- 9 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 decoder/CMakeLists.txt create mode 100644 decoder/include/Decoder.hpp create mode 100644 decoder/src/Decoder.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 8390598..c30ddfc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,11 +17,13 @@ set(CMAKE_CXX_FLAGS_RELEASE "-O3") include_directories(maca_common/include) include_directories(tape_machine/include) include_directories(trainer/include) +include_directories(decoder/include) include_directories(tests/include) include_directories(MLP/include) add_subdirectory(maca_common) add_subdirectory(tape_machine) add_subdirectory(trainer) +add_subdirectory(decoder) add_subdirectory(MLP) add_subdirectory(tests) diff --git a/MLP/src/MLP.cpp b/MLP/src/MLP.cpp index 11b993b..4c1bc79 100644 --- a/MLP/src/MLP.cpp +++ b/MLP/src/MLP.cpp @@ -150,11 +150,10 @@ dynet::Parameter & MLP::featValue2parameter(const FeatureModel::FeatureValue & f if(it != ptr2parameter.end()) return it->second; - //ptr2parameter[fv.vec] = model.add_parameters({fv.vec->size(),1}, dynet::ParameterInitFromVector(*fv.vec)); ptr2parameter[fv.vec] = model.add_parameters({(unsigned)fv.vec->size(),1}); it = ptr2parameter.find(fv.vec); -// it->second.values()->v = fv.vec->data(); + it->second.values()->v = fv.vec->data(); return it->second; } diff --git a/decoder/CMakeLists.txt b/decoder/CMakeLists.txt new file mode 100644 index 0000000..1054160 --- /dev/null +++ b/decoder/CMakeLists.txt @@ -0,0 +1,4 @@ +FILE(GLOB SOURCES src/*.cpp) + +#compiling library +add_library(decoder STATIC ${SOURCES}) diff --git a/decoder/include/Decoder.hpp b/decoder/include/Decoder.hpp new file mode 100644 index 0000000..5c61498 --- /dev/null +++ b/decoder/include/Decoder.hpp @@ -0,0 +1,22 @@ +#ifndef DECODER__H +#define DECODER__H + +#include "TapeMachine.hpp" +#include "MCD.hpp" +#include "Config.hpp" + +class Decoder +{ + private : + + TapeMachine & tm; + MCD & mcd; + Config & config; + + public : + + Decoder(TapeMachine & tm, MCD & mcd, Config & config); + void decode(); +}; + +#endif diff --git a/decoder/src/Decoder.cpp b/decoder/src/Decoder.cpp new file mode 100644 index 0000000..779e59b --- /dev/null +++ b/decoder/src/Decoder.cpp @@ -0,0 +1,12 @@ +#include "Decoder.hpp" + +Decoder::Decoder(TapeMachine & tm, MCD & mcd, Config & config) +: tm(tm), mcd(mcd), config(config) +{ +} + +void Decoder::decode() +{ + +} + diff --git a/tape_machine/include/Classifier.hpp b/tape_machine/include/Classifier.hpp index 5b913c9..7ee75bb 100644 --- a/tape_machine/include/Classifier.hpp +++ b/tape_machine/include/Classifier.hpp @@ -33,6 +33,8 @@ class Classifier public : + static void printWeightedActions(FILE * output, WeightedActions & wa); + static Type str2type(const std::string & filename); Classifier(const std::string & filename); WeightedActions weightActions(Config & config, const std::string & goldAction); diff --git a/tape_machine/src/Classifier.cpp b/tape_machine/src/Classifier.cpp index 7f6cd60..9e3ff5e 100644 --- a/tape_machine/src/Classifier.cpp +++ b/tape_machine/src/Classifier.cpp @@ -123,3 +123,18 @@ std::string Classifier::getActionName(int actionIndex) return as->getActionName(actionIndex); } +void Classifier::printWeightedActions(FILE * output, WeightedActions & wa) +{ + int nbCols = 80; + char symbol = '-'; + + for(int i = 0; i < nbCols; i++) + fprintf(output, "%c%s", symbol, i == nbCols-1 ? "\n" : ""); + + for (auto it : wa) + fprintf(output, "%.2f\t%s\n", it.first, it.second.c_str()); + + for(int i = 0; i < nbCols; i++) + fprintf(output, "%c%s", symbol, i == nbCols-1 ? "\n" : ""); +} + diff --git a/trainer/include/Trainer.hpp b/trainer/include/Trainer.hpp index 361d215..93c41d1 100644 --- a/trainer/include/Trainer.hpp +++ b/trainer/include/Trainer.hpp @@ -15,7 +15,6 @@ class Trainer private : - void printWeightedActions(FILE * output, Classifier::WeightedActions & wa); void trainUnbatched(); void trainBatched(); diff --git a/trainer/src/Trainer.cpp b/trainer/src/Trainer.cpp index 4f6aca2..f341911 100644 --- a/trainer/src/Trainer.cpp +++ b/trainer/src/Trainer.cpp @@ -71,8 +71,8 @@ void Trainer::trainBatched() config.moveHead(transition->headMvt); } - int nbIter = 20; - int batchSize = 50; + int nbIter = 5; + int batchSize = 256; for (int i = 0; i < nbIter; i++) { @@ -109,18 +109,3 @@ void Trainer::train() trainBatched(); } -void Trainer::printWeightedActions(FILE * output, Classifier::WeightedActions & wa) -{ - int nbCols = 80; - char symbol = '-'; - - for(int i = 0; i < nbCols; i++) - fprintf(output, "%c%s", symbol, i == nbCols-1 ? "\n" : ""); - - for (auto it : wa) - fprintf(output, "%.2f\t%s\n", it.first, it.second.c_str()); - - for(int i = 0; i < nbCols; i++) - fprintf(output, "%c%s", symbol, i == nbCols-1 ? "\n" : ""); -} - -- GitLab