Commit eb211b77 authored by Franck Dary's avatar Franck Dary
Browse files

improved print

parent b9cd4b4e
......@@ -111,13 +111,12 @@ std::string util::shrink(std::string s, int printedSize)
try
{
float value = std::stof(s);
s = fmt::format("{:{}.3f}", value, printedSize);
s = std::string(s.begin(), s.begin()+printedSize-1);
return fmt::format("{}{}", s, filler);
}
catch (std::exception &) {}
if (printedLength(s) <= printedSize)
return s;
auto splited = splitAsUtf8(s);
std::string result;
......
......@@ -168,7 +168,6 @@ int MacaonTrain::main()
Decoder decoder(machine);
float bestDevScore = computeDevScore ? -std::numeric_limits<float>::max() : std::numeric_limits<float>::max();
fmt::print("best = {}\n", bestDevScore);
auto trainInfos = machinePath.parent_path() / "train.info";
......@@ -255,16 +254,22 @@ int MacaonTrain::main()
std::string devScoresStr = "";
float devScoreMean = 0;
int totalLen = 0;
std::string toAdd;
for (auto & score : devScores)
{
if (computeDevScore)
devScoresStr += fmt::format("{}({:5.2f}{}),", score.second, score.first, computeDevScore ? "%" : "");
toAdd = fmt::format("{}({}{}),", score.second, util::shrink(fmt::format("{}", std::abs(score.first)),7), score.first >= 0 ? "%" : "");
else
devScoresStr += fmt::format("{}({:6.4f}{}),", score.second, 100.0*score.first, computeDevScore ? "%" : "");
toAdd = fmt::format("{}({}),", score.second, util::shrink(fmt::format("{}", 100.0*score.first),7));
devScoreMean += score.first;
devScoresStr += toAdd;
totalLen += util::printedLength(score.second) + 3;
}
if (!devScoresStr.empty())
devScoresStr.pop_back();
devScoresStr = fmt::format("{:{}}", devScoresStr, totalLen+7*devScores.size());
devScoreMean /= devScores.size();
if (computeDevScore)
......@@ -282,7 +287,7 @@ int MacaonTrain::main()
if (printAdvancement)
fmt::print(stderr, "\r{:80}\r", "");
std::string iterStr = fmt::format("[{}] Epoch {:^5} loss = {:6.4f} dev = {} {:5}", util::getTime(), fmt::format("{}/{}", currentEpoch+1, nbEpoch), 100.0*loss, devScoresStr, saved ? "SAVED" : "");
std::string iterStr = fmt::format("[{}] Epoch {:^5} loss = {:7} dev = {} {:5}", util::getTime(), fmt::format("{}/{}", currentEpoch+1, nbEpoch), util::shrink(fmt::format("{}",100.0*loss), 7), devScoresStr, saved ? "SAVED" : "");
fmt::print(stderr, "{}\n", iterStr);
std::FILE * f = std::fopen(trainInfos.c_str(), "a");
fmt::print(f, "{}\t{}\n", iterStr, devScoreMean);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment