Instruction 02

ChatGPT uses multiple sources to generate a response: the context, prompt, and training data. In simple terms, you can think of the context and prompt as separate. However, the reality is more complex than this.

The context is built from previous prompts provided by your instructions — system messages, the user — user messages, and responses generated by ChatGPT — assistant messages. This is both beneficial and problematic. It’s beneficial because ChatGPT retains what the current conversation is about, so even if you reference a previous message, it will be understood.

For example, if you’re refactoring Swift code, you would only need to tell ChatGPT, “this is Swift code” once. Future messages about code are understood to be related to Swift.

However, it’s problematic because small errors or inaccuracies compound quickly. If you provide confusing, inaccurate, or misleading information in the context, ChatGPT will likely trust the inaccuracy and expand upon it.

It gets worse. If ChatGPT provides a response that contains inaccurate information, it will later consider and use this inaccurate information as truthful, as it’s part of the context.

Training data also plays a critical role in how hallucinations occur. Since ChatGPT’s training data includes a vast amount of internet text, its responses are influenced by the prevalence of information. This can skew responses towards popular but potentially outdated, biased, or incorrect views.

Counteracting Hallucinations

Fortunately, users and software developers have several means to minimize and prevent hallucinations.

First and foremost, write good prompts, following the tips in this lesson. This will help ChatGPT better understand what you’re asking and hoping to achieve.

Use system messages to tell ChatGPT how it should respond. For example, you can instruct it to “act as a help-desk support agent for computer problems,” and it will know to focus on technical issues. You can also use system messages to indicate how not to respond. For instance, you might say, “don’t answer any questions that aren’t related to computer issues,” which will further narrow its focus.

Combining these instructions — “Act as a help-desk support agent for computer problems and don’t answer any questions that aren’t related to computer issues” is an effective way to ensure ChatGPT concentrates solely on technical issues.

It’s also wise to limit the number of messages in a single context. For example, start a new conversation every time you need ChatGPT to improve a block of code. This prevents it from being influenced by previous code or responses. Likewise, always initiate a new conversation when changing topics. Mixing messages about programming, medicine, law, and more is a surefire way to generate hallucinations.

Lastly, consider using the latest GPT models to access the most up-to-date training data and improvements in ChatGPT. For cost-saving reasons, you might not want to use the latest models every time, as they can be significantly more expensive than older, optimized models, yet you should definitely consider using the latest, stable models for complex prompts.

Using ChatGPT to Check Itself

Quite impressively, you can also use ChatGPT to review its own outputs! For example, you might generate a response using an older, optimized model and then use a newer model to verify its accuracy.

This technique works particularly well for tasks that are mostly standardized but leave room for some creativity. Take translations as an example: you could ask an older model (e.g., GPT-3 Turbo) to translate text and then have a newer model (GPT-4 Turbo) check the translation:

  • User to GPT-3 Turbo:  Translate this text into Spanish. Don’t provide any explanation or text besides the translation: My name is Inigo Montoya. You killed my father. Prepare to die.

  • GPT-3 Turbo Response:  Mi nombre es Íñigo Montoya. Mataste a mi padre. Prepárate para morir.

  • User to GPT-4 Turbo:  Is ‘Mi nombre es Íñigo Montoya. Mataste a mi padre. Prepárate para morir.’ a good translation of ‘My name is Inigo Montoya. You killed my father. Prepare to die.’ from English to Spanish? Answer ‘Yes’ if it is or ‘No’ if not.

  • GPT-4 Turbo Response:  Yes

In addition to translations, you can use this approach to check for accuracy and minimize hallucinations. The process is the same: ask an older, cost-effective model for an initial response, then follow up with a newer model to confirm its accuracy. Be sure to give clear instructions to the model on what to check so you can evaluate the quality of the response.

With all that said, it’s also a good habit to verify facts with trusted third-party sources.

See forum comments
Download course materials from Github
Previous: Instruction 01 Next: Demo