import numpy as npsar ="to do is to be"soc ="to be is to do"sha ="to be or no to be"sin ="do be do be do"all= [sar, soc, sha, sin]words = [quote.split() for quote inall]sets = [set(quote) for quote in words]unique =set.union(*sets)nexts =dict()for first in unique:next= []for quote in words:for loc, word inenumerate(quote):if word == first and loc +1<len(quote):next.append(quote[loc +1]) nexts[first] =nextdef next_word(prev_word): die = np.random.rand() possible_words = nexts[prev_word] position = die *len(possible_words) position =int(position)return possible_words[position]def make_text(first_word, num_words): text = first_word word = first_wordfor _ inrange(num_words -1): word = next_word(word) text = text +" "+ wordprint(text)for word in unique: make_text(word, 5)
or no to be do
do is to be or
no to do be is
is to be is to
be or no to be
to be do be is
Prompts
Citation
I do consider myself good at writing “prompts” - instructions to get a large language model to produce the prompt I want.
However, I do so by thinking of prompts as writing code.
I took Google’s guide and put it in Gemini (then lightly edited)
Prompt “engineering”
The rise of large language models (LLMs) has brought forth exciting possibilities for human-computer interaction. However, harnessing the full potential of these powerful AI models requires a crucial skill: prompt engineering.
Goals
“Unlock” the capabilities of LLMs.
Understand intent.
Follow instructions.
Generate desired outputs.
Aim for:
Accurate, relevant, safe
What is prompt engineering?
Art and science of designing/optimizing prompts.
Very cool to see the term “art and science” appear… not just in a “College of Arts and Sciences”
I think of it as: things that can be verified experimentally and things that can’t.
Prompts are both!
Guides AI toward specific responses.
Provides context, instructions, and examples.
Acts as a structure for the AI.
What is a prompt?
Input provided to “primes” a specific response.
Like when we provided example phrases, a starting word, and a length.
Structure how is natural to you:
Questions, keywords, instructions.
I often provide examples.
Influences quality and relevance of output.
Key Elements
Mastery communicates effectively with AI models.
Format: How the model interprets requests.
Natural language, commands, structured fields.
Context: Improves tone, theme, and accuracy.
“For a work email…”
“For an Instagram post…”
“For the group chat…”
Elements
The idea
Decompose a prompt into some key elements.
Format
Context
Example
Tuning
Turns
Prompt formats
The (1) structure and (2) style of your prompt play a significant role in guiding the AI’s response.
Different models (GPT, Claude, LLaMa, Gemini) may respond better to specific formats.
Examples
Natural language questions.
“Is this a leaf?”
Direct commands.
“Write 4 sentences of 14-18 words.”
Structured inputs with specific fields
“3 adjectives that evoke happiness and relaxation.”
Context and Examples
Provide context to improve accuracy and relevance.
Define specific tone or themes.
Helps the AI understand the desired intent.
Examples:
Include a few sentences on the tasks background.
Describe the mood (e.g., “upbeat,” “concerned”).
Fine-tuning and Adapting
Fine-tuning enhances performance via tailored prompts.
Target specific tasks or domains.
Adapt based on user feedback or model outputs.
Improves response quality over time.
Examples:
Train on peer-reviewed journals for accuracy.
Refine prompts based on common user errors.
Multi-turn Conversations
Enables continuous, context-aware interactions.
Enhances the overall user experience.
AI remembers previous inputs within the thread.
Facilitates complex, multi-step tasks.
Examples:
Refining a search: “Now find prices for those hotels.”
Debugging: “Why did the previous code throw an error?”
Types
Types of prompts
There are various types of prompts used in AI, each serving a specific purpose:
Direct
\(n\)-shot
Chain-of-thought
Direct Prompts
Provide direct instructions or questions.
Includes no additional context or examples.
Helpful to get “general” or “broad” responses.
Relies on the model’s pre-existing knowledge.
Basically, what is currently on the internet.
And at the rate things are on the internet.
So: low density of peer reviewed studies.
Direct Prompts
Also called “zero-shot” prompts (zero back-and-forth)
Useful for standard tasks and quick queries.
Examples:
“Brainstorming”: “Brainstorm a theme for birthday party.”
Summarization: “Summarize the text provided below.”
Translation: “Translate ‘Hello’ into French.”
\(n>0\) Shot
Provide one or more input-output pairs.
With a human, we would say “conversation” or “back-and-forth”.
Helps the model understand complex patterns.
“Make more things like this”.
Improves accuracy for specific formatting.
\(n>0\) Shot
Refines the desired style before the task.
Examples:
One-shot: Give more fictional names like “Argaven Harge”
Specify the source and target programming languages to enable the AI to translate code while preserving functionality and syntax.
“Translate the following Python code to JavaScript: def greet(name): print(‘Hello,’, name)”
Code Generation
Scenario
Instructions
Example Prompt
Code Optimization
Prompt the AI to analyze existing code and suggest improvements for efficiency, readability, or performance.
“Optimize the following Python code to reduce its execution time.”
Code Generation
Scenario
Instructions
Example Prompt
Code Debugging
Provide the AI with code containing errors and prompt it to identify and suggest potential solutions for the identified issues.
“Debug the following Java code and explain why it is throwing a NullPointerException.”
Return to vision
Gemini in particularly is fond of its image capabilities, including writing alt-text and generating images.
I do not think the following necessariyl apply as broadly to non-Gemini.
Image Generation
Scenario
Instructions
Example Prompt
Photorealistic Images
Craft prompts that describe the desired image in detail, including objects, scenery, lighting, and style, to generate realistic and high-quality images.
“A photorealistic image of a sunset over the ocean with palm trees silhouetted against the sky.”
Image Generation
Scenario
Instructions
Example Prompt
Artistic Images
Design prompts that specify art styles, techniques, and subject matter to guide the AI in creating images that mimic specific artistic movements or evoke certain emotions.
“An impressionist painting of a bustling city street with people walking under umbrellas in the rain.”
Image Generation
Scenario
Instructions
Example Prompt
Abstract Images
Formulate prompts that encourage the AI to generate images that are open to interpretation, utilizing shapes, colors, and textures to evoke feelings or concepts.
“An abstract image representing the concept of hope, using bright colors and flowing shapes.”
Image Generation
Scenario
Instructions
Example Prompt
Image Editing
Provide the AI with an existing image and specify desired modifications, enabling it to edit and enhance the image according to the given instructions.
“Change the background of this photo to a starry night sky and add a full moon.” or “Remove the person from this image and replace them with a cat.”
Strategies
Clear Goals
Context
Iterate
Avoid Pitfalls
Clear Goals
Clearly define what you want the AI to achieve.
Tactic
Prompt Example
Use precise language and avoid ambiguity
Instead of: “Write something about climate change,” use: “Write a persuasive essay arguing for the implementation of stricter carbon emission regulations.”
Clear Goals
Clearly define what you want the AI to achieve.
Tactic
Prompt Example
Use action verbs to specify the desired action
“Write a bulleted list that summarizes the key findings of the attached research paper”
Clear Goals
Clearly define what you want the AI to achieve.
Tactic
Prompt Example
Define the desired length and format of the output
“Compose a 500-word essay discussing the impact of climate change on coastal communities.”
Clear Goals
Clearly define what you want the AI to achieve.
Tactic
Prompt Example
Quantify your requests whenever possible
Instead of: “Write a long poem,” use: “Write a sonnet with 14 lines that explores themes of love and loss.”
Provide Context
Providing relevant context and background information.