diff --git a/MLP/src/MLP.cpp b/MLP/src/MLP.cpp index 8852ef509c890a09e53c7ed06c06135de77074fc..daf41e8660438eda5434ebf3bc648bbe02170bdb 100644 --- a/MLP/src/MLP.cpp +++ b/MLP/src/MLP.cpp @@ -270,10 +270,14 @@ dynet::Expression MLP::run(dynet::ComputationGraph & cg, dynet::Expression x) if (ProgramParameters::showFeatureRepresentation) { - for (unsigned int i = 0; i < 81; i++) - fprintf(stderr, "%s", i == 80 ? "\n" : "-"); + if (ProgramParameters::showFeatureRepresentation == 1) + for (unsigned int i = 0; i < 81; i++) + fprintf(stderr, "%s", i == 80 ? "\n" : "-"); exprForDebug.clear(); - exprForDebug.emplace_back("Input layer", h_cur); + if (ProgramParameters::showFeatureRepresentation == 1) + exprForDebug.emplace_back("Input layer", h_cur); + if (ProgramParameters::showFeatureRepresentation >= 2) + exprForDebug.emplace_back("", h_cur); } for(unsigned int l = 0; l < layers.size(); l++) @@ -303,9 +307,17 @@ dynet::Expression MLP::run(dynet::ComputationGraph & cg, dynet::Expression x) if (ProgramParameters::showFeatureRepresentation) { - exprForDebug.emplace_back("Result of h = h*W_" + std::to_string(l) + " + b_" + std::to_string(l), a); - exprForDebug.emplace_back("Result of h = a_" + std::to_string(l) + "(h)", h); - exprForDebug.emplace_back("Result of h = dropout_" + std::to_string(l) + "(h)", h_dropped); + if (ProgramParameters::showFeatureRepresentation == 1) + { + exprForDebug.emplace_back("Result of h = h*W_" + std::to_string(l) + " + b_" + std::to_string(l), a); + exprForDebug.emplace_back("Result of h = a_" + std::to_string(l) + "(h)", h); + exprForDebug.emplace_back("Result of h = dropout_" + std::to_string(l) + "(h)", h_dropped); + } + else if (ProgramParameters::showFeatureRepresentation >= 2) + { + exprForDebug.emplace_back("", a); + exprForDebug.emplace_back("", h); + } } h_cur = h_dropped; @@ -314,10 +326,20 @@ dynet::Expression MLP::run(dynet::ComputationGraph & cg, dynet::Expression x) if (ProgramParameters::showFeatureRepresentation) { cg.forward(h_cur); - for (auto & it : exprForDebug) - fprintf(stderr, "%s (dimension=%lu) :\n%s\n", it.first.c_str(), dynet::as_vector(it.second.value()).size(), expression2str(it.second).c_str()); - for (unsigned int i = 0; i < 81; i++) - fprintf(stderr, "%s", i == 80 ? "\n" : "-"); + + if (ProgramParameters::showFeatureRepresentation == 1) + { + for (auto & it : exprForDebug) + fprintf(stderr, "%s (dimension=%lu) :\n%s\n", it.first.c_str(), dynet::as_vector(it.second.value()).size(), expression2str(it.second).c_str()); + for (unsigned int i = 0; i < 81; i++) + fprintf(stderr, "%s", i == 80 ? "\n" : "-"); + } + else if (ProgramParameters::showFeatureRepresentation >= 2) + { + for (auto & it : exprForDebug) + fprintf(stderr, "| %s |", expression2str(it.second).c_str()); + fprintf(stderr, "\n"); + } } return h_cur; @@ -457,17 +479,16 @@ dynet::ParameterCollection & MLP::getModel() std::string MLP::expression2str(dynet::Expression & expr) { - std::string result = "<"; + std::string result = ""; auto elem = dynet::as_vector(expr.value()); for (auto & f : elem) result += float2str(f, "%f") + " "; + if (!result.empty()) result.pop_back(); - result += ">"; - return result; } diff --git a/decoder/src/macaon_decode.cpp b/decoder/src/macaon_decode.cpp index c7f811d5db5918326bc50716b5eb0950829fd933..0fa11af8ef3f301e97450eeb3780e092707b28d8 100644 --- a/decoder/src/macaon_decode.cpp +++ b/decoder/src/macaon_decode.cpp @@ -42,7 +42,7 @@ po::options_description getOptionsDescription() "The name of the buffer's tape that contains the delimiter token for a sequence") ("sequenceDelimiter", po::value<std::string>()->default_value("1"), "The value of the token that act as a delimiter for sequences") - ("showFeatureRepresentation", po::value<bool>()->default_value(false), + ("showFeatureRepresentation", po::value<int>()->default_value(0), "For each state of the Config, show its feature representation") ("lang", po::value<std::string>()->default_value("fr"), "Language you are working with"); @@ -110,7 +110,7 @@ int main(int argc, char * argv[]) ProgramParameters::lang = vm["lang"].as<std::string>(); ProgramParameters::sequenceDelimiterTape = vm["sequenceDelimiterTape"].as<std::string>(); ProgramParameters::sequenceDelimiter = vm["sequenceDelimiter"].as<std::string>(); - ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<bool>(); + ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>(); const char * MACAON_DIR = std::getenv("MACAON_DIR"); std::string slash = "/"; diff --git a/error_correction/src/macaon_decode_error_detector.cpp b/error_correction/src/macaon_decode_error_detector.cpp index 488fabf01c2820a338d7c3fda77f2c65800b88b3..8b8236858715b550ec73c9db8b13400b481f1e51 100644 --- a/error_correction/src/macaon_decode_error_detector.cpp +++ b/error_correction/src/macaon_decode_error_detector.cpp @@ -41,7 +41,7 @@ po::options_description getOptionsDescription() "The name of the buffer's tape that contains the delimiter token for a sequence") ("sequenceDelimiter", po::value<std::string>()->default_value("1"), "The value of the token that act as a delimiter for sequences") - ("showFeatureRepresentation", po::value<bool>()->default_value(false), + ("showFeatureRepresentation", po::value<int>()->default_value(0), "For each state of the Config, show its feature representation") ("lang", po::value<std::string>()->default_value("fr"), "Language you are working with"); @@ -109,7 +109,7 @@ int main(int argc, char * argv[]) ProgramParameters::lang = vm["lang"].as<std::string>(); ProgramParameters::sequenceDelimiterTape = vm["sequenceDelimiterTape"].as<std::string>(); ProgramParameters::sequenceDelimiter = vm["sequenceDelimiter"].as<std::string>(); - ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<bool>(); + ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>(); const char * MACAON_DIR = std::getenv("MACAON_DIR"); std::string slash = "/"; diff --git a/error_correction/src/macaon_train_error_detector.cpp b/error_correction/src/macaon_train_error_detector.cpp index 5221047f047a9f94d0debf1e45e0a05f01b692af..da5f3f5432eca467a1af4f941286ff683fdb33ea 100644 --- a/error_correction/src/macaon_train_error_detector.cpp +++ b/error_correction/src/macaon_train_error_detector.cpp @@ -61,7 +61,7 @@ po::options_description getOptionsDescription() "The number of models that will be trained, with only the random seed changing") ("duplicates", po::value<bool>()->default_value(true), "Remove identical training examples") - ("showFeatureRepresentation", po::value<bool>()->default_value(false), + ("showFeatureRepresentation", po::value<int>()->default_value(0), "For each state of the Config, show its feature representation") ("interactive", po::value<bool>()->default_value(true), "Is the shell interactive ? Display advancement informations") @@ -515,7 +515,7 @@ int main(int argc, char * argv[]) ProgramParameters::optimizer = vm["optimizer"].as<std::string>(); ProgramParameters::dynamicEpoch = vm["epochd"].as<int>(); ProgramParameters::dynamicProbability = vm["proba"].as<float>(); - ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<bool>(); + ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>(); ProgramParameters::iterationSize = vm["iterationSize"].as<int>(); if (ProgramParameters::nbTrain) diff --git a/maca_common/include/ProgramParameters.hpp b/maca_common/include/ProgramParameters.hpp index 0e25ebd9a62944597544db7edad8694d6d71b9a1..8e706fe7a5290a7b2d0203450554f3f132281049 100644 --- a/maca_common/include/ProgramParameters.hpp +++ b/maca_common/include/ProgramParameters.hpp @@ -41,7 +41,7 @@ struct ProgramParameters static bool interactive; static int dynamicEpoch; static float dynamicProbability; - static bool showFeatureRepresentation; + static int showFeatureRepresentation; static int iterationSize; static int nbTrain; static bool randomEmbeddings; diff --git a/maca_common/src/ProgramParameters.cpp b/maca_common/src/ProgramParameters.cpp index c863179ce7fdfcd47f3f5ae9fd8ef8c7e7277a5b..00283642a93d03d9e269d06a1b73f2f251bc5427 100644 --- a/maca_common/src/ProgramParameters.cpp +++ b/maca_common/src/ProgramParameters.cpp @@ -36,7 +36,7 @@ float ProgramParameters::bias; bool ProgramParameters::interactive; int ProgramParameters::dynamicEpoch; float ProgramParameters::dynamicProbability; -bool ProgramParameters::showFeatureRepresentation; +int ProgramParameters::showFeatureRepresentation; bool ProgramParameters::randomEmbeddings; bool ProgramParameters::printEntropy; bool ProgramParameters::printTime; diff --git a/trainer/src/macaon_train.cpp b/trainer/src/macaon_train.cpp index 33ea8ad04179124d3af8f2f6bb2e54c0fb557791..e7965a72c9f6ce2548401ecd523178c2a710d6da 100644 --- a/trainer/src/macaon_train.cpp +++ b/trainer/src/macaon_train.cpp @@ -59,7 +59,7 @@ po::options_description getOptionsDescription() "The number of models that will be trained, with only the random seed changing") ("duplicates", po::value<bool>()->default_value(true), "Remove identical training examples") - ("showFeatureRepresentation", po::value<bool>()->default_value(false), + ("showFeatureRepresentation", po::value<int>()->default_value(0), "For each state of the Config, show its feature representation") ("interactive", po::value<bool>()->default_value(true), "Is the shell interactive ? Display advancement informations") @@ -262,7 +262,7 @@ int main(int argc, char * argv[]) ProgramParameters::optimizer = vm["optimizer"].as<std::string>(); ProgramParameters::dynamicEpoch = vm["epochd"].as<int>(); ProgramParameters::dynamicProbability = vm["proba"].as<float>(); - ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<bool>(); + ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>(); ProgramParameters::iterationSize = vm["iterationSize"].as<int>(); if (ProgramParameters::nbTrain) diff --git a/transition_machine/src/Classifier.cpp b/transition_machine/src/Classifier.cpp index 25c7291d3657f47ded719d54b3ca3834dd520a1c..b54e3aa4834ae72c13e804b0e56986bc2cbd10c9 100644 --- a/transition_machine/src/Classifier.cpp +++ b/transition_machine/src/Classifier.cpp @@ -94,7 +94,7 @@ Classifier::WeightedActions Classifier::weightActions(Config & config) auto fd = fm->getFeatureDescription(config); auto scores = mlp->predict(fd); - if (ProgramParameters::showFeatureRepresentation) + if (ProgramParameters::showFeatureRepresentation == 1) fd.printForDebug(stderr); for (unsigned int i = 0; i < scores.size(); i++)