diff --git a/MLP/include/MLP.hpp b/MLP/include/MLP.hpp index e0637b9cee0bec98bdd9aff44c0e1332da1deddb..7713815f3fbe8d6b9b31e7097f306a2fd41f1c75 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 609484a141c5d11f8ffe161afac742d136645eac..0c1238595c3e3dc32b30f1987c9fda47c508ace5 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 bdecd652adb5a9adeaa58e0d3a00b8ae3b9f0795..f362db5ea8bde0e58eab5839e1cda59141c93696 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);