Answers.Body: <p>LLMs like GPT family use tokenizing to transform text into numbers. GPT models offered by OpenAI don't use separate tokens for each letter. Instead, they split the words into commonly occurring, short parts. Like <code>backpack</code> into <code>back</code> and <code>pack</code>.</p>
  <p>You can check the tokenizing <a href="https://platform.openai.com/tokenizer" rel="nofollow noreferrer">on OpenAI website</a> and in <a href="https://github.com/openai/tiktoken/tree/main" rel="nofollow noreferrer">tiktoken library</a>.</p>
  <p>When plugging the long english texts into tiktoken, I didn't observe any tokens in English that resulted in numbers higher than 100,000. This may suggest that there is around 100,000 different tokens in English.</p>
  <p>There is a high chance, that the models learned the length and the order of letters in each of these tokens, in exactly the same manner that they've learned other things.</p>
  <p>GPT-3.5 struggled with tasks regarding text structure (like length of the words), GPT-4 performs a bit better - this may result from further aligning and fine-tuning the model on datasets that force the model to learn the letters and lengths of each token.</p>
  <p>GPT-3.5 struggling with counting the letters:
  <a href="https://i.sstatic.net/m0Kn6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/m0Kn6.png" alt="enter image description here" /></a></p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-11-11T09:34:02.357Z
