News for hackers. Stuff that matters.
Re:You Should Probably Pay Attention to Tokenizers by stephantul on Wednesday October 23, 2024 @01:09PM (#41927079)
Using subwords makes your sequences shorter, which makes them cost less.

Besides that, for alphabetic languages, there exists almost no relation between form and meaning. I.e.: “ring” and “wing” differ by one letter but have no real common meaning. By picking the character or byte as your choice of representation, the model basically has to learn to distinguish ring and wing in context. This is a lot of work!

So, while working on the character or byte level saves you some embeddings and thus makes your model smaller, it puts all of the work of distinguishing similar sequences with divergent meanings on the model itself, which means you need a larger model.

By having subwords, a part of this distinguishing work already has been done by the vocabulary itself. As the article points out, this sometimes fails.

Re:You Should Probably Pay Attention to Tokenizers by bunderbunder on Wednesday October 23, 2024 @04:08PM (#41928842)
I suspect that the holy grail here is figuring out how to break the input into a sequence of morphemes and non-morpheme lexical units.
Re:You Should Probably Pay Attention to Tokenizers by thaumasiotes on Wednesday October 23, 2024 @08:59PM (#41930854)
What do you mean by non-morpheme lexical units? Syntactic particles, units too small to be morphemes? Lexical items that contain multiple morphemes?

In either case, isn't this something we already do well?

Re:You Should Probably Pay Attention to Tokenizers by bunderbunder on Thursday October 24, 2024 @10:37AM (#41935939)
Punctuation, for example.

And no, at least for the languages with which I'm familiar SOTA tokenizers tend to only capture the easy cases.

For example, the GPT-4 tokenizer breaks the first sentence of your post like so:

  What/ do/ you/ mean/ by/ non/-m/orp/heme/ lexical/ units/?
Notice how "morpheme" gets broken into three tokens, and none of them matches "morpheme"'s two morphemes. "Lexical" and "units" are each a single token, when they have three and two morphemes respectively.

Or in French, the word "cafetière" gets chopped willy-nilly into "c/afet/ière". The canonical breakdown is "cafe/t/ière".

Re:You Should Probably Pay Attention to Tokenizers by p1esk on Wednesday October 23, 2024 @05:17PM (#41929332)
Has anyone tried to combine a token embedding with some representation of the characters in the (sub)word? For example, use a 512 long vector to represent a token, and reserve the last 12 values to spell out the word.
Re:You Should Probably Pay Attention to Tokenizers by mattnewton on Wednesday October 23, 2024 @05:45PM (#41929537)
I'm not following - spell out the word how? Like put the actual bytes as numerical input to the transformer layer?
Re:You Should Probably Pay Attention to Tokenizers by p1esk on Wednesday October 23, 2024 @07:19PM (#41930237)
Yes
Re:You Should Probably Pay Attention to Tokenizers by stephantul on Thursday October 24, 2024 @12:09AM (#41931816)
Not that I know of, but encoding orthography in a fixed width vector usually carries the assumption that words with the same prefix are more similar. So there’s an alignment problem. You usually solve this using dynamic programming, but that doesn’t work in a vector.

For example “parent” and “parents” are aligned, they share letters in the same position, but “skew” and “askew” share no letters in the same position.

Re:You Should Probably Pay Attention to Tokenizers by p1esk on Thursday October 24, 2024 @01:12AM (#41932137)
The other 500 values in the skew/askew vectors will be similar though. The 12 character values don’t need to be aligned, their function is to provide spelling. Adding such info will probably help LLM answer questions requiring character level knowledge (e.g. counting ‘r’s in ‘strawberry’).
Re:You Should Probably Pay Attention to Tokenizers by mattnewton on Thursday October 24, 2024 @02:22PM (#41938131)
Actually adding the numerical value I think is not the right way to do it because of what happens when you matmul those values - usually the right way to do it would be to have low dimensional character embeddings that are learnable in addition to the token embeddings.

The problem with pure numerical values representing a class as input to nueral network layer is that the byte encoding number is going to be very hard for the transformer to memorize exact values especially when relatively close numbers to each other often do not share much meaning. Catagories are usually encoded somehow, like a one-hot embedding layer, or more recently a learned embedding, so that these different categories can be easily distinguished (different categories are close to orthogonal).

My prediction would be that using the numerical value directly would not work at all, and using learnable embeddings would work but You would have to reserve that part of the token embedding for each token which would hurt performance a lot on non-spelling tasks relative to just letting that whole embedding represent the token however the model sees fit.

But, IDK! It would be easy enough to try! You should on a small toy model. And then try a small learnable re-usable character embedding. And write a blog post. Would be happy to coach / offer some gpu time / answer any other questions you have while building it.

Re:You Should Probably Pay Attention to Tokenizers by kadushka on Thursday October 24, 2024 @02:32PM (#41938231)
Which tasks would you test the expected improvements on from this addition?
Re:You Should Probably Pay Attention to Tokenizers by mattnewton on Thursday October 24, 2024 @02:44PM (#41938359)
maybe make a metric of "count letter $L in work $word" - if you want to game it, you can choose words so that they are all tokenized into 1-2 tokens and each token has multiples of letter $L

And then use something like helloswag to measure how much you've lost on general text completion compared to a vanilla LLM with the same embedding size all dedicated to just the token.

Re:You Should Probably Pay Attention to Tokenizers by kadushka on Thursday October 24, 2024 @02:52PM (#41938477)
Which model would you recommend to try it on? Would you train it from scratch, or finetune an existing one?
Re:You Should Probably Pay Attention to Tokenizers by mattnewton on Thursday October 24, 2024 @03:38PM (#41938957)
You would have to train the new model from scratch since it would be all new token embeddings with whatever character encoding scheme you come up with. It would probably make sense to train the vanilla gpt from scratch with the same total embeddings size as your control. I would start with https://github.com/karpathy/nanoGPT as a baseline since you can train a toy (GPT2 sized) llm in a couple days on an a100 which are pretty easy to come by.
Re:You Should Probably Pay Attention to Tokenizers by RicoElectrico on Wednesday October 23, 2024 @05:25PM (#41929378)
Well, fastText uses character n-grams to compute embeddings for out-of-vocabulary words. This is pre-transformers work BTW.
Re:You Should Probably Pay Attention to Tokenizers by p1esk on Thursday October 24, 2024 @12:07AM (#41931809)
IIRC, overlapping ngram vectors are summed to form the token embedding - doesn’t it effectively destroy any character level representation of the token? Doesn’t really make sense to me.
Re:You Should Probably Pay Attention to Tokenizers by stephantul on Thursday October 24, 2024 @12:12AM (#41931831)
It works because they use really large ngram values, up to 6. So most character-level information is in these subwords.
Re:You Should Probably Pay Attention to Tokenizers by p1esk on Thursday October 24, 2024 @01:25AM (#41932206)
Let’s say we want to use 6-grams and build an embedding vector for the word “because”: we add integer vectors for “becaus” and “ecause”, right? For example: [1,2,3,4,5,6] + [2,3,4,5,6,2] = [3,5,7,9,11,8]. Obviously we cannot use this resulting numerical vector to spell the input word. Pretty much all character level info is lost.
Re:You Should Probably Pay Attention to Tokenizers by sundarurfriend on Wednesday October 23, 2024 @05:43PM (#41929527)
> Besides that, for alphabetic languages, there exists almost no relation between form and meaning.

Also true for Abugida-based languages, for eg. சரம் (saram = string) vs மரம் (maram = tree), and many more. I think your intention with specifying "alphabetic languages" was to say "non-logographic languages", right?

Re:You Should Probably Pay Attention to Tokenizers by bunderbunder on Wednesday October 23, 2024 @06:08PM (#41929677)
I'll do you one more and say "non-Chinese languages". Written Japanese - including the kanji portion of the script - has the same characteristic.

And even in Chinese it's a fairly weak relationship. A large portion of the meanings of individual characters come from sound loan. For example the 英 in 英雄 means "hero", in 英语 means "England", an in 精英 means "flower". The relationship there is simple homophony.

On the other hand, one thing you do get with written Chinese is that "1 character = 1 morpheme" very nearly works. So mechanistically breaking a text into a sequence of morphemes can be done pretty reliably without the aid of a semantic model or exhaustive hard-coded mapping. I think that for many other languages you can't even get close using only syntactic analysis.

Re:You Should Probably Pay Attention to Tokenizers by thaumasiotes on Wednesday October 23, 2024 @08:55PM (#41930827)
> I'll do you one more and say "non-Chinese languages". Written Japanese - including the kanji portion of the script - has the same characteristic.

Written Japanese is much more ideographic than written Chinese. Japanese spelling is determined, such as it is, by semantics. Chinese spelling is determined by sound. Thus, 女的, 娘们, and 妮子, all meaning 'girl' or 'woman', have no spelling in common because they are different words, while Japanese uses 女 for "jo" and "onna" despite a total lack of any relationship between those words.

Re:You Should Probably Pay Attention to Tokenizers by bunderbunder on Thursday October 24, 2024 @11:11AM (#41936303)
Chinese spelling is also determined by meaning. 是、事、and 式 are all pronounced shì. Which one you use depends on whether you mean the copula, an event/business/matter, or a test.

I see that your examples are getting at how character components work in Chinese, but it's oversimplistic. 女(nǚ) means "woman", but 娘 (niáng) means "mother". It's composed of the functional components 女, which is just a hint at the meaning for disambiguation purposes, and 良 (liáng), which is a hint at the pronunciation. Similar for 妮 (nī) with sound component 尼 (ní) and a similar historical meaning and development to the English word "lass". In the second and third cases the 女 is a semantic functional component, but it's still a different character with a different (if similar) meaning.

re: What I said about Kanji; I don't speak the language so perhaps I misunderstand how things work. My impression was that the mapping from character to meaning was looser in Japanese than it is in Chinese.

Re:You Should Probably Pay Attention to Tokenizers by stephantul on Thursday October 24, 2024 @12:05AM (#41931796)
I was trying to say “at least for alphabetic languages”. I don’t like to say things about languages I can’t speak or write. So, no, it wasn’t my intention to say “non-logographic languages”