| 918 | } |
| 919 | |
| 920 | static std::vector<size_t> unicode_regex_split_custom(const std::string & text, const std::string & regex_expr, const std::vector<size_t> & offsets) { |
| 921 | std::vector<size_t> bpe_offsets; |
| 922 | |
| 923 | if (regex_expr == "'s|'t|'re|'ve|'m|'ll|'d| ?\\p{L}+| ?\\p{N}+| ?[^\\s\\p{L}\\p{N}]+|\\s+(?!\\S)") { |
| 924 | bpe_offsets = unicode_regex_split_custom_gpt2(text, offsets); |
| 925 | } else if ( |
| 926 | regex_expr == "(?i:'s|'t|'re|'ve|'m|'ll|'d)|[^\\r\\n\\p{L}\\p{N}]?\\p{L}+|\\p{N}{1,3}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+" || |
| 927 | regex_expr == "(?:'[sS]|'[tT]|'[rR][eE]|'[vV][eE]|'[mM]|'[lL][lL]|'[dD])|[^\\r\\n\\p{L}\\p{N}]?\\p{L}+|\\p{N}{1,3}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+") { |
| 928 | bpe_offsets = unicode_regex_split_custom_llama3(text, offsets); |
| 929 | } else if ( |
| 930 | regex_expr == "(?:'[sS]|'[tT]|'[rR][eE]|'[vV][eE]|'[mM]|'[lL][lL]|'[dD])|[^\\r\\n\\p{L}\\p{N}]?\\p{L}+|\\p{N}| ?[^\\s\\p{L}\\p{N}]+[\\r\\n]*|\\s*[\\r\\n]+|\\s+(?!\\S)|\\s+") { |
| 931 | bpe_offsets = unicode_regex_split_custom_qwen2(text, offsets); |
| 932 | } else if (regex_expr == "\\p{Han}+") { |
| 933 | // K2's first pattern - handle all K2 patterns together |
| 934 | bpe_offsets = unicode_regex_split_custom_kimi_k2(text, offsets); |
| 935 | } else if (regex_expr == "\\p{AFMoE_digits}") { |
| 936 | // AFMOE digit pattern - use custom implementation for proper splitting |
| 937 | bpe_offsets = unicode_regex_split_custom_afmoe(text, offsets); |
| 938 | } else if (regex_expr == "[^\\n]+|[\\n]+") { |
| 939 | bpe_offsets = unicode_regex_split_custom_newlines(text, offsets); |
| 940 | } else if (regex_expr == "\\d{1,3}(?=(?:\\d{3})*\\b)") { |
| 941 | // tiny_aya digit grouping pattern from tokenizer.json: |
| 942 | // {"type": "Split", "pattern": {"Regex": "\\d{1,3}(?=(?:\\d{3})*\\b)"}, "behavior": "Isolated"} |
| 943 | // Splits digits into groups of 3 from the right (e.g., 1234567 -> 1, 234, 567) |
| 944 | // TODO: Revisit this regex, in case there are any subtle tokenization differences with the original regex. |
| 945 | bpe_offsets = unicode_regex_split_custom_afmoe(text, offsets); |
| 946 | } |
| 947 | |
| 948 | return bpe_offsets; |
| 949 | } |
| 950 | |
| 951 | // |
| 952 | // interface |
no test coverage detected