each penalized token once with its count among the last n of seq
| 85 | namespace { |
| 86 | // each penalized token once with its count among the last n of seq |
| 87 | std::vector<std::pair<int, int>> window_counts(const std::vector<int>& seq, int n) { |
| 88 | std::vector<std::pair<int, int>> out; |
| 89 | const size_t start = seq.size() > (size_t) n ? seq.size() - n : 0; |
| 90 | for (size_t i = start; i < seq.size(); ++i) { |
| 91 | if (seq[i] >= Engine::IMAGE_TOK) continue; // image cells are not vocabulary tokens |
| 92 | auto it = std::find_if(out.begin(), out.end(), [&](const std::pair<int, int>& c) { return c.first == seq[i]; }); |
| 93 | if (it == out.end()) out.emplace_back(seq[i], 1); |
| 94 | else ++it->second; |
| 95 | } |
| 96 | return out; |
| 97 | } |
| 98 | } // namespace |
| 99 | |
| 100 | Engine::Penalties::Row penalty_row(const std::vector<int>& seq, const Sampling& s) { |
no test coverage detected