Review of "ChatGPT Prompt Engineering for Developers"

ChatGPT continues to dominate the headlines and is set to transform the way we work. If you're looking to learn more about this exciting technology, check out this course "ChatGPT Prompt Engineering for Developers" hosted by Isa Fulford and Andrew Ng, developed by DeepLearning.AI and OpenAI. Despite its title, this 90-minute course is a great resource for anyone who wants to improve their understanding of ChatGPT and learn how to use it more effectively. 


You will be introduced to the fundamental principles of prompt engineering, how to craft and iteratively improve your prompts, and basic tasks that you can accomplish with ChatGPT before moving on to building more complex systems, such as customised chat bots. To help you navigate the course, here are my notes, and I hope you enjoy the learning experience.

Prompt Engineering Principles

Principle 1: write clear and specific instructions

  • Focus on providing context, it is not always shorter the better

  • Tactics

    • Use delimiters, such as triple quotes, triple backticks, triple dashes, angle brackets, XML tags, etc, to clearly indicate distinct parts of the input

      • Example: “summarise the text delimited by triple backticks ```text``` into a single sentence

    • Ask for structured output, like HTML, JSON, etc

      • Example: “provide the result in JSON format with the following keys: id, title, description” 

    • Check whether conditions are satisfied, check assumptions required to do the task

      • Example: “if the text contains a sequence of instructions, rewrite the instructions in the following format: step 1, step 2…; if the text does not contain a sequence of instructions, then simply write ‘no steps provided’

    • Few-shot prompting, which is to give successful examples of completing tasks, then ask model to perform the task

      • Example: “answer in a consistent style ```style```

Principle 2: give the model time to “think”

  • Reframe the query for reasoning errors

  • Tactics

    • Specify the steps to complete a task

      • Example: “```context```  Perform the following actions: step 1 - summarise; step 2 - translate; step 3 - list; step 4 - output in a format

    • Instruct the model to work out its own solution before rushing to a conclusion

Limitations

  • Hallucination: make statements that sound plausible but are not true

  • Reducing hallucination: first find relevant information, then answer the question based on the relevant information

Iterative Prompt Development

  • Don’t expect to get the best result with one shot, but by employing an iterative approach, to fine-tune the prompts.

  • Prompt guidelines

    • Be clear and specific

    • Analyse why result does not give desired output

    • Refine the idea and the prompt

    • Repeat 

  • Iterative process

    • Try something

    • Analyse where the result does not give what you want

    • Clarify instructions, give more time to think

    • Refine prompts with a batch of examples

Capabilities

Summarising 

  • Summarise text with a focus on specific topics.

  • Examples

    • Summarise with a word / sentence / character limit: “summarise the review below, delimited by triple backticks, in at most 30 words

    • Extract information: “extract relevant information from the text

    • Summarise multiple inputs and categorise them into dashboards

Inferring

  • Takes text as input and forms some kind of analysis, such as extracting labels, names, understanding the sentiment of a text, etc.

  • Examples

    • Sentiment: “what is the sentiment of the following review

    • Identity types of emotions: “identify a list of emotions the text is expressing

    • Identity particular sentiments, such as anger

    • Extract rich information

    • Extract multiple (un-related) information at the same time

    • Inferring topics: “determine five topics that are being discussed

    • Indexing topics using zero-shot prompting: “determine whether each item in the following list of topics is a topic in the text

    • Create alerts for interested topics

Transforming

  • Perform text transformation tasks, such as language translation, spelling and grammar corrections, tone adjustment and format conversion.

  • Examples

    • Language identification: “identity the language of this text

    • Translation: “translate the English text to Spanish

    • Formal and informal: “translate the text to Spanish in both the formal and informal formats

    • Format conversion: “translate the python dictionary from JSON to HTML

    • Spelling and grammar correction: “proofread and correct… rewrite

    • Tone adjustment: “make it more compelling, ensure it follows APA style guide targets an advanced reader

Expending

  • Take a short piece of text, such as instructions or a list of topics, expand and generate a longer piece of text, e.g. email, essay, etc. Use LLM as a brainstorming partner.

  • Examples

    • Temperature describes the level of randomness: “temperature = 0.7

      • Temperature = 0, the result is more predictable

      • Higher temperature for a wider variety of outputs

Building a Chatbot

  • Build a customised chatbot

  • Roles: user, assistant, system

    • User: the user

    • Assistant: chat model, where user interacts with the most

    • System: the system role also known as the system message is included at the beginning of the array. This message provides the initial instructions to the model, it sets the behaviour of the assistant, so that assistant can provide guided responses without the user's awareness. The system role/message is optional, but it's recommended to at least include a basic one to get the best results. You can provide various information in the system role including

  • A brief description of the assistant

  • Personality traits of the assistant

  • Instructions or rules you would like the assistant to follow

  • Data or information needed for the model, such as relevant questions from an FAQ

Conclusion

Please please please use LLM responsibly


Comments

Popular posts from this blog

A practical guide to Scala Traits

A Short Guide to AWK

How to: Add Watermark to PDFs Programmatically using iTextSharp