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

improved print

parent b9cd4b4e
No related branches found
No related tags found
No related merge requests found
...@@ -111,13 +111,12 @@ std::string util::shrink(std::string s, int printedSize) ...@@ -111,13 +111,12 @@ std::string util::shrink(std::string s, int printedSize)
try try
{ {
float value = std::stof(s); 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 &) {} catch (std::exception &) {}
if (printedLength(s) <= printedSize)
return s;
auto splited = splitAsUtf8(s); auto splited = splitAsUtf8(s);
std::string result; std::string result;
......
...@@ -168,7 +168,6 @@ int MacaonTrain::main() ...@@ -168,7 +168,6 @@ int MacaonTrain::main()
Decoder decoder(machine); Decoder decoder(machine);
float bestDevScore = computeDevScore ? -std::numeric_limits<float>::max() : std::numeric_limits<float>::max(); 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"; auto trainInfos = machinePath.parent_path() / "train.info";
...@@ -255,16 +254,22 @@ int MacaonTrain::main() ...@@ -255,16 +254,22 @@ int MacaonTrain::main()
std::string devScoresStr = ""; std::string devScoresStr = "";
float devScoreMean = 0; float devScoreMean = 0;
int totalLen = 0;
std::string toAdd;
for (auto & score : devScores) for (auto & score : devScores)
{ {
if (computeDevScore) 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 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; devScoreMean += score.first;
devScoresStr += toAdd;
totalLen += util::printedLength(score.second) + 3;
} }
if (!devScoresStr.empty()) if (!devScoresStr.empty())
devScoresStr.pop_back(); devScoresStr.pop_back();
devScoresStr = fmt::format("{:{}}", devScoresStr, totalLen+7*devScores.size());
devScoreMean /= devScores.size(); devScoreMean /= devScores.size();
if (computeDevScore) if (computeDevScore)
...@@ -282,7 +287,7 @@ int MacaonTrain::main() ...@@ -282,7 +287,7 @@ int MacaonTrain::main()
if (printAdvancement) if (printAdvancement)
fmt::print(stderr, "\r{:80}\r", ""); 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); fmt::print(stderr, "{}\n", iterStr);
std::FILE * f = std::fopen(trainInfos.c_str(), "a"); std::FILE * f = std::fopen(trainInfos.c_str(), "a");
fmt::print(f, "{}\t{}\n", iterStr, devScoreMean); fmt::print(f, "{}\t{}\n", iterStr, devScoreMean);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment