Skip to content
Snippets Groups Projects
Commit fe8a3033 authored by Franck Dary's avatar Franck Dary
Browse files

Added a program option to randomly mask part of a tape

parent 52974429
Branches
No related tags found
No related merge requests found
......@@ -55,6 +55,10 @@ po::options_description getOptionsDescription()
"The maximal size of each Dict (number of differents embeddings).")
("interactive", po::value<bool>()->default_value(true),
"Is the shell interactive ? Display advancement informations")
("tapeToMask", po::value<std::string>()->default_value("FORM"),
"The name of the Tape for which some of the elements will be masked.")
("maskRate", po::value<float>()->default_value(0.0),
"The rate of elements of the Tape that will be masked.")
("lang", po::value<std::string>()->default_value("fr"),
"Language you are working with");
......@@ -154,6 +158,8 @@ int main(int argc, char * argv[])
ProgramParameters::dictCapacity = vm["dictCapacity"].as<int>();
ProgramParameters::beamSize = vm["beamSize"].as<int>();
ProgramParameters::nbChilds = vm["nbChilds"].as<int>();
ProgramParameters::tapeToMask = vm["tapeToMask"].as<std::string>();
ProgramParameters::maskRate = vm["maskRate"].as<float>();
ProgramParameters::optimizer = "none";
std::string featureModels = vm["featureModels"].as<std::string>();
if (!featureModels.empty())
......
......@@ -63,6 +63,16 @@ class LimitedArray
data[index % data.size()].second = false;
}
void maskIndex(unsigned int index)
{
data[index % data.size()].second = true;
}
void unmaskIndex(unsigned int index)
{
data[index % data.size()].second = false;
}
int getLastIndex() const
{
return lastElementRealIndex;
......
......@@ -68,6 +68,8 @@ struct ProgramParameters
static int readSize;
static int dictCapacity;
static bool printOutputEntropy;
static std::string tapeToMask;
static float maskRate;
private :
......
......@@ -62,4 +62,6 @@ int ProgramParameters::devTapeSize;
int ProgramParameters::readSize;
bool ProgramParameters::printOutputEntropy;
int ProgramParameters::dictCapacity;
std::string ProgramParameters::tapeToMask;
float ProgramParameters::maskRate;
......@@ -81,6 +81,10 @@ po::options_description getOptionsDescription()
"The size of each minibatch (in number of taining examples)")
("dictCapacity", po::value<int>()->default_value(30000),
"The maximal size of each Dict (number of differents embeddings).")
("tapeToMask", po::value<std::string>()->default_value("FORM"),
"The name of the Tape for which some of the elements will be masked.")
("maskRate", po::value<float>()->default_value(0.0),
"The rate of elements of the Tape that will be masked.")
("printTime", "Print time on stderr")
("shuffle", po::value<bool>()->default_value(true),
"Shuffle examples after each iteration");
......@@ -289,6 +293,8 @@ int main(int argc, char * argv[])
ProgramParameters::loss = vm["loss"].as<std::string>();
ProgramParameters::dynamicEpoch = vm["epochd"].as<int>();
ProgramParameters::dynamicProbability = vm["proba"].as<float>();
ProgramParameters::tapeToMask = vm["tapeToMask"].as<std::string>();
ProgramParameters::maskRate = vm["maskRate"].as<float>();
ProgramParameters::showFeatureRepresentation = vm["showFeatureRepresentation"].as<int>();
ProgramParameters::iterationSize = vm["iterationSize"].as<int>();
std::string featureModels = vm["featureModels"].as<std::string>();
......
......@@ -126,6 +126,10 @@ class Config
/// @brief Get the last tape index that will be overriden with the next read.
int getNextOverridenRealIndex();
void setTotalEntropy(float entropy);
/// @brief Mask a cell of the tape
///
/// @param index the index to mask
void maskIndex(int index);
};
private :
......
......@@ -96,6 +96,10 @@ void Config::readInput()
tape.addToRef(cols[i]);
tape.addToHyp("");
if (tape.getName() == ProgramParameters::tapeToMask)
if (choiceWithProbability(ProgramParameters::maskRate))
tape.maskIndex(tape.refSize()-1);
}
haveRead++;
......@@ -610,3 +614,8 @@ void Config::Tape::setTotalEntropy(float entropy)
totalEntropy = entropy;
}
void Config::Tape::maskIndex(int index)
{
ref.maskIndex(index);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment