From 007ae6d75beccdfe434fa2a2cd73ecb46dec3d9b Mon Sep 17 00:00:00 2001 From: Franck Dary <franck.dary@etu.univ-amu.fr> Date: Wed, 8 Aug 2018 15:01:38 +0200 Subject: [PATCH] Made the random seed a parameter --- MLP/include/MLP.hpp | 3 +++ MLP/src/MLP.cpp | 4 +++- trainer/src/macaon_train.cpp | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/MLP/include/MLP.hpp b/MLP/include/MLP.hpp index e0637b9..7713815 100644 --- a/MLP/include/MLP.hpp +++ b/MLP/include/MLP.hpp @@ -37,6 +37,9 @@ class MLP SOFTMAX }; + /// @brief The seed that will be used by RNG (srand and dynet) + static int randomSeed; + /// @brief Get the string corresponding to an Activation. /// /// @param a The activation. diff --git a/MLP/src/MLP.cpp b/MLP/src/MLP.cpp index 609484a..0c12385 100644 --- a/MLP/src/MLP.cpp +++ b/MLP/src/MLP.cpp @@ -5,6 +5,8 @@ #include <dynet/param-init.h> #include <dynet/io.h> +int MLP::randomSeed = 0; + std::string MLP::activation2str(Activation a) { switch(a) @@ -175,7 +177,7 @@ std::vector<float> MLP::predict(FeatureModel::FeatureDescription & fd) dynet::DynetParams & MLP::getDefaultParams() { static dynet::DynetParams params; - params.random_seed = 100; + params.random_seed = randomSeed; std::srand(params.random_seed); diff --git a/trainer/src/macaon_train.cpp b/trainer/src/macaon_train.cpp index bdecd65..f362db5 100644 --- a/trainer/src/macaon_train.cpp +++ b/trainer/src/macaon_train.cpp @@ -44,6 +44,8 @@ po::options_description getOptionsDescription() "Number of training epochs (iterations)") ("batchsize,b", po::value<int>()->default_value(256), "Size of each training batch (in number of examples)") + ("seed,s", po::value<int>()->default_value(100), + "The random seed that will initialize RNG") ("shuffle", po::value<bool>()->default_value(true), "Shuffle examples after each iteration"); @@ -109,6 +111,7 @@ int main(int argc, char * argv[]) std::string lang = vm["lang"].as<std::string>(); int nbIter = vm["nbiter"].as<int>(); int batchSize = vm["batchsize"].as<int>(); + int randomSeed = vm["seed"].as<int>(); bool mustShuffle = vm["shuffle"].as<bool>(); const char * MACAON_DIR = std::getenv("MACAON_DIR"); @@ -121,6 +124,9 @@ int main(int argc, char * argv[]) trainFilename = expPath + trainFilename; devFilename = expPath + devFilename; + // Setting the random seed + MLP::randomSeed = randomSeed; + TransitionMachine tapeMachine(tmFilename, true, expPath); BD trainBD(BDfilename, MCDfilename); -- GitLab