From the training data, it determines the is the most likely next word, then from there, lazy, etc. And Chat GPT is basically that at scale after we dumped the internet into it for reasons which escape me.