The GPT-4 works by using a neural network that has been trained with an enormous amount of data. The model is pre-trained on a large body of text, allowing it to understand and produce natural language. OpenAI used Internet data to train GPT-3 to generate any type of text. He was trained generatively and unsupervised.
In simple terms, he was taught to transform prompts into large amounts of appropriate text without supervision.