How ChatGPT learns and why it sometimes gets things wrong