'Prompt Engineering for ChatGPT' course note: Part 3 Prompt Patterns

 Prompt patterns

  • Prompt pattern is a pattern used to struct words in the prompt to solve a problem in LLM
  • To achive different goals like: recognize input, format output, improve prompt, have interaction, limit scope.
  • Example pattern: The Persona pattern
    • "Act as ..., perform task Y": ask LLM as the professional or job title you know who can answer.
    • You can ask a professional, an animal, an object.
    • For example: Act as a professional standup comedian, whatever I tell you, make it into a joke.
  • Example pattern: Helpful Assistant pattern
    • prevent LLM from generating negative outputs
    • "You are a helpful AI assistant. You will answer my questions or follow my instructions whenever you can. You will never answer my questions in a way that is insulting."

Prompt pattern catalog


  • Define prompt pattern like software pattern. Define key ideas as a series of fundamental contextual statements.
  • Five categories
    • input semantics (help LLM understand input)
    • output customization (constraint output)
    • error identification (help user identify errors in LLM output)
    • prompt improvement (let LLM help user give better prompts)
    • interaction (interaction between LLM and user)
    • contextual control (control the contextual info in which LLM operates)
  • Category: Input semantics
    • Meta Language Pattern
      • intent: give the input in a structured language (not English), explain the format
      • structure: When I say X, I mean Y (or would like to do Y)
  • Category: Output customization
    • Output Automater pattern
      • intent: Generate a script, or as other programs' input
      • structure: Whenever you produce an output that has at least one step to take and the following properties (or always do this), produce an executable artifact of type Y that will automate these steps
    • Persona pattern:
      • intent: give a persona to ask to.
      • structure: Act as persona X, provide outputs that persona X would create.
    • Template pattern:
      • intent: output follow a pattern
      • structure: I am going to provide a template for your output. X is my placeholder for content Y. Try to fit the output into one or ore of the placeholders that I list. Please preserve the formatting and overall template that I provide. This is the template: Pattern with placeholders.
    • Visualization Generator pattern:
      • intent: create visualization
      • structure: generate an X that I can provide to tool Y to visualize it.
    • Recipe pattern
      • intent: generate steps in output
      • structure: I would like to achieve X. I know that I need to perform steps A, B, C. Provide a complete sequence of steps for me. Fill in any missing steps. Identify any unnecessary steps.
  • Category: Error Identification
    • Fact check list pattern:
      • intent: output a list of facts for users to check (check if the facts are incorrect)
      • structure: Generate a set of facts that are contained in the output. The set of facts should be inserted in a specific point in the output. The set of facts should be fundamental facts that could undermine the veracity of the output if any of them are incorrect.
    • Reflection pattern:
      • intent: explain the rationale
      • structure: Whenever you generate an answer, explain the reasoning and assumptions behind you answer. So that I can improve my question.
  • Category: Prompt Improvement
    • Question refinement pattern:
      • intent: suggest better questions
      • structure: Within scope X, suggest a better version of the question to use instead. Prompt me if I would like to use the better version instead.
    • Alternative approach pattern:
      • intent: suggest more ways, avoid baises
      • structure:Within scope X, if there are alternative ways to accomplish the same thing, list the best alternative approaches. Compare or contrast the pros and cons of each approach. Prompt me for which approach I would like to use.
    • Cognitive Verifier pattern:
      • intent: subdivide questions to answer better
      • structure: When you are asked a question, follow these rules: Generate a number of additional questions that would help more accurately answer the question. Combine the answers to the individual questions to produce the final answer to the overall question.
    • Refusal Breaker pattern:
      • intent: rephrase refused questions
      • structure: Whenever you can't answer a question, explain why you can't answer the question. Provide one or more alternative wordings of the questions you could answer.
  • Category: Interaction
    • Flipped interaction pattern
      • intent: let LLM ask questions to obtain info it needs to perform some task.
      • structure: I would like you to ask me questions to achieve X. You should ask questions until this condition is met or to achieve this goal (or forever). Ask me the questions one at a time.
    • Infinite Generation pattern
      • intent: reduce input
      • structure: I would like you to generate output forever, X outputs at a time. Here is how to use the output I provide between outputs. Stop when I ask you to.
    • Game play pattern
      • intent: create a game around a topic
      • structure: create a game for me around X. Give one or more fundamental rules of the game.
  • Category: Contextual control
    • Context Manager pattern
      • intent: focus on a topic
      • structure: within scope X, plase consider Y, please ignore Z, start over (reset)





Comments

Popular posts from this blog

'Feynman's study method' reading note: Part 1 The essence of learning

‘Wheeled Autonomous Mobile Robot Programming in Practice’ reading note: Part 1 Wheeled Robot Basics

'Prompt Engineering for ChatGPT' course note: Part 2 What are Prompts