diff --git a/common/src/util.cpp b/common/src/util.cpp index 2ce33306431ea96551d282fbd5c637690206ecd3..ec795d8a4218fd94a679a748558dccdbcb6eda00 100644 --- a/common/src/util.cpp +++ b/common/src/util.cpp @@ -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; diff --git a/trainer/src/MacaonTrain.cpp b/trainer/src/MacaonTrain.cpp index f4504081a8cdb5426b5bf919252ad0e9757709c9..10a7349933902b21f60f8c99f7eeb5176fd5f18e 100644 --- a/trainer/src/MacaonTrain.cpp +++ b/trainer/src/MacaonTrain.cpp @@ -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);