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

Method feed_data

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

Source from the content-addressed store, hash-verified

60
61
62int LAC::feed_data(const std::vector<std::string> &querys)
63{
64 this->_seq_words_batch.clear();
65 this->_lod[0].clear();
66
67 this->_lod[0].push_back(0);
68 long shape = 0;
69 for (size_t i = 0; i < querys.size(); ++i)
70 {
71 split_words(querys[i], this->_codetype, this->_seq_words);
72 this->_seq_words_batch.push_back(this->_seq_words);
73 shape += this->_seq_words.size();
74 this->_lod[0].push_back(shape);
75 }
76 this->_input_tensor->Resize({shape, 1});
77 this->_input_tensor->SetLoD(this->_lod);
78
79 int64_t *input_d = this->_input_tensor->mutable_data<int64_t>();
80 int index = 0;
81 for (size_t i = 0; i < this->_seq_words_batch.size(); ++i)
82 {
83 for (size_t j = 0; j < this->_seq_words_batch[i].size(); ++j)
84 {
85 /* normalization */
86 std::string word = this->_seq_words_batch[i][j];
87 auto q2b_iter = this->_q2b_dict->find(word);
88 if (q2b_iter != this->_q2b_dict->end())
89 {
90 word = q2b_iter->second;
91 }
92
93 /* get word_id */
94 int64_t word_id = this->_oov_id; // OOV word
95 auto word_iter = this->_word2id_dict->find(word);
96 if (word_iter != this->_word2id_dict->end())
97 {
98 word_id = word_iter->second;
99 }
100 input_d[index++] = word_id;
101 }
102 }
103 return 0;
104}
105
106/* 对输出的标签进行解码转换为模型输出格式 */
107int LAC::parse_targets(

Callers 1

lexerMethod · 0.95

Calls 1

split_wordsFunction · 0.70

Tested by

no test coverage detected