Added CopyTask input representation with unary representation of repeat count
This commit is contained in:
@@ -262,111 +262,22 @@ BOOST_AUTO_TEST_CASE(AddTaskTest) {
|
||||
|
||||
BOOST_REQUIRE(ok);
|
||||
}
|
||||
/*
|
||||
BOOST_AUTO_TEST_CASE(LSTMBaselineTestCopy)
|
||||
{
|
||||
ofstream fout;
|
||||
fout.open("output.log");
|
||||
fout << "Report for aligned representation.\n";
|
||||
fout << "Training epochs = " << 20 << "\n";
|
||||
int maxNRepeat[] = {10, 10, 10, 6, 4, 3, 3, 3, 2, 2, 2};
|
||||
for (size_t maxLen = 2; maxLen <= 8; ++maxLen) {
|
||||
for (size_t nRepeats = 1; nRepeats <= maxNRepeat[maxLen]; ++nRepeats) {
|
||||
bool ok = true;
|
||||
|
||||
const size_t outputSize = 1;
|
||||
const size_t inputSize = 1;
|
||||
const size_t rho = 2;
|
||||
const size_t maxRho = 128;
|
||||
|
||||
RNN<MeanSquaredError<> > model(rho);
|
||||
|
||||
model.Add<IdentityLayer<> >();
|
||||
model.Add<Linear<> >(inputSize, 30);
|
||||
model.Add<LSTM<> >(30, 15, maxRho);
|
||||
model.Add<LeakyReLU<> >();
|
||||
model.Add<Linear<> >(15, outputSize);
|
||||
model.Add<SigmoidLayer<> >();
|
||||
|
||||
Adam<decltype(model)> opt(model);
|
||||
|
||||
CopyTask task(maxLen, nRepeats);
|
||||
|
||||
arma::field<arma::colvec> trainPredictor, trainResponse;
|
||||
size_t trainSize = 15 + 5 * maxLen;
|
||||
task.Generate(trainPredictor, trainResponse, trainSize);
|
||||
size_t testSize = 15 + 5 * maxLen;
|
||||
arma::field<arma::colvec> testPredictor, testResponse;
|
||||
task.Generate(testPredictor, testResponse, testSize);
|
||||
for (size_t epoch = 0; epoch < 20; ++epoch) {
|
||||
for (size_t example = 0; example < trainPredictor.n_elem; ++example) {
|
||||
size_t totSize =
|
||||
trainPredictor.at(example).n_elem + trainResponse.at(example).n_elem;
|
||||
arma::mat predictor = arma::zeros(totSize, 1);
|
||||
predictor.col(0).rows(0,trainPredictor.at(example).n_elem-1) =
|
||||
trainPredictor.at(example);
|
||||
//predictor.col(1) = arma::ones(totSize);
|
||||
arma::mat response = arma::zeros(totSize, 1);
|
||||
response.col(0).rows(trainPredictor.at(example).n_elem,totSize-1) =
|
||||
trainResponse.at(example);
|
||||
model.Rho() = totSize;
|
||||
model.Train(predictor, response, opt);
|
||||
}
|
||||
std::cerr << "Finished running training epoch #"
|
||||
<< epoch+1 << "\n";
|
||||
}
|
||||
|
||||
arma::field<arma::colvec> modelOutput(testSize);
|
||||
for (size_t example = 0; example < testSize; ++example) {
|
||||
arma::colvec softOutput;
|
||||
size_t totSize =
|
||||
testPredictor.at(example).n_elem + testResponse.at(example).n_elem;
|
||||
arma::mat predictor = arma::zeros(totSize, 1);
|
||||
predictor.col(0).rows(0,testPredictor.at(example).n_elem-1) =
|
||||
testPredictor.at(example);
|
||||
//predictor.col(1) = arma::ones(totSize);
|
||||
model.Rho() = predictor.n_rows;
|
||||
model.Predict(
|
||||
predictor,
|
||||
softOutput);
|
||||
modelOutput.at(example) = softOutput.rows(
|
||||
testPredictor.at(example).n_elem,
|
||||
softOutput.n_rows-1);
|
||||
Binarize<double>(modelOutput.at(example), modelOutput.at(example), 0.5);
|
||||
// TODO Check this one!
|
||||
std::cerr << "Predictor:\n"
|
||||
<< predictor
|
||||
<< "Model response:\n"
|
||||
<< softOutput;
|
||||
}
|
||||
std::cerr << "Final score for ("
|
||||
<< maxLen << ","
|
||||
<< nRepeats << "): "
|
||||
<< SequencePrecision<arma::colvec>(testResponse, modelOutput)
|
||||
<< "\n";
|
||||
|
||||
fout << "Final score for ("
|
||||
<< maxLen << ","
|
||||
<< nRepeats << "): "
|
||||
<< SequencePrecision<arma::colvec>(testResponse, modelOutput)
|
||||
<< "\n";
|
||||
fout << "Sample size = " << trainSize << "\n";
|
||||
fout.flush();
|
||||
}
|
||||
}
|
||||
fout.close();
|
||||
}*/
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(LSTMBaselineTestCopyRepeatRepr)
|
||||
{
|
||||
ofstream fout;
|
||||
fout.open("output-aug.log");
|
||||
fout << "Report for augmented representation.\n";
|
||||
fout << "Training epochs = " << 20 << "\n";
|
||||
|
||||
int maxNRepeat[] = {10, 10, 10, 6, 4, 3, 3, 3, 2, 2, 2};
|
||||
for (size_t maxLen = 2; maxLen <= 8; ++maxLen) {
|
||||
for (size_t nRepeats = 1; nRepeats <= maxNRepeat[maxLen]; ++nRepeats) {
|
||||
bool ok = true;
|
||||
|
||||
const size_t outputSize = 1;
|
||||
const size_t inputSize = 1;
|
||||
const size_t inputSize = 2;
|
||||
const size_t rho = 2;
|
||||
const size_t maxRho = 128;
|
||||
|
||||
@@ -398,9 +309,8 @@ BOOST_AUTO_TEST_CASE(LSTMBaselineTestCopyRepeatRepr)
|
||||
trainPredictor.at(example);
|
||||
predictor.col(1).rows(trainPredictor.at(example).n_elem,totSize-1) =
|
||||
arma::ones(totSize-trainPredictor.at(example).n_elem);
|
||||
// You can't do this here...
|
||||
/* predictor = predictor.t();
|
||||
predictor.reshape(predictor.n_elem, 1);*/
|
||||
predictor = predictor.t();
|
||||
predictor.reshape(predictor.n_elem, 1);
|
||||
arma::mat response = arma::zeros(totSize, 1);
|
||||
response.col(0).rows(trainPredictor.at(example).n_elem,totSize-1) =
|
||||
trainResponse.at(example);
|
||||
@@ -422,10 +332,9 @@ BOOST_AUTO_TEST_CASE(LSTMBaselineTestCopyRepeatRepr)
|
||||
assert(predictor.n_rows == totSize);
|
||||
predictor.col(1).rows(testPredictor.at(example).n_elem, totSize-1) =
|
||||
arma::ones(totSize-testPredictor.at(example).n_elem);
|
||||
// ... but you *must* do it here.
|
||||
predictor = predictor.t();
|
||||
predictor.reshape(predictor.n_elem, 1);
|
||||
model.Rho() = predictor.n_rows;
|
||||
model.Rho() = totSize;
|
||||
model.Predict(
|
||||
predictor,
|
||||
softOutput);
|
||||
@@ -447,8 +356,17 @@ BOOST_AUTO_TEST_CASE(LSTMBaselineTestCopyRepeatRepr)
|
||||
<< nRepeats << "): "
|
||||
<< SequencePrecision<arma::colvec>(testResponse, modelOutput)
|
||||
<< "\n";
|
||||
|
||||
fout << "Final score for ("
|
||||
<< maxLen << ","
|
||||
<< nRepeats << "): "
|
||||
<< SequencePrecision<arma::colvec>(testResponse, modelOutput)
|
||||
<< "\n";
|
||||
fout << "Sample size = " << trainSize << "\n";
|
||||
fout.flush();
|
||||
}
|
||||
}
|
||||
fout.close();
|
||||
}
|
||||
|
||||
arma::field<arma::colvec> binarizeAdd(arma::field<arma::colvec> data) {
|
||||
|
||||
Reference in New Issue
Block a user