Answers.LastActivityDate: 2023-11-11T09:34:02.357Z
Answers.UserDisplayName: Jakub Podolak
Answers.Body: <p>It's actually tokenizing each letter. That is the reason why asking it to count the number of letters in more than a few words will result in basically a guessing game, and it will more often than not result in wrong answers.</p>
  <p>Now, if you prompt it to follow a more resource demanding methodology (1) identify the words one by one of x text, (2) then number each letter within the identified words, (3) then summarize the numbers of letters within that particular word, then (4) start over with the next word and (5) continue until you reach to the under of the text, then it will only be able to process maybe 10 to 15 average length words. It has to express the steps in concepts (tokens) including every single letter, then associating a number to that etc.</p>
  <p>When you do the above, you will experience GPT-4 either simply cutting the cr—p, and saying, &quot;[a]nd this is how you continue until you finish&quot;, or if you keep insisting that it go through the entirety of text x, then it will run out of tokens, and leave production unfinished—when you have to prompt again &quot;Continue&quot;, or &quot;carry on&quot;, etc.</p>
  <p>This would either mean that GPT-4 in ChatGPT does not actually have 4,096 tokens (it does!), or that doing these tasks are extremely token demanding.</p>
  <p>This is a high-level understanding of the issue, but it generally points at the fact that it doesn't work it out from a pre-existing &quot;database&quot; that was sort of hardcoded in the model; it doesn't call the result which is actually shown in the initial wrong answers when it sort of guesses instead of following a strict methodology to avoid errors. (If it did have that, the initial answer would be correct, and it wouldn't be so resource-demanding to actually run the &quot;math&quot; through this task.)</p>
  <p>If needed, I can provide an entire example chat of this behavior.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-22T01:36:19.147Z
Answers.Text: “It's actually tokenizing each letter”—where did you get this from? I find it [unlikely](https://en.wikipedia.org/wiki/Byte_pair_encoding).
Answers.UserDisplayName: HelloGoodbye
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-24T17:36:37.683Z
Answers.Text: It is so when it tries to count the letters, not generally.
Answers.UserDisplayName: Raiden Snaker
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-08-25T19:06:00.850Z
Answers.Text: Well, the language model doesn’t decide itself how the tokenization should happen, and the tokenizer doesn’t know whether the language model is trying to count letters, so that cannot be the case.
Answers.UserDisplayName: HelloGoodbye
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-05-16T09:30:32.467Z
Answers.LastActivityDate: 2023-05-16T09:30:32.467Z
Answers.UserDisplayName: Raiden Snaker
Body: <p>I understand that GPT models process input text by converting words into tokens and then embedding vectors and do not process them letter by letter. Given this approach, I am curious to know how a model like ChatGPT can identify the first (or n-th) letter of a given word. Can anyone explain the underlying mechanism or provide any insights on this capability?</p>
  <p><a href="https://i.sstatic.net/qZNNx.png" rel="noreferrer"><img src="https://i.sstatic.net/qZNNx.png" alt="enter image description here" /></a>
  <a href="https://i.sstatic.net/2hGyg.png" rel="noreferrer"><img src="https://i.sstatic.net/2hGyg.png" alt="enter image description here" /></a></p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-24T07:32:16.493Z
Comments.Text: Please check the 'how can a transformer do X' section of the following post: https://ai.stackexchange.com/questions/40179/how-does-a-transformer-or-large-language-model-work/40180#40180.
Comments.UserDisplayName: Robin van Hoorn
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-25T04:53:27.987Z
Comments.Text: @user253751 I edited the post. Do you believe there is a list on the web indicating that "L" is the fourth word of "agglutinoid"?
Comments.UserDisplayName: Peyman
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-25T05:08:01.243Z
Comments.Text: I bet not. Thus, two possible options are: character processing, before or in parallel to tokenizing; data augmentation of the corpus, with generation of about one million sentences of the form "The <nth> letter of <word w> is <letter l>". About one million would come from about say 100000 words x 10 characters/word.
Comments.UserDisplayName: Jaume Oliver Lafont
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-25T05:16:28.973Z
Comments.Text: A more involved approach would come from using some positional encoding of words, if say "cab" was encoded as 3x27^2+1×27+2. The operation nth letter would require integer division and modulo operation on this number equivalent of the word.
Comments.UserDisplayName: Jaume Oliver Lafont
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2023-04-26T05:20:56.610Z
Comments.Text: So? What are your thoughts about the question? In particular, do you think there are resources where "agglutinoid" is listed to have an L in fourth position?
Comments.UserDisplayName: Jaume Oliver Lafont
Tags: <natural-language-processing><chatgpt><gpt><natural-language-understanding><language-model>
Title: How does GPT-based language model like ChatGPT determine the n-th letter of a word?
UserDisplayName: Peyman
ThreadText: # How does GPT-based language model like ChatGPT determine the n-th letter of a word?
  
  (Asked by: username_0 on 2023-04-23)
  
  I understand that GPT models process input text by converting words into tokens and then embedding vectors and do not process them letter by letter. Given this approach, I am curious to know how a model like ChatGPT can identify the first (or n-th) letter of a given word. Can anyone explain the underlying mechanism or provide any insights on this capability?
  
  [![enter image description here](https://i.sstatic.net/qZNNx.png)](https://i.sstatic.net/qZNNx.png)
  [![enter image description here](https://i.sstatic.net/2hGyg.png)](https://i.sstatic.net/2hGyg.png)
  
  **Tags:** natural-language-processing, chatgpt, gpt, natural-language-understanding, language-model
  > **Comments:**
  > **username_1**: Please check the 'how can a transformer do X' section of the following post: https://ai.stackexchange.com/questions/40179/how-does-a-transformer-or-large-language-model-work/40180#40180.  
  > **username_0**: @user253751 I edited the post. Do you believe there is a list on the web indicating that "L" is the fourth word of "agglutinoid"?  
  > **username_2**: I bet not. Thus, two possible options are: character processing, before or in parallel to tokenizing; data augmentation of the corpus, with generation of about one million sentences of the form "The <nth> letter of <word w> is <letter l>". About one million would come from about say 100000 words x 10 characters/word.  
  > **username_2**: A more involved approach would come from using some positional encoding of words, if say "cab" was encoded as 3x27^2+1×27+2. The operation nth letter would require integer division and modulo operation on this number equivalent of the word.  
  > **username_2**: So? What are your thoughts about the question? In particular, do you think there are resources where "agglutinoid" is listed to have an L in fourth position?  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_3 on 2023-11-11. Score: 1
  
  LLMs like GPT family use tokenizing to transform text into numbers. GPT models offered by OpenAI don't use separate tokens for each letter. Instead, they split the words into commonly occurring, short parts. Like `backpack` into `back` and `pack`.
  
  You can check the tokenizing [on OpenAI website](https://platform.openai.com/tokenizer) and in [tiktoken library](https://github.com/openai/tiktoken/tree/main).
  
  When plugging the long english texts into tiktoken, I didn't observe any tokens in English that resulted in numbers higher than 100,000. This may suggest that there is around 100,000 different tokens in English.
  
  There is a high chance, that the models learned the length and the order of letters in each of these tokens, in exactly the same manner that they've learned other things.
  
  GPT-3.5 struggled with tasks regarding text structure (like length of the words), GPT-4 performs a bit better - this may result from further aligning and fine-tuning the model on datasets that force the model to learn the letters and lengths of each token.
  
  GPT-3.5 struggling with counting the letters:
  [![enter image description here](https://i.sstatic.net/m0Kn6.png)](https://i.sstatic.net/m0Kn6.png)
  
  
  ---
  
  ### Answer by username_4 on 2023-05-16. Score: -2
  
  It's actually tokenizing each letter. That is the reason why asking it to count the number of letters in more than a few words will result in basically a guessing game, and it will more often than not result in wrong answers.
  
  Now, if you prompt it to follow a more resource demanding methodology (1) identify the words one by one of x text, (2) then number each letter within the identified words, (3) then summarize the numbers of letters within that particular word, then (4) start over with the next word and (5) continue until you reach to the under of the text, then it will only be able to process maybe 10 to 15 average length words. It has to express the steps in concepts (tokens) including every single letter, then associating a number to that etc.
  
  When you do the above, you will experience GPT-4 either simply cutting the cr—p, and saying, "[a]nd this is how you continue until you finish", or if you keep insisting that it go through the entirety of text x, then it will run out of tokens, and leave production unfinished—when you have to prompt again "Continue", or "carry on", etc.
  
  This would either mean that GPT-4 in ChatGPT does not actually have 4,096 tokens (it does!), or that doing these tasks are extremely token demanding.
  
  This is a high-level understanding of the issue, but it generally points at the fact that it doesn't work it out from a pre-existing "database" that was sort of hardcoded in the model; it doesn't call the result which is actually shown in the initial wrong answers when it sort of guesses instead of following a strict methodology to avoid errors. (If it did have that, the initial answer would be correct, and it wouldn't be so resource-demanding to actually run the "math" through this task.)
  
  If needed, I can provide an entire example chat of this behavior.
  
  > **Comments:**
  > **username_5**: “It's actually tokenizing each letter”—where did you get this from? I find it [unlikely](https://en.wikipedia.org/wiki/Byte_pair_encoding).  
  > **username_4**: It is so when it tries to count the letters, not generally.  
  > **username_5**: Well, the language model doesn’t decide itself how the tokenization should happen, and the tokenizer doesn’t know whether the language model is trying to count letters, so that cannot be the case.  
  
  ---
  
  