Tokenizer supports multiple encodings, compatible with .Net Standard 2.0#218
Open
Frogley wants to merge 4 commits intobetalgo:devfrom
Open
Tokenizer supports multiple encodings, compatible with .Net Standard 2.0#218Frogley wants to merge 4 commits intobetalgo:devfrom
Frogley wants to merge 4 commits intobetalgo:devfrom
Conversation
…e encoding: r50k_base, p50k_base, cl100k_base; supports encode and decode method.
```C#
Tokenizer tokenizer = new Tokenizer("cl100k_base");
Tokenizer tokenizer = new Tokenizer().FromModelName("gpt-3.5-turbo-0301");
Tokenizer tokenizer = new Tokenizer().FromModel(Models.Model.TextDavinciV3);
string str = @"床前明月光,疑是地上霜,举头望明月,低头思故乡。";
int[] res = tokenizer.Encode(str);
// res =[ 11795 232 25580 31958 9953 6708 231 3922 163 244 239 21043 30590 17905 52597 250 3922 3574 122 65455 4916 249 31958 9953 3922 8687 236 65455 91763 8067 227 18259 94 1811]
string str2 = tokenizer.Decode(res);
// str2 = "床前明月光,疑是地上霜,举头望明月,低头思故乡。"
```
Member
|
Hey @Frogley, I haven't forgotten about your PR. I am just trying to understand how the tokenizer works and comparing it against your PR, which is taking up a lot of time. I apologize for the delay. :/ |
Author
|
Great. To be honest, my understanding of the core algorithm for the tokenizer is somewhat vague, I didn't fully grasp it. Basically, my PR is a translation of tiktoken/lib.rs from Rust into C#, with some simplifications. After the translation was complete, I did a few case tests and they were consistent. But I didn't do any extensive testing and comparison. Hope my work can be of help to you. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Tokenizer supports multiple encodings: r50k_base, p50k_base, cl100k_base; supports encode and decode method.