| | |
| | | Vocab::Vocab(const char *filename) |
| | | { |
| | | ifstream in(filename); |
| | | LoadVocabFromYaml(filename); |
| | | LoadVocabFromJson(filename); |
| | | } |
| | | Vocab::Vocab(const char *filename, const char *lex_file) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | void Vocab::LoadVocabFromJson(const char* filename){ |
| | | nlohmann::json json_array; |
| | | std::ifstream file(filename); |
| | | if (file.is_open()) { |
| | | file >> json_array; |
| | | file.close(); |
| | | } else { |
| | | LOG(INFO) << "Error loading token file, token file error or not exist."; |
| | | exit(-1); |
| | | } |
| | | |
| | | int i = 0; |
| | | for (const auto& element : json_array) { |
| | | vocab.push_back(element); |
| | | token_id[element] = i; |
| | | i++; |
| | | } |
| | | } |
| | | |
| | | void Vocab::LoadLex(const char* filename){ |
| | | std::ifstream file(filename); |
| | | std::string line; |