Show HN: LLaMA 3 tokenizer runs in the browser
belladoreai.github.io
Show HN: LLaMA 3 tokenizer runs in the browser
1–10 of 13 posts
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#2Re: Show HN: LLaMA 3 tokenizer runs in the browser
#3Also occasionally a space appears as a capital G (in Chrome)
Probably a minor issue. Question: Is there a special ruleset that llama3 follows that other LMs don't as far as what qualifies as a token?
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#4I'm not sure it's working correctly, I entered the word "what" and it says "4 characters, 3 tokens", I type a space and it says "4 tokens" - shouldn't it just be 1 token? and the space shouldn't count in this case? Also occasionally a space appears as a capital G (in Chrome) Probably a minor issue. Question: Is there a special ruleset that llama3 follows that other LMs don't as far as what qualifies as a token?
When you enter the word "what", the 3 tokens were: start-of-string token, the token "what", and end-of-string token. I made a change now to hide the special start-of-string and end-of-string tokens so that the visualization is a bit simplified.
Adding a space to input changes the tokenization of the input. Sometimes the resulting token count is the same (if the space is merged into some other text), sometimes the resulting token count increases by one (if the space does not get merged).
That part of the tokenizer is working correctly.
> Also occasionally a space appears as a capital G (in Chrome)
Fixed, thanks for reporting! This is a fork of my earlier tokenizer for LLaMA 1 and the demo visualizer had special handling for tokens 0-256 in LLaMA 1. This LLaMA 3 tokenizer doesn't have same special tokens, so some tokens would be visualized in a weird way (like that G thing you reported). I removed that special handling now and it fixed the visualization issue.
> Question: Is there a special ruleset that llama3 follows that other LMs don't as far as what qualifies as a token?
Different models use different tokenization schemes. Most models use some kind of variant of Byte Pair Encoding, trained with their data (the tokenizer itself is also trained, not only the language model).
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#5I'm not sure it's working correctly, I entered the word "what" and it says "4 characters, 3 tokens", I type a space and it says "4 tokens" - shouldn't it just be 1 token? and the space shouldn't count in this case? Also occasionally a space appears as a capital G (in Chrome) Probably a minor issue. Question: Is there a special ruleset that llama3 follows that other LMs don't as far as what qualifies as a token?
> I'm not sure it's working correctly, I entered the word "what" and it says "4 characters, 3 tokens", I type a space and it says "4 tokens" - shouldn't it just be 1 token? and the space shouldn't count in this case? When you enter the word "what", the 3 tokens were: start-of-string token, the token "what", and end-of-string token. I made a change now to hide the special start-of-string and end-of-string tokens so th…
> Different models use different tokenization schemes
Curious then why this is called "LLaMA 3 tokenizer" what does it have to do with llama3?
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#6Earlier quoted context omitted.
> I'm not sure it's working correctly, I entered the word "what" and it says "4 characters, 3 tokens", I type a space and it says "4 tokens" - shouldn't it just be 1 token? and the space shouldn't count in this case? When you enter the word "what", the 3 tokens were: start-of-string token, the token "what", and end-of-string token. I made a change now to hide the special start-of-string and end-of-string tokens so th…
Hm I had not heard of tokenizing like that, typically it's just words or occasionally a word + some adjacent stuff like a punctuation or space. "What " might be a different token than "What" but the total token count shouldn't increment, would just be a different token, right? > Different models use different tokenization schemes Curious then why this is called "LLaMA 3 tokenizer" what does it have to do with llama3?
The input string "What" (without trailing space) tokenizes into 1 token. The input string "What " tokenizes into 2 tokens. In theory, one might have a tokenizer that would simply tokenize "What " into a single token, but the actual tokenizers we have will tokenize that into at least 2 tokens.
> Curious then why this is called "LLaMA 3 tokenizer" what does it have to do with llama3?
When you input text into any of the LLaMA 3 models, the first step in the process is tokenizing your input. This library is called "LLaMA 3 tokenizer", because it produces the same tokenization as the official LLaMA 3 repo.
When I said that different models use different tokenization schemes, I am talking in comparison to other models, such as LLaMA 1, or GPT-4. Different models use different tokenizers, so the same text is tokenized into different tokens depending on if you're using GPT-4 or LLaMA 3 or what not.
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#7Re: Show HN: LLaMA 3 tokenizer runs in the browser
#8Really good. I am actually using js-tiktokken and wish there was a package to handle all the other LLMs also but still something I can work with.
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#9Earlier quoted context omitted.
Hm I had not heard of tokenizing like that, typically it's just words or occasionally a word + some adjacent stuff like a punctuation or space. "What " might be a different token than "What" but the total token count shouldn't increment, would just be a different token, right? > Different models use different tokenization schemes Curious then why this is called "LLaMA 3 tokenizer" what does it have to do with llama3?
> "What " might be a different token than "What" but the total token count shouldn't increment, would just be a different token, right? The input string "What" (without trailing space) tokenizes into 1 token. The input string "What " tokenizes into 2 tokens. In theory, one might have a tokenizer that would simply tokenize "What " into a single token, but the actual tokenizers we have will tokenize that into at least…
I just read about how both sentencepiece and tiktoken tokenize.
Thanks for making this (in JavaScript no less!) and putting it online! I'm going to use it in my auto-completion library (here: https://github.com/bennyschmidt/next-token-prediction/blob/m...) instead of just `.split(' ')` as I'm pretty sure it will be more nuanced :)
Awesome work!
Re: Show HN: LLaMA 3 tokenizer runs in the browser
#10Really good. I am actually using js-tiktokken and wish there was a package to handle all the other LLMs also but still something I can work with.
If you need to work with multiple LLMs, you probably want to use transformers.js