diff --git a/maca_common/include/ProgramParameters.hpp b/maca_common/include/ProgramParameters.hpp index 14d920fa6af78cf5e452fb3e5c2ee351ea91bc0d..a749f9d4028aa67ba96688392de5b0cf3974efeb 100644 --- a/maca_common/include/ProgramParameters.hpp +++ b/maca_common/include/ProgramParameters.hpp @@ -6,6 +6,7 @@ #define PROGRAMPARAMETERS__H #include <string> +#include <map> struct ProgramParameters { @@ -54,6 +55,7 @@ struct ProgramParameters static int batchSize; static std::string loss; static std::string dicts; + static std::map<std::string,std::string> featureModelByClassifier; private : diff --git a/maca_common/src/ProgramParameters.cpp b/maca_common/src/ProgramParameters.cpp index cd88256d9c49ed2275ab125415ecbe5b1ff325bb..41930ad1380923e5acaee21c8c407be9d7c9892c 100644 --- a/maca_common/src/ProgramParameters.cpp +++ b/maca_common/src/ProgramParameters.cpp @@ -49,3 +49,4 @@ std::string ProgramParameters::sequenceDelimiter; std::string ProgramParameters::classifierName; int ProgramParameters::batchSize; std::string ProgramParameters::loss; +std::map<std::string,std::string> ProgramParameters::featureModelByClassifier; diff --git a/trainer/src/macaon_train.cpp b/trainer/src/macaon_train.cpp index ab8111c1eaa87772ff0b48cba2aaee179614e579..1e3c79dcb7e3cd170637e09d7b9d4d2e59a19a2d 100644 --- a/trainer/src/macaon_train.cpp +++ b/trainer/src/macaon_train.cpp @@ -43,6 +43,8 @@ po::options_description getOptionsDescription() ("printEntropy", "Print mean entropy and standard deviation accross sequences") ("dicts", po::value<std::string>()->default_value(""), "The .dict file describing all the dictionaries to be used in the experiement. By default the filename specified in the .tm file will be used") + ("featureModels", po::value<std::string>()->default_value(""), + "For each classifier, specify what .fm (feature model) file to use. By default the filename specified in the .cla file will be used. Example : --featureModel Parser=parser.fm,Tagger=tagger.fm") ("optimizer", po::value<std::string>()->default_value("amsgrad"), "The learning algorithm to use : amsgrad | adam | sgd") ("loss", po::value<std::string>()->default_value("neglogsoftmax"), @@ -273,6 +275,21 @@ int main(int argc, char * argv[]) ProgramParameters::dynamicProbability = vm["proba"].as<float>(); ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>(); ProgramParameters::iterationSize = vm["iterationSize"].as<int>(); + std::string featureModels = vm["featureModels"].as<std::string>(); + if (!featureModels.empty()) + { + auto byClassifiers = split(featureModels, ','); + for (auto & classifier : byClassifiers) + { + auto parts = split(classifier, '='); + if (parts.size() != 2) + { + fprintf(stderr, "ERROR (%s) : wrong format for argument of option featureModels. Aborting.\n", ERRINFO); + exit(1); + } + ProgramParameters::featureModelByClassifier[parts[0]] = parts[1]; + } + } if (ProgramParameters::nbTrain) { diff --git a/transition_machine/src/Classifier.cpp b/transition_machine/src/Classifier.cpp index 88b1cd690087e1817a2077de137b616370877e6b..59d6d4a037820b4d4b40dace28f9c22d9f38ca71 100644 --- a/transition_machine/src/Classifier.cpp +++ b/transition_machine/src/Classifier.cpp @@ -55,7 +55,12 @@ Classifier::Classifier(const std::string & filename, bool trainMode) if(fscanf(fd, "Feature Model : %s\n", buffer) != 1) badFormatAndAbort(ERRINFO); - fm.reset(new FeatureModel(ProgramParameters::expPath + buffer)); + std::string fmFilename = ProgramParameters::expPath + buffer; + + if (ProgramParameters::featureModelByClassifier.count(this->name)) + fmFilename = ProgramParameters::featureModelByClassifier[this->name]; + + fm.reset(new FeatureModel(fmFilename)); if(fscanf(fd, "Action Set : %s\n", buffer) != 1) badFormatAndAbort(ERRINFO);