MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / Train

Method Train

external/sentencepiece/src/char_model_trainer.cc:24–58  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace character {
23
24util::Status Trainer::Train() {
25 RETURN_IF_ERROR(status());
26
27 CHECK_OR_RETURN(normalizer_spec_.escape_whitespaces());
28 CHECK_EQ_OR_RETURN(TrainerSpec::CHAR, trainer_spec_.model_type());
29
30 RETURN_IF_ERROR(LoadSentences());
31
32 const int vocab_size = trainer_spec_.vocab_size() - meta_pieces_.size();
33 CHECK_GE_OR_RETURN(vocab_size, 0);
34
35 uint64_t sum = 0;
36 for (const auto &it : required_chars_) {
37 sum += it.second;
38 }
39
40 const auto logsum = std::log(static_cast<float>(sum));
41
42 CHECK_OR_RETURN(final_pieces_.empty());
43 for (const auto &it : Sorted(required_chars_)) {
44 if (!trainer_spec_.use_all_vocab() &&
45 final_pieces_.size() == static_cast<size_t>(vocab_size)) {
46 break;
47 }
48 final_pieces_.emplace_back(
49 string_util::UnicodeCharToUTF8(it.first),
50 std::log(static_cast<float>(it.second)) - logsum);
51 }
52
53 if (trainer_spec_.use_all_vocab()) {
54 trainer_spec_.set_vocab_size(final_pieces_.size() + meta_pieces_.size());
55 }
56
57 return Save();
58}
59} // namespace character
60} // namespace sentencepiece

Callers

nothing calls this directly

Calls 9

SortedFunction · 0.85
UnicodeCharToUTF8Function · 0.85
escape_whitespacesMethod · 0.80
model_typeMethod · 0.80
use_all_vocabMethod · 0.80
set_vocab_sizeMethod · 0.80
vocab_sizeMethod · 0.45
sizeMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected