| 194 | } |
| 195 | |
| 196 | static std::vector<std::string> unicode_byte_encoding_process(const std::vector<std::string> & bpe_words) { |
| 197 | std::vector<std::string> bpe_encoded_words; |
| 198 | for (const auto & word : bpe_words) { |
| 199 | std::string text_utf; |
| 200 | auto utf_word = unicode_cpts_from_utf8(word); |
| 201 | for (size_t i = 0; i < utf_word.size(); ++i) { |
| 202 | text_utf += unicode_cpt_to_utf8(utf_word[i]); |
| 203 | } |
| 204 | |
| 205 | std::string encoded_token; |
| 206 | for (char & c : text_utf) { |
| 207 | encoded_token += unicode_byte_to_utf8(c); |
| 208 | } |
| 209 | bpe_encoded_words.emplace_back(encoded_token); |
| 210 | } |
| 211 | return bpe_encoded_words; |
| 212 | } |
| 213 | |
| 214 | // GPT2 system regex: 's|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+ |
| 215 | static std::vector<size_t> unicode_regex_split_custom_gpt2(const std::string & text, const std::vector<size_t> & offsets) { |
no test coverage detected