MCPcopy Create free account
hub / github.com/baidu/lac / LAC

Method LAC

Android/testlac/app/src/main/cpp/lac.cpp:23–59  ·  view source on GitHub ↗

LAC构造函数:初始化、装载模型和词典 */

Source from the content-addressed store, hash-verified

21
22/* LAC构造函数:初始化、装载模型和词典 */
23LAC::LAC(std::string model_dict_path, int threads, CODE_TYPE type)
24 : _codetype(type),
25 _lod(std::vector<std::vector<uint64_t> >(1)),
26 _word2id_dict(new std::unordered_map<std::string, int64_t>),
27 _q2b_dict(new std::unordered_map<std::string, std::string>),
28 _id2label_dict(new std::unordered_map<int64_t, std::string>)
29{
30 /* 装载词典 */
31 std::string word_dict_path = model_dict_path + "/word.dic";
32 load_word2id_dict(word_dict_path, *_word2id_dict);
33 std::string q2b_dict_path = model_dict_path + "/q2b.dic";
34 load_q2b_dict(q2b_dict_path, *_q2b_dict);
35 std::string label_dict_path = model_dict_path + "/tag.dic";
36 load_id2label_dict(label_dict_path, *_id2label_dict);
37 std::cout << "read word dict succeed" << std::endl;
38
39 paddle::lite_api::MobileConfig config;
40 config.set_threads(threads); // 自行设置多线程
41
42 /* 装载模型 */
43 config.set_model_from_file(model_dict_path + "/model.nb");
44 this->_predictor = paddle::lite_api::CreatePaddlePredictor(config);
45
46 std::cout << "load model succeed" << std::endl;
47
48 /* 初始化输入输出变量 */
49 this->_input_tensor = this->_predictor->GetInput(0);
50 this->_output_tensor = this->_predictor->GetOutput(0);
51 this->_oov_id = this->_word2id_dict->size() - 1;
52 auto word_iter = this->_word2id_dict->find("OOV");
53 if (word_iter != this->_word2id_dict->end())
54 {
55 this->_oov_id = word_iter->second;
56 }
57
58 std::cout << "init succeed" << std::endl;
59}
60
61
62int LAC::feed_data(const std::vector<std::string> &querys)

Callers

nothing calls this directly

Calls 3

load_word2id_dictFunction · 0.70
load_q2b_dictFunction · 0.70
load_id2label_dictFunction · 0.70

Tested by

no test coverage detected