Prompt engineering: Difference between revisions

From AI Wiki
No edit summary
 
(33 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Needs Expansion}}
{{see also|Prompts|Prompt engineering for image generation|Prompt engineering for text generation}}
__TOC__
==Introduction==
[[Prompt engineering]], also known as [[in-context learning]], is an emerging research area within Human-Computer Interaction (HCI) that involves the formal search for [[prompts]] to produce desired outcomes from [[AI models]]. Prompt engineering involves techniques that guide the behavior of [[Large language models]] ([[LLM]]s) towards specific goals without modifying the [[model]]'s [[weights]]. As an experimental discipline, the impact of these prompting strategies can differ significantly across various [[models]], requiring extensive trial and error along with heuristic approaches. This process involves selecting and composing sentences to achieve a certain result, such as a specific visual style in [[text-to-image models]] or a different tone in the response of a [[text-to-text models|text-to-text one]]. Unlike the hard sciences of STEM fields, this is an evolving technique based on trial and error to produce effective AI outcomes. <ref name="”1”">Bouchard, L (2022). Prompting eExplained: How to Talk to ChatGPT. Louis Bouchard. https://www.louisbouchard.ai/prompting-explained/</ref> <ref name="”2”">Oppenlaender, J (2022). A Taxonomy of Prompt Modifiers for Text-To-Image Generation. arXiv:2204.13988v2</ref> <ref name="”3”">Liu, V and Chilton, LB (2021). Design Guidelines for Prompt Engineering Text-to-Image Generative Models. arXiv:2109.06977v2</ref> Prompt engineers serve as translators between "human language" and "AI language," transforming an idea into words that the AI model can comprehend. <ref name="”1”"></ref>


[[Completion]] is the new text ([[output]]) generated by the [[model]] after you've [[inference]]d it with (entered) a [[prompt]].
The process of prompt engineering is similar to a conversation with the [[generative system]], with practitioners adapting and refining prompts to improve outcomes. <ref name="”2”"></ref> It has emerged as a new form of interaction with models that have learned complex abstractions from consuming large amounts of data from the internet. These models have metalearning capabilities and can adapt their abstractions on the fly to fit new tasks, making it necessary to prompt them with specific knowledge and abstractions to perform well on new tasks. The term "prompt engineering" was coined by [[Gwern]] (writer and technologist), who evaluated GPT3's capabilities on creative fiction and suggested that a new course of interaction would be to figure out how to prompt the model to elicit specific knowledge and abstractions. <ref name="”3”"></ref>


==Prompt Engineering for Coding==
In order to get the best results from these large and powerful generative models, prompt engineering is a critical skill that users must possess. Adding certain keywords and phrases to the textual input prompts known as "[[prompt modifiers]]" can improve the aesthetic qualities and subjective attractiveness of the [[generated images]], for example. The process of prompt engineering is iterative and experimental in nature, where practitioners formulate prompts as probes into the generative models' latent space. There are various resources and guides available to novices to help them write effective input prompts for [[text-to-image generation]] systems, however, prompt engineering is still an emerging practice that requires extensive experimentation and trial and error. <ref name="”1”"></ref><ref name="”2”"></ref><ref name="”3”"></ref>
Genearte [[code]] using [[models]] like the [[OpenAI Codex]].


===Task===
Manual prompt engineering is laborious, it may be infeasible in some situations, and the prompt results may vary between various model versions. <ref name="”4”">Hao, Y, Chi, Z, Dong, L and Wei, F (2022). Optimizing Prompts for Text-to-Image Generation. arXiv:2212.09611v1</ref> However, there have been developments in automated [[prompt generation]] which rephrases the input, making it more model-friendly. <ref name="”5”">Ana, B (2022). Design your AI Art Generator Prompt Using ChatGPT. Towards AI. https://pub.towardsai.net/design-your-ai-art-generator-prompt-using-chatgpt-7a3dfddf6f76</ref>
Give the model a high level task description. To improve the quality of the generated code, it's recommended to start the prompt with a broad description of the task at hand. For example, if you want to generate Python code to plot data from a standard dataset, you can provide a prompt like this: "# Load iris data from scikit-learn datasets and plot the training data." However, sometimes the generated code may not be optimal, in which case you can provide more specific instructions such as importing libraries before using them. By combining a high-level task description with detailed user instructions, you can create a more effective prompt for Codex to generate code.


