8
8
9
9
static std::string unescape_whitespace (llama_context* ctx, const std::vector<llama_token>& tokens) {
10
10
std::string result;
11
- for (int i = 0 ; i < tokens.size (); ++i) {
11
+ for (size_t i = 0 ; i < tokens.size (); ++i) {
12
12
result += llama_token_to_str (ctx, tokens[i]);
13
13
}
14
14
return result;
15
15
}
16
16
17
- static const std::map<std::string, std::vector<llama_token>> & k_tests ()
18
- {
17
+ static const std::map<std::string, std::vector<llama_token>> & k_tests () {
19
18
static std::map<std::string, std::vector<llama_token>> _k_tests = {
20
19
{ " " , {1 , 259 , }, },
21
20
{ " \t " , { 1 , 29871 , 12 , }, },
@@ -29,17 +28,18 @@ static const std::map<std::string, std::vector<llama_token>> & k_tests()
29
28
{ " this is 🦙.cpp" , { 1 , 29871 , 445 , 338 , 29871 , 243 , 162 , 169 , 156 , 29889 , 8223 , }, },
30
29
{ " w048 7tuijk dsdfhu" , { 1 , 281 , 29900 , 29946 , 29947 , 29871 , 29955 , 9161 , 13535 , 18031 , 2176 , 6905 , }, },
31
30
{ " нещо на Български" , { 1 , 1538 , 4851 , 665 , 1386 , 29713 , 1305 , }, },
32
- { " កាន់តែពិសេសអាចខលចេញ" , { 1 , 29871 , 31849 , 31324 , 31934 , 228 , 162 , 142 , 228 , 161 ,
33
- 146 , 228 , 162 , 133 , 228 , 161 , 153 , 228 , 161 , 186 ,
34
- 31708 , 228 , 162 , 132 , 31708 , 228 , 161 , 165 , 31324 , 228 ,
35
- 161 , 136 , 228 , 161 , 132 , 228 , 161 , 158 , 228 , 161 ,
36
- 136 , 228 , 162 , 132 , 228 , 161 , 140 , }, },
31
+ { " កាន់តែពិសេសអាចខលចេញ" , { 1 , 29871 , 31849 , 31324 , 31934 , 228 , 162 , 142 , 228 , 161 ,
32
+ 146 , 228 , 162 , 133 , 228 , 161 , 153 , 228 , 161 , 186 ,
33
+ 31708 , 228 , 162 , 132 , 31708 , 228 , 161 , 165 , 31324 , 228 ,
34
+ 161 , 136 , 228 , 161 , 132 , 228 , 161 , 158 , 228 , 161 ,
35
+ 136 , 228 , 162 , 132 , 228 , 161 , 140 , }, },
37
36
{ " 🚀 (normal) 😶🌫️ (multiple emojis concatenated) ✅ (only emoji that has its own token)" ,
38
- { 1 , 29871 , 243 , 162 , 157 , 131 , 313 , 8945 , 29897 , 29871 ,
39
- 243 , 162 , 155 , 185 , 30722 , 243 , 162 , 143 , 174 , 30598 ,
40
- 313 , 20787 , 953 , 3848 , 275 , 16125 , 630 , 29897 , 29871 , 31681 ,
41
- 313 , 6194 , 953 , 29877 , 2397 , 393 , 756 , 967 , 1914 , 5993 , 29897 , }, },
42
- };
37
+ { 1 , 29871 , 243 , 162 , 157 , 131 , 313 , 8945 , 29897 , 29871 ,
38
+ 243 , 162 , 155 , 185 , 30722 , 243 , 162 , 143 , 174 , 30598 ,
39
+ 313 , 20787 , 953 , 3848 , 275 , 16125 , 630 , 29897 , 29871 , 31681 ,
40
+ 313 , 6194 , 953 , 29877 , 2397 , 393 , 756 , 967 , 1914 , 5993 , 29897 , }, },
41
+ };
42
+
43
43
return _k_tests;
44
44
};
45
45
@@ -90,8 +90,8 @@ int main(int argc, char **argv) {
90
90
}
91
91
92
92
for (const auto & test_kv : k_tests ()) {
93
- std::vector<llama_token> res = llama_tokenize (ctx, test_kv.first . c_str () , true );
94
- fprintf (stderr, " %s : '%s' tokenized to '%s'\n " ,
93
+ std::vector<llama_token> res = llama_tokenize (ctx, test_kv.first , true );
94
+ fprintf (stderr, " %s : '%s' tokenized to '%s'\n " ,
95
95
__func__, test_kv.first .c_str (), unescape_whitespace (ctx, res).c_str ());
96
96
97
97
bool correct = res.size () == test_kv.second .size ();
0 commit comments