MCPcopy Create free account
hub / github.com/FastFlowLM/FastFlowLM / Tokenizer

Method Tokenizer

src/common/tokenizer/tokenizer.cpp:17–48  ·  view source on GitHub ↗

\brief Constructor \param model_path the model path

Source from the content-addressed store, hash-verified

15/// \brief Constructor
16/// \param model_path the model path
17Tokenizer::Tokenizer(const std::string& model_path) {
18 #ifdef _WIN32
19 std::ifstream fs(model_path + "\\tokenizer.json", std::ios::in | std::ios::binary);
20 #else
21 std::ifstream fs(model_path + "/tokenizer.json", std::ios::in | std::ios::binary);
22 #endif
23 if (fs.fail()) {
24 #ifdef _WIN32
25 std::cerr << "Cannot open " << model_path + "\\tokenizer.json" << std::endl;
26 #else
27 std::cerr << "Cannot open " << model_path + "/tokenizer.json" << std::endl;
28 #endif
29 exit(1);
30 }
31 std::string data;
32 fs.seekg(0, std::ios::end);
33 size_t size = static_cast<size_t>(fs.tellg());
34 fs.seekg(0, std::ios::beg);
35 data.resize(size);
36 fs.read(data.data(), size);
37 this->tokenizer = tokenizers::Tokenizer::FromBlobJSON(data);
38 fs.close();
39 std::string decoder_type;
40 nlohmann::json data_json = nlohmann::json::parse(data);
41 JSON_GET(decoder_type, data_json["decoder"], "type", "ByteLevel", std::string);
42 if (decoder_type == "ByteLevel") {
43 this->is_doubled_encoded = true;
44 }
45 else {
46 this->is_doubled_encoded = false;
47 }
48}
49
50/// \brief Destructor
51Tokenizer::~Tokenizer() = default;

Callers

nothing calls this directly

Calls 3

parseFunction · 0.85
resizeMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected