The GPT tokenizer
I am currently dissecting microgpt in order to gain a deep understanding of how GPTs work.
A GPT model only works on numbers. This means the input text - both in training and generating - has to be first converted into numbers the GPT can use. This process is known as tokenisation and is done by a tokeniser.
microgpt uses the most simple type of tokeniser - it simply assigns a number to each character. microgpt does this by getting a list of all the characters used in each name, removing the duplicates and then sorting them. The index of each character then becomes its token number. This means "a" = 0, "b" = 1 and "c" = 2 etc.
In addition to assigning a number to all the unique characters used in the names, microgpt adds a special beginning-of-sequence token which also doubles as an end-of-sequence token, to mark the beginning and end of each document.
In the microgpt project a document is a name such as "bob".
When generating a name using the predict, pick, append loop I described in my GPT overview post, the document being generated is seeded with the beginning-of-sequence character.
It is worth pointing out that in other GPTs, the tokens may map to multiple characters, for example:
the,froat- etc.
microgpt is just trying to use the simplest approach possible.