· By Jody in GPT Internals —

What is a GPT? A high-level overview

GPT stands for Generative Pre-trained Transformer:

  • Generative - because it generates text.
  • Pre-trained - because it is trained on a pile of text before it is asked a question.
  • Transformer - because this is the type of neural network it uses internally.

How a GPT generates text

A GPT at its core is a stateless function that takes a list of tokens as its input, and then outputs a list of all the tokens the GPT will allow, each scored with its probability of coming next.

A token is just a fragment of text represented by a number. The set of tokens that a GPT will allow is known as its vocabulary. Different GPTs can have different tokens and vocabularies.

The GPT function is typically run in a loop with the following steps:

  • Predict - the GPT function using the current input tokens returns its scored vocabulary.
  • Pick - a token is usually randomly picked weighted by its score.
  • Append - the picked token is added to the end of the input tokens.

The loop will stop when it outputs a special end-of-sequence token, which marks the end of a document.

Training and tokenisation

When a GPT is trained, it is trained on a set of documents. For microgpt these documents are names (such as "bob", "dave" or "liz"). Large high-end GPTs will use books and web pages as their documents.

In order for a GPT to consume a document during training, it must first convert these documents into a sequence of tokens. This is done by the tokeniser.

A GPT's tokeniser can define tokens and vocabularies in different ways. For example, one GPT might define tokens as single characters; another might group several characters together.

microgpt has a very simple vocabulary, which comprises all the lowercase letters plus a special beginning-of-sequence token - which is also used as an end-of-sequence token. In other words, all the tokens required to output a name.