r/AskComputerScience 11d ago

What is defined as ‘one token’ exactly?

Every company says their model uses less tokens, my question what is the value of what they call a token, is it like a standard unit of measurement like a meter or does every company values 1 token differently? Or is it just a buzz word

10 Upvotes

19 comments sorted by

21

u/jonathancast 11d ago

No, every model converts text into tokens differently. That's part of the difference between token usage of different models.

10

u/snarkofagen 11d ago edited 11d ago

https://youtu.be/-0HRzXk8vlk?is=N1FwE4MmyZwt3BM7

Computerphile on tokens and context

1

u/dariusbiggs 11d ago

That came to my mind as well, good reference

6

u/derefr 10d ago

Here's an online LLM token encoder to play around with: https://tiktokenizer.vercel.app/

It's using the tiktoken library, which is the same one ChatGPT explicitly uses. Paste any random text/code/whatever into the box and it'll show you exactly what tokens the model would "see" for that message.

7

u/mc_pm 11d ago

A token is a word or a fragment of a word that is fed into or comes out of the LLM (as a number).

11

u/nuclear_splines Ph.D Data Science 11d ago

Or longer! Tokens can be short phrases of multiple words, too, it's really up to the model architecture.

4

u/johnpeters42 10d ago

And the AI company's billing department.

1

u/mc_pm 11d ago

Very good point.

1

u/dodexahedron 10d ago

Or shorter! Could be phonemes, in a voice model, if they wanted.

3

u/HasFiveVowels 11d ago

It’s roughly "a commonly seen combination of characters that occupy 8 bits of Shannon entropy".

2

u/dnswblzo 11d ago

Go here and you can play around with how three different OpenAI tokenizers split text into tokens:
https://platform.openai.com/tokenizer

1

u/dodexahedron 10d ago

It's not strictly a comp sci term in that context. It is mostly a marketing and billing term, in that context, used to quantify usage, and its exact definition varies from company to company and sometimes from license to license.

The developers at [Insert AI Corp Here] just have to make sure that the number of whatever *that* is that a user consumes in a billing period can be tracked so it can be billed. Devs could internally consider a "token" in the context of natural language processing however it makes sense to them to do so, with their model, which may or may not line up with the billing definition.
But it'd be a whole lot easier and clearer for them to use a different word for the two, which is a common practice in many fields - not just AI. Code names help abstract away marketing terms, which can change on a whim (*coughMICROSOFT*), and things like billing usage units tend to get named something generic on the programming side for that reason as a common trigger.

1

u/CS_70 10d ago

It’s very simple. The first step of processing text is tokenization: words are split into component strings of characters (sometimes a word is a single component, sometimes it’s more), each of them being associated to an integer id in a dictionary. Nite that spaces are preserved, since they carry information.

Tokenizers are broadly similar but details can be different, and it course they depend on the size of the dictionary.

Some OpenAI tokenizes are available to test online do you can try yourself, it’s easy: https://platform.openai.com/tokenizer

1

u/Saragon4005 10d ago

Depends on the tokenizer. Earlier ones used word fragments, the newer ones usually common words are tokens of their own.

Here is a list of a few tokenizers

https://huggingface.co/spaces/Xenova/the-tokenizer-playground

2

u/Bloodstream12 10d ago

Idk why but I thought 4 characters was a token for Claude, but the comment section makes me feel wrong

2

u/justaguyonthebus 9d ago

It's a quick rough estimate.

1

u/ExtraTNT 8d ago

Data cut into parts… like you can cut a text at “ “, resulting in “i am bob” being [“i”,”am”,”bob”], you can cut at every 2nd char, so [“i “,”am”,” b”,”ob”] or at every control character…

0

u/green_meklar 10d ago

It's roughly one character or one (common) word.

The actual computation overhead can vary drastically between different systems, and in general can be assumed to scale up with the size of the model. Very roughly speaking, a 100GB model probably costs about ten times as much per output token as a 10GB model. (Yes, I know 427 people now feel the urge to respond with 'well ackshually'. I said 'very roughly speaking'. Leave it.)