icon picker
ChatGPT Prompt Engineering Notes

Hyperparameters in ChatGPT

response = openai.ChatCompletion.create( messages = [ {"role": "user", "content": "" }], model = "gpt-4" temperature = 0, max_tokens = 100, stop = ["goodbye"], top_p = 0.5, frequency_penalty = 0, presence_penalty = 0)
Screenshot 2024-01-10 at 3.12.16 PM.png
Screenshot 2024-01-10 at 3.11.22 PM.png

ChatGPT Official Prompt Engineering

Screenshot 2023-12-13 at 4.12.08 PM.png
Instructions Tune LLM
LLM that's been trained on a huge amount of text data and further train and fine-tune it with inputs and outputs and then further refine the model using a technique called RLHF, reinforcement learning from human feedback, to make the system better able to be helpful and follow instructions.

Principles

Principle 1: Write clear and specific instructionsPrinciple 2: Give the model time to “think”
Screenshot 2023-12-13 at 4.39.58 PM.png
Screenshot 2023-12-13 at 4.40.52 PM.png

Screenshot 2023-12-13 at 5.14.20 PM.png
Screenshot 2023-12-13 at 5.17.46 PM.png
Avoiding Prompt Injections
Screenshot 2023-12-13 at 5.16.37 PM.png
Screenshot 2023-12-13 at 5.19.49 PM.png
text_2 = f"""
The sun is shining brightly today, and the birds are \
singing. It's a beautiful day to go for a \
walk in the park. The flowers are blooming, and the \
trees are swaying gently in the breeze. People \
are out and about, enjoying the lovely weather. \
Some are having picnics, while others are playing \
games or simply relaxing on the grass. It's a \
perfect day to spend time outdoors and appreciate the \
beauty of nature.
"""
prompt = f"""
You will be provided with text delimited by triple quotes.
If it contains a sequence of instructions, \
re-write those instructions in the following format:
Step 1 - ...
Step 2 - …
Step N - …
If the text does not contain a sequence of instructions, \
then simply write \"No steps provided.\"

\"\"\"{text_2}\"\"\"
"""
response = get_completion(prompt)
print("Completion for Text 2:")
print(response)

Completion for Text 2:
No steps provided.
4 Tactics
Screenshot 2023-12-13 at 5.22.02 PM.png
Screenshot 2023-12-13 at 5.24.20 PM.png
Give the model time to think
Screenshot 2023-12-13 at 8.34.08 PM.png
Screenshot 2023-12-13 at 8.35.03 PM.png
Use angled brackets
Use triple backticks ‘’’ ’’’
Screenshot 2023-12-13 at 9.44.54 PM.png
Screenshot 2023-12-13 at 9.47.31 PM.png
Screenshot 2023-12-13 at 9.46.40 PM.png

Work on the solution first and compare its solution with model solution.
Model Limitations
Screenshot 2023-12-13 at 9.48.45 PM.png

Screenshot 2023-12-13 at 9.50.14 PM.png

Iterative Prompt Development

What matters most is the process for getting to prompts that works for your application.
Screenshot 2023-12-13 at 10.00.04 PM.png
Screenshot 2023-12-13 at 10.03.51 PM.png
Screenshot 2023-12-13 at 10.05.40 PM.png
Screenshot 2023-12-13 at 10.01.08 PM.png
Screenshot 2023-12-13 at 10.04.22 PM.png
Screenshot 2023-12-13 at 10.07.40 PM.png

Screenshot 2023-12-13 at 10.14.16 PM.png
It’s a really long result → modify the prompt
add “Use at most 50 words”
“Use at most 3 sentences”
“Use at most 280 characters”
Add more intentions, instructions or requests
Keep best practices in mind, clear, specific, and give model the time to think.
Take the first attempt and iteratively refine the prompt to the results we need
Have a good process to develop prompts that are effective for the app
Can apply prompts with multiple input txt

Summarizing

Screenshot 2023-12-13 at 10.18.49 PM.png
Screenshot 2023-12-13 at 10.23.59 PM.png
Screenshot 2023-12-13 at 10.21.49 PM.png
Screenshot 2023-12-13 at 10.35.19 PM.png
add “give feedback to the shipping department”
“extract relevant information”
work on a list of reviews - at most 20 words

Inferring Topics

inference the number of topics / sentiment score
Screenshot 2023-12-13 at 10.43.51 PM.png
Screenshot 2023-12-13 at 10.45.48 PM.png
Screenshot 2023-12-13 at 10.48.07 PM.png
Use a collection of topics
Zero Shot Learning Algorithm
Output answer in JSON format could be more reliable
think about ways to stabilize output format

Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.