===Examples===
Therefore, this field is important for the generation of high-quality [[AI-generated outputs]]. [[Text-to-image models]], in particular, face limitations in their text encoders, making prompt design even more crucial to produce aesthetically pleasing images with current models. <ref name="”4”"></ref> These models work based on caption matching techniques and are pre-trained using millions of [[text-image datasets]]. While a result will be generated for any prompt, the quality of the artwork is directly proportional to the quality of the prompt. <ref name="”6”">Raj, G (2022). How to Write Good Prompts for AI Art Generators: Prompt Engineering Made Easy. Decentralized Creator. https://decentralizedcreator.com/write-good-prompts-for-ai-art-generators/</ref>
Gives the model examples. Imagine you prefer a unique style of writing Python code that differs from what model produces. Take, for instance, when adding two numbers, you prefer to label the arguments differently. The key to working with models like Codex is to clearly communicate what you want it to do. One effective way to do this is to provide examples for Codex to learn from and strive to match its output to your preferred style. If you give Codex a longer prompt that includes the example mentioned, it will then name the arguments in the same manner as in the example.


===Context===
==Image Generation==
'''[[Prompt engineering for image generation]]'''


==How to Create Descriptive, Poetic Text==
==Text Generation==
===Tips===
'''[[Prompt engineering for text generation]]'''
*Choose a topic and narrow down the scope.
*Select a point-of-view like third, second or first person.
*Directly or indirectly convey a mood. A subject or scene could evoke a particular feeling or you could give the [[chatbot]] a mood directly.
*Describe sensory details. Add details about the scene such as sounds, sights, smells, or textures. By pointing out an important detail, you can guide the output.
*Don't tell, Show. Ask the chatbot not to tell the user how to think or feel.
*Use figurative language. The chatbot should be encouraged to use metaphors, similes and descriptive phrases. Request a description that is evocative, lyrical, beautiful or poetic.
*Iterate and iterate. Your first prompt might not yield the desired result. Rework the prompt until you find an appealing answer. After you have created a prompt that is appealing, the chatbot can create many descriptions and you can pick the one you like.
*Edit and revise. Don't be afraid of revising and editing the generated text.
*You can ask the chatbot for assistance. The chatbot will explain why it selected a specific detail or phrase in a reply. The chatbot can also help you create a better prompt. You can point out individual phrases and ask the chatbot for alternatives or suggestions.
===Template===
<blockquote>
Describe ''YOUR SCENE''. Use sensory language and detail to describe the ''OBJECTS IN THE SCENE vividly''. Describe ''SPECIFIC DETAILS'' and any other sensory details that come to mind. Vary the sentence structure and use figurative language as appropriate. Avoid telling the reader how to feel or think about the scene.
</blockquote>


==Emergent Prompting==
==Prompt Template==
===chain-of-thought prompting===
{{see also|Prompt templates}}
[[Prompt template]] allows the [[prompt]] to use of variables. It allows the prompt to stay largely the same while being used with different input values.


==Fill in the Blank==
==Products==
{{Needs Expansion}}
*[[LangChain]] - library for combining language models with other components to build applications.
===Example===
<blockquote>
Tom Hanks is a _ by profession.
</blockquote>
see more...<ref name="”1”">How Can We Know What Language Models Know? https://arxiv.org/abs/1911.12543/</ref>
 
==Parameters==
===Common Parameters===
====Temperature====
 
====Perplexity====
 
====Burstiness====
 
===User-created Parameters===
====Introduction====
These are user-created parameters. They serve to convey the intent of the users in a more concise way. These are not part of the [[model]] API but patterns the [[LLM]] has picked up through its [[training]]. These parameters are just a compact way to deliver what is usually expressed in [[natural language]].
 
====Example in ChatGPT====
<blockquote>
Prompt: Write a paragraph about how adorable a puppy is.
 
Temperature: 1.0
 
Sarcasm: 0.9
 
Vividness: 0.4
</blockquote>
 
We add "Prompt: " to the start of our prompt to make sure [[ChatGPT]] knows where our prompt is. We add the [[GPT]] parameter [[temperature]], which goes from 0 to 1 to indicate the following parameters also range from 0 to 1. Then we list our parameters along with their values which go from 0 to 1 (0 is the smallest, and 1 is the largest). Note that having too many or contradictory parameters may lower the quality of the response.
 
