diff --git a/CMakeLists.txt b/CMakeLists.txt index 8390598a1492b17b1f548fc5f2b50037b3b6b14c..c30ddfc50edf298a5f42e82a28db89ab576bf08d 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 11b993bf0e1a91f976d87f7808e5040e41a4a317..4c1bc79d62c2703d91e1069aba0ba211d979f5b0 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 0000000000000000000000000000000000000000..1054160ac9f37995594c3555811144b54be0e6e2 --- /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 0000000000000000000000000000000000000000..5c61498bae0450509eb9157a76b7e0b14f285c51 --- /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 0000000000000000000000000000000000000000..779e59b417939ab8f9b3eab0c84759b32fcb619c --- /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 5b913c9e90f16e5a242f2db90d2276aba66c8191..7ee75bb35df98a1a92269311220c2666d0345aca 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 7f6cd608d251b4e4872f6e6101de36c19cb122d5..9e3ff5efa694e79e1fc17a80ecadf53f3595ab20 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 361d215354f92720b4975339af51005961d2fa30..93c41d12699b53b10fd281bba35e87934e42e945 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 4f6aca255e5a6598dfc34dc1db830d007d28b9bd..f3419110606f52535ef0d423d0cb17353fb5e841 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" : ""); -} -