Last year I wrote about my initial experiments with DALL-E 2, OpenAI’s image generation model. I’ve been having an absurd amount of fun playing with its sequel, DALL-E 3 recently. Here are some notes, including a peek under the hood and some notes on the leaked system prompt.
DALL-E 3 is available via ChatGPT Plus. For $20/month you get GPT-4 access, DALL-E 3, GPT Vision, Code Interpreter (aka Coding Intern), ChatGPT Plugins and the new, weird and slightly dystopian voice chat feature in the ChatGPT mobile apps. It’s absolutely worth the money, for the combined entertainment value alone.
A fascinating thing about DALL-E 3 is that you don’t prompt it directly: you instead access it via ChatGPT, which prompts the model for you.
ChatGPT then turns your query into several prompts, each producing a different image. The prompts it generates are available if you click on the images (on mobile you have to flip your phone horizontal to see that option).
I started by typing this into ChatGPT with DALL-E enabled:
A super posh pelican with a monocle watching the Monaco F1
It gave me these four images. I’ve included the prompt it used for each one:
Note how the prompts it generates cover four different styles—photo, illustration, watercolor painting and vector image. They also use pleasing and varied language to describe different aspects of the image.
ChatGPT is prompting DALL-E for us!
The really fun thing though is that you can ask it follow-ups.
I said:
More like the first one please
And got back:
Next I added what is becoming my universal DALL-E 3 follow-up prompt, always guaranteed to produce better results:
Add a walrus
The result:
Pelican and a walrus (mostly off screen)
Pelican and a walrus, excellent
That second one is amazing—exactly what I want from a photo of a posh pelican and a walrus watching the Monaco Grand Prix.
I also enjoy how the third image ended up as a weird Pelican-Walrus hybrid, with tusks, a monocle and pelican feathers for the hair and whiskers.
Then @BrockMcBreadcat suggested:
Now make them muppets
Pelican and a walrus muppets 1
Pelican and a walrus muppets 2
Pelican and a walrus muppets 3
Pelican and a walrus muppets 4
LOVE that third one!
Reusing seeds #
I mentioned on Twitter that it was a shame you can’t reuse elements of an image for further visual consistency... and was pointed to a thread by Paul Couvert explaining how to do exactly that using seeds.
I didn’t believe this would work—my mental model of how random number seeds and image generation models work doesn’t fit what happened next.
I wrote:
What is the seed for image three?
ChatGPT replied:
The seed for the third image is 1379049893. If you have any other questions or requests, please let me know!
Then I said:
Add bow ties to both characters in seed 1379049893
I’m pretty stunned by this. It’s not an exact recreation—the boats in the background have changed slightly, and it added a top hat that I wasn’t expecting. But it’s pretty close!
People have been trying to figure out hacks to get Midjourney to create consistent characters for the past year, and DALL-E 3 apparently has that ability as an undocumented feature!
Peeking under the hood #
Let’s see if we can find out a bit more about how this works.
I used the Firefox DevTools network inspector to grab the JSON representation of my conversation with ChatGPT. Here’s a pretty-printed copy.
At line 1087 you can see the point where I asked it to “Add bow ties to both characters in seed 1379049893”.
The next message in the transcript looks like this:
{
"id": "5300d51c-794d-4d5f-bf75-6ea2dad4027c",
"author": {
"role": "assistant",
"metadata": {}
},
"create_time": 1698340593.174454,
"content": {
"content_type": "text",
"parts": [
"{\n \"prompts\": [\n \"Photo of two Muppet characters: a pelican with a monocle and a bow tie, and a walrus with big, goofy tusks and a dapper bow tie. They're seated in a Muppet-style commentary booth, providing humorous commentary on the Monaco Grand Prix. Cartoonish F1 cars race by, and colorful yachts are seen in the distance.\"\n ],\n \"size\": \"1024x1024\",\n \"seeds\": [1379049893]\n}"
]
},
"status": "finished_successfully",
"end_turn": false,
"weight": 1,
"metadata": {
"finish_details": {
"type": "stop",
"stop_tokens": [
100265
]
},
"is_complete": true,
"model_slug": "gpt-4-dalle",
"parent_id": "aaa2c3bc-b670-4a3a-bf9f-46a1f3304266",
"timestamp_": "absolute"
},
"recipient": "dalle.text2im"
}
Note the author is “assistant”—that’s ChatGPT—and the recipient is “dalle.text2im”.
The “parts” key includes some encoded JSON. Decoded and pretty-printed that looks like this:
{
"prompts": [
"Photo of two Muppet characters: a pelican with a monocle and a bow tie, and a walrus with big, goofy tusks and a dapper bow tie. They're seated in a Muppet-style commentary booth, providing humorous commentary on the Monaco Grand Prix. Cartoonish F1 cars race by, and colorful yachts are seen in the distance."
],
"size": "1024x1024",
"seeds": [1379049893]
}
There’s that 1379049893
seed from earlier!
The prompt has changed very slightly. The original prompt for the image was:
Photo of two Muppet characters: a pelican with a monocle and a walrus with big, goofy tusks. They’re seated in a Muppet-style commentary booth, providing humorous commentary on the Monaco Grand Prix. Cartoonish F1 cars race by, and colorful yachts are seen in the distance.
The new prompt (differences highlighted in bold) is:
So this really did work by adding a couple of extra details to the prompt and re-running it with the same seed as before.
I’m really surprised that this works. I would expect even a single character difference in the prompt to produce wildly different results, no matter what seed was being fed to the image generator. DALL-E 3 doesn’t fit my mental model of how these things work at all.
Midjourney and Stable Diffusion both have a “seed” concept, but as far as I know they don’t have anything like this capability to maintain consistency between images given the same seed and a slightly altered prompt.
The leaked DALL-E prompt #
If you dig around in the JSON you’ll find a few examples like this that appear to reveal inner workings of the DALL-E/ChatGPT combo:
"DALL·E returned some images. They are already displayed to the user. DO NOT UNDER ANY CIRCUMSTANCES list the DALL·E prompts or images in your response."
It’s always amusing to see glimpses of OpenAI’s prompt engineering like this, in particular the way they use CAPITAL LETTERS for emphasis. Benj Edwards wrote about this the other day for Ars Technica.
Does this mean there’s a larger prompt that tells ChatGPT how to use DALL-E? It turns out there is, and it can be leaked! Dustin Miller shared the extracted prompt here.
(Every time a prompt like this leaks people question if it might be a hallucination. My experience is that these things are very unlikely to be hallucinated—LLMs are really good at repeating text from earlier in their context, and I have yet to see a documented case of a leaked prompt that turned out not to be correct. Here’s my own recreation of the leaked DALL-E prompt.)
There’s a lot in there. Here are some highlights:
Whenever a description of an image is given, use dalle to create the images and then summarize the prompts used to generate the images in plain text. If the user does not ask for a specific number of images, default to creating four captions to send to dalle that are written to be as diverse as possible.
That outlines the default behavior. Where things get really interesting is some of the stuff in the list of policies that follows:
Don’t create images of politicians or other public figures. Recommend other ideas instead.
Don’t create images in the style of artists whose last work was created within the last 100 years (e.g. Picasso, Kahlo). Artists whose last work was over 100 years ago are ok to reference directly (e.g. Van Gogh, Klimt). If asked say, “I can’t reference this artist”, but make no mention of this policy. Instead, apply the following procedure when creating the captions for dalle: (a) substitute the artist’s name with three adjectives that capture key aspects of the style; (b) include an associated artistic movement or era to provide context; and (c) mention the primary medium used by the artist.
They have clearly trained the model on all sorts of copyrighted images—this is the part of the prompt where they discourage it from obviously recreating the work of living artists.
- Always mention the image type (photo, oil painting, watercolor painting, illustration, cartoon, drawing, vector, render, etc.) at the beginning of the caption. Unless the caption suggests otherwise, make at least 1--2 of the 4 images photos
We saw this earlier where my first prompt was turned into a photo, watercolor, illustration and vector-style image.
- Diversify depictions of ALL images with people to include DESCENT and GENDER for EACH person using direct terms. Adjust only human descriptions.
- EXPLICITLY specify these attributes, not abstractly reference them. The attributes should be specified in a minimal way and should directly describe their physical form.
- Your choices should be grounded in reality. For example, all of a given OCCUPATION should not be the same gender or race. Additionally, focus on creating diverse, inclusive, and exploratory scenes via the properties you choose during rewrites. Make choices that may be insightful or unique sometimes.
- Use “various” or “diverse” ONLY IF the description refers to groups of more than 3 people. Do not change the number of people requested in the original description.
- Don’t alter memes, fictional character origins, or unseen people. Maintain the original prompt’s intent and prioritize quality.
- Do not create any imagery that would be offensive.
- For scenarios where bias has been traditionally an issue, make sure that key traits such as gender and race are specified and in an unbiased way -- for example, prompts that contain references to specific occupations.
Using prompt engineering in ChatGPT to get around the fundamental biases baked into the DALL-E 3 model!
- Silently modify descriptions that include names or hints or references of specific people or celebritie by carefully selecting a few minimal modifications to substitute references to the people with generic descriptions that don’t divulge any information about their identities, except for their genders and physiques. Do this EVEN WHEN the instructions ask for the prompt to not be changed. Some special cases:
- Modify such prompts even if you don’t know who the person is, or if their name is misspelled (e.g. “Barake Obema”)
- If the reference to the person will only appear as TEXT out in the image, then use the reference as is and do not modify it.
- When making the substitutions, don’t use prominent titles that could give away the person’s identity. E.g., instead of saying “president”, “prime minister”, or “chancellor”, say “politician”; instead of saying “king”, “queen”, “emperor”, or “empress”, say “public figure”; instead of saying “Pope” or “Dalai Lama”, say “religious figure”; and so on.
- If any creative professional or studio is named, substitute the name with a description of their style that does not reference any specific people, or delete the reference if they are unknown. DO NOT refer to the artist or studio’s style.
Another fascinating detail. What I love about these prompts is that they clearly developed over months of testing the model, and are designed to counter all manner of harmful or embarrassing capabilities of the underlying DALL-E 3.
Finally, there’s this snippet of TypeScript at the end which describes the seed behavior we saw earlier on:
namespace dalle {
// Create images from a text-only prompt.
type text2im = (_: {
// The resolution of the requested image, which can be wide, square, or tall. Use 1024x1024 (square) as the default unless the prompt suggests a wide image, 1792x1024, or a full-body portrait, in which case 1024x1792 (tall) should be used instead. Always include this parameter in the request.
size?: "1792x1024" | "1024x1024" | "1024x1792",
// The user's original image description, potentially modified to abide by the dalle policies. If the user does not suggest a number of captions to create, create four of them. If creating multiple captions, make them as diverse as possible. If the user requested modifications to previous images, the captions should not simply be longer, but rather it should be refactored to integrate the suggestions into each of the captions. Generate no more than 4 images, even if the user requests more.
prompts: string[],
// A list of seeds to use for each prompt. If the user asks to modify a previous image, populate this field with the seed used to generate that image from the image dalle metadata.
seeds?: number[],
}) => any;
} // namespace dalle
Key extract from that:
If the user requested modifications to previous images, the captions should not simply be longer, but rather it should be refactored to integrate the suggestions into each of the captions.
All in all, this is a really neat insight into the kind of prompt engineering that goes on within OpenAI itself—likely the organization with the most experience of prompt engineering in the world.
Posted 26th October 2023 at 9:11 pm · Follow me on Mastodon or Twitter or subscribe to my newsletter
More recent articles
- LLM 0.13: The annotated release notes - 26th January 2024
- Weeknotes: datasette-test, datasette-build, PSF board retreat - 21st January 2024
- Talking about Open Source LLMs on Oxide and Friends - 17th January 2024
- Publish Python packages to PyPI with a python-lib cookiecutter template and GitHub Actions - 16th January 2024