First Principles of Prompt Design🧠

Crafting better prompts through understanding the language model’s inner workings.

Eric Gu
6 min readApr 26, 2023
Midjourney image of a robotic alcoholics anonymous… ehh… more like a jury.

My name is Eric, and must confess… my brain has been rewired lately from thinking “how am I going to do that myself” to defaulting to “how am I going to write a prompt to get me started...”

And I freaking love it.

I’d like to think I’m a power user, not only from the perspective of an academic or as a consultant, but also in my personal life. With all the experience in training my own models or fine-tuning others, exploring prompt-tuning and prompt-programming, and now prompt designing, I noticed that I’ve developed some level of intuition in anticipating how our inputs are constraining the probability distribution space for generating outputs.

And I want to share some insights that I’ve picked up.

So, What do I mean by Prompts?

In a very short time, few-shot learning capabilities in AI models advanced sufficiently to enable instructive inputs for language-capable models to process and generate almost any forms of digital content (text, images, audio, and videos) from text as a foundation (Brown et al., 2020).

This became Prompts that we write today.

They may feel like commands you are giving to an intelligent being, but it is still operating on the same token prediction approach.

Behind the Scene

An LLM, like GPT-4, processes input prompts using a technique called Transformer architecture. This architecture relies on attention mechanisms, which allow the model to focus on different parts of the input sequence during the processing. The attention mechanism helps the model decide which parts of the input are most relevant at a given time.

Some key concepts to keep in mind:

  1. Tokenization: The input text is broken down into smaller units called tokens, which can be words, subwords, or characters. These tokens are then encoded as numerical vectors to be fed into the model.
  2. Embedding: Each token is converted into a high-dimensional vector (embedding) that represents the token in a continuous space. These embeddings are then used as input for the Transformer architecture.
  3. Self-Attention: The attention mechanism in the Transformer architecture calculates the relevance of each token in the input sequence concerning every other token. This helps the model focus on the most important parts of the input and understand the context and relationships between words.

Imagine a traveler about to embark on a road, and you are guiding them by providing them with a set of instructions (prompt), which becomes understood (tokenized) and referenced on a map previous travelers have drawn (embeddings) and the traveler (attention) prioritizes the steps to getting to the destination (output).

LLMs are not great at calculations, but they can use language to “reason through” a problem, which maybe… a mental image could be to setting up camps during a really really long journey rather than attempting it all in one go and failing to reach the desired destination.

Chain-of-Thought Prompting

Chain-of-thought (CoT) prompting, introduced by Wei et al. (2022), helps AI perform a morecomplex reasoning by breaking down tasks into smaller steps. Combining this with few-shot prompting leads to better results on challenging tasks. For example, when given a group of numbers and asked if the odd ones add up to an even number, the AI can find the answer by adding the odd numbers and checking if the result is even. This works well even with just one example. This ability emerges in large language models like GPT-4.

Image Source: Wei et al. (2022)

Directional Stimulus Prompting is a new framework that algorithmically and artificially boosts the attention towards certain keywords of a prompt by specifically highlighting it to the LLM. Li et al. (2023) proposed it using a smaller, tunable language model (LM) to generate hints or cues that guide the LLM. These hints are combined with the original input to help the LLM generate better results.

Image Source: Li et al., (2023)

I hope these examples have convinced you that there are ways to design effective prompts that guide these models in generating more meaningful and relevant responses.

You can do this algorithmically, or creatively. For the latter, here are some ideas for you.

Prompt Components 101

From what I’ve gathered, these are the most important, or let’s say “attention grabbing” components in a prompt:

  1. Contextual information: The background info or context given in the prompt.
  2. Explicit questions or tasks: The specific questions or tasks the model needs to answer or perform.
  3. Implicit assumptions or constraints: Any assumptions or constraints that aren’t explicitly stated but are essential for understanding the prompt.

Explicit?

These components emerged within the model as a result of the training process, no one explicitly coded them in. The model learns to recognize and process these components by analyzing the patterns present in the vast amount of training data it has been exposed to. How it encoded it is hard for us to interpret.

Bonus: Explicit parameters: Commands that are can also be used with tools like Midjourney, where adding the --command flag sets the parameters for the AI model's generation. However, this is not a component that the AI model processes, but rather one that is explicitly programmed by the tool provider.

Exhaustive?

These 3 example component types serve as a general framework for understanding and categorizing various aspects of a prompt. But this is just a way to help you think about prompt design, NOT a description of the actual model’s encoding. (I imagine it is more of a continuous space than discrete categories).

So this list cannot possibly be exhaustive, but it can be used as a starting point for understanding and analyzing prompts. As language models and our understanding of their behavior continue to evolve, we might discover or define other components that further refine our understanding of how prompts are processed and how LLMs respond to them.

Examples 🌟

From my analysis of about 15000 prompts collected from Flowgpt.com, I came up with a few dozen examples of most commonly used prompt components. I bet you can come up with more.

A non-exhaustive list of smaller prompt components I’ve gathered.

Prompting as a Profession

As you can imagine, adding so many dimensions to a prompt can get really messy quickly. Prompt designing, prompt engineering, promptcrafting, regardless of what you want to call it, it is undeniable that it is rapidly taking shape as a proper profession.

And as any field matures, experts tend to use complex tools and techniques that separate them from the casual hobbyist. That’s where I believe we will need advanced interfaces for experts to really get creative with their prompt design.

Imagine a novice opening Adobe Photoshop, their mind boggled by the plethora of features. Now, contrast this with the finesse of an expert whose mouse glides effortlessly across the canvas, fingers tapping rhythmically.

Professionals develop heuristics, commit shortcuts to memory, and meticulously archive their past work to refine and expedite future endeavors.

Yes, AI is already empowering anyone to flush an even a half-baked idea in to a somewhat complete form. (Take my attempt at fashion with Midjourney).

But Mastery looks different… Pros have heuristics, memorize shortcuts, save their past work so as to preserve it and hopefully streamline future work. Prompt Design as a profession is just starting to take shape!

With that said… I’m promoting the Prompt Editor that Johannes Mutter and I built. We came up with a Nested Prompt Design approach that allows you to write massive complex and interconnected prompt without it being a visual nightmare.

No this isn’t a post entirely to build up to an ad. And it’s a free tool, you have nothing to complain about… If you want to contribute, visit the Github page on the site or linked below.

… Plus you made it all the way down here, hopefully you at least took away something from it.

It is also a prompt management tool (if you make an account).

Craft your next intricate prompt using Promptly.

Website: https://www.heypromptly.com/

--

--

Eric Gu

Creative technologist and researcher exploring themes of technology, creativity, and navigating an ever more complex world.