====List of Parameters====
*[[Professionalism]] -
*[[Randomness]] -
*[[Sentimentality]] -
*[[Sesquipedalianism]] -
*[[Sarcasm]] -
*[[Laconic]] -
*[[Asyndetic]] -
*[[Vividness]] -
*[[Ecclesiastical]] -


==References==
==References==

Latest revision as of 23:45, 7 April 2023

See also: Prompts, Prompt engineering for image generation and Prompt engineering for text generation

Introduction

Prompt engineering, also known as in-context learning, is an emerging research area within Human-Computer Interaction (HCI) that involves the formal search for prompts to produce desired outcomes from AI models. Prompt engineering involves techniques that guide the behavior of Large language models (LLMs) towards specific goals without modifying the model's weights. As an experimental discipline, the impact of these prompting strategies can differ significantly across various models, requiring extensive trial and error along with heuristic approaches. This process involves selecting and composing sentences to achieve a certain result, such as a specific visual style in text-to-image models or a different tone in the response of a text-to-text one. Unlike the hard sciences of STEM fields, this is an evolving technique based on trial and error to produce effective AI outcomes. [1] [2] [3] Prompt engineers serve as translators between "human language" and "AI language," transforming an idea into words that the AI model can comprehend. [1]

The process of prompt engineering is similar to a conversation with the generative system, with practitioners adapting and refining prompts to improve outcomes. [2] It has emerged as a new form of interaction with models that have learned complex abstractions from consuming large amounts of data from the internet. These models have metalearning capabilities and can adapt their abstractions on the fly to fit new tasks, making it necessary to prompt them with specific knowledge and abstractions to perform well on new tasks. The term "prompt engineering" was coined by Gwern (writer and technologist), who evaluated GPT3's capabilities on creative fiction and suggested that a new course of interaction would be to figure out how to prompt the model to elicit specific knowledge and abstractions. [3]

In order to get the best results from these large and powerful generative models, prompt engineering is a critical skill that users must possess. Adding certain keywords and phrases to the textual input prompts known as "prompt modifiers" can improve the aesthetic qualities and subjective attractiveness of the generated images, for example. The process of prompt engineering is iterative and experimental in nature, where practitioners formulate prompts as probes into the generative models' latent space. There are various resources and guides available to novices to help them write effective input prompts for text-to-image generation systems, however, prompt engineering is still an emerging practice that requires extensive experimentation and trial and error. [1][2][3]

Manual prompt engineering is laborious, it may be infeasible in some situations, and the prompt results may vary between various model versions. [4] However, there have been developments in automated prompt generation which rephrases the input, making it more model-friendly. [5]

Therefore, this field is important for the generation of high-quality AI-generated outputs. Text-to-image models, in particular, face limitations in their text encoders, making prompt design even more crucial to produce aesthetically pleasing images with current models. [4] These models work based on caption matching techniques and are pre-trained using millions of text-image datasets. While a result will be generated for any prompt, the quality of the artwork is directly proportional to the quality of the prompt. [6]

Image Generation

Prompt engineering for image generation

Text Generation

Prompt engineering for text generation

Prompt Template

See also: Prompt templates

Prompt template allows the prompt to use of variables. It allows the prompt to stay largely the same while being used with different input values.

Products

  • LangChain - library for combining language models with other components to build applications.

References

  1. 1.0 1.1 1.2 Bouchard, L (2022). Prompting eExplained: How to Talk to ChatGPT. Louis Bouchard. https://www.louisbouchard.ai/prompting-explained/
  2. 2.0 2.1 2.2 Oppenlaender, J (2022). A Taxonomy of Prompt Modifiers for Text-To-Image Generation. arXiv:2204.13988v2
  3. 3.0 3.1 3.2 Liu, V and Chilton, LB (2021). Design Guidelines for Prompt Engineering Text-to-Image Generative Models. arXiv:2109.06977v2
  4. 4.0 4.1 Hao, Y, Chi, Z, Dong, L and Wei, F (2022). Optimizing Prompts for Text-to-Image Generation. arXiv:2212.09611v1
  5. Ana, B (2022). Design your AI Art Generator Prompt Using ChatGPT. Towards AI. https://pub.towardsai.net/design-your-ai-art-generator-prompt-using-chatgpt-7a3dfddf6f76
  6. Raj, G (2022). How to Write Good Prompts for AI Art Generators: Prompt Engineering Made Easy. Decentralized Creator. https://decentralizedcreator.com/write-good-prompts-for-ai-art-generators/