/prompting

Learning the basics of prompting

This is an experiment with prompt tweaking, prompt engineering, prompt design, or any future prompt [blank] terminology that becomes popular. These images are the result of giving AI input text (prompts) to generate the desired output.  While AI is improving daily, neural networks still make associations that can be unclear even to programmers. Here, I work through some of the nuances of prompting, testing different keywords, phrases, and biases to achieve different outputs. To accurately compare them, I’ve kept the seed value constant, ensuring that the differences between A/B prompts aren’t random.

Prompt Skeleton

A good generic prompt skeleton to build from is “[subject] in [background], <b> [framing], [style]</b>” This structure provides a clear and concise template that helps guide the AI in generating images.

Structure
Big picture, prompts are free-form, but there are some elements you should always consider: subject, background, framing, and style. The prompt skeleton I’m using to build from is “[subject] in [background], [framing], [style]“. Image generators like MidJourney are sensitive to style cues, even if they are buried in your prompt.

In the two images below, I’ve added framing and style tokens. “Dynamic Perspective” reframes the subject, moving it out of the center of the frame, and adds more depth to the image. “Cinematic Lighting” adjusts the hues, saturation, and luminance of the teals and oranges, drastically improving the style of our image.
Retrofuturistic Transportation Hub in the Swiss Alps

retrofuturism transportation hub at the top of the swiss alps, Popular Mechanics 1970s style –seed 1243093561

Retrofuturistic Transportation Hub in the Swiss Alps
retrofuturism transportation hub at the top of the swiss alps, dynamic perspective, cinematic lighting, Popular Mechanics 1970s style –seed 1243093561
Seed Value
Each MJ prompt starts with a seed value. The seed value represents a mathematically extrapolated square of random noise for an image generator diffuser to shape into an image. Or, more simply, each seed value is a random dispersion of noise for the image generator to “diffuse” or turn into an image. If you use the exact same prompt with the exact same seed value, you will get an identical result. However, the slightest change in your prompt can visibly alter outcomes.

For example, to a person, Prompt #1 (“Amazonian Jungle” vs. “Jungle in the Amazon”) would read identically. However, to the image generator, this slight variation is enough for the diffuser to interpret the prompt differently in terms of style and composition. Prompt #2 illustrates the random nature of seeds. Adjacent seeds won’t necessarily correspond to each other. Using an identical prompt, the adjacent seed produces a different style, composition, and giant, similar to modifying the prompt in example #1. In the grand scheme, you don’t need to worry about seeds unless you’re trying to make comparisons or testing.

a large tree of wisdom stands above the canopy in a rain drenched Amazonian Jungle –seed 4567

a large tree of wisdom stands above the canopy in a rain drenched jungle in the amazon –seed 4567

a giant looks down from a mountain at night on a frostbitten town –seed 4567

a giant looks down from a mountain at night on a frostbitten town –seed 4568

Tokens
‘Tokenisation’ is the process of our AI Image Generator (in this case MidJourney) converting our prompt into smaller units ‘tokens’ like words and subwords so that AI can begin to understand what we’re trying to accomplish. You can dive into the science behind AI neural networks, and how they connect our natural language with images here. To oversimplify the process, once the prompt is converted into a string of tokens, the AI begins to assign “values” to tokens and combinations of tokens to help conceptualize the image. Higher-value tokens will overpower weaker ones, combinations will activate associations in the neural network, and punctuation (mostly commas) will separate ideas or concepts.

In this example, the base prompt uses punctuation to keep concepts like ‘kid’, ‘steam’, and ‘punk’ separated, along with a camera type and lens (more on that coming up). To test out some high-value tokens and combination tokens, I’ve changed ‘kid’ to ’10-year-old’, which is a great way to produce a more accurate image of age, despite consisting of 5+ tokens. Removing the comma from ‘steam punk’ illustrates how high-value tokens and phrases, such as the style ‘steampunk’, take precedence over the two individual tokens. Lastly, we’ve included ‘cinematic lighting’ and a camera type from the prior prompt to add some extra styling.
AI Generated Picture of Small Kid Running

kid running through the streets, nikon D5 85mm –seed 3446087434

AI Generated Picture of Steam Punk Kid Running

10-year-old running through the streets, steampunk, cinematic lighting, nikon D5 85mm  –seed 3446087434

Prompt Bias in the Neural Network
Image generators are trained on millions of images with haphazard descriptions and minimal manual curation of the text-to-image datasets. The images that are generated from prompts are influenced by English descriptions that carry societal biases. When crafting a prompt, it’s important to take a step back and consider how someone might describe their photo when uploading it online.

A common mistake is to use the word “photorealistic” in hopes of generating a life-like image, when in reality it will guide an image in the opposite direction. “Photorealism” is a painting style, so using it in a prompt will heavily influence the direction. If you’re looking for a life-like photo, you have to tag it how a photographer would, and that is by adding camera and lens information.

Another example of prompt bias is that most text-to-image datasets are trained on English images. For instance, typing “man” will almost always generate an Anglo-looking man unless you specify an ethnicity or nationality. In the prompts below, I explored prompt bias and successfully transformed my original prompt into a life-like image of a Spanish man in a garden, and used a detailed age phrase to help create the image I wanted.

70-year-old man in a garden, portrait, photorealistic –seed 4233915284

70-year-old Spanish Man in a garden, portrait, hassleblad-hkd 35mm photograph –seed 4233915284

Token Order
Another prompt bias to consider is that our AI is trained on the english language, so it carries a left-to-right bias. Meaning that early tokens or phrases in your prompt will receive the most attention. By rearranging the order of tokens, phrases or concepts in the prompt, you can place more focus on valuable tokens needed to achieve the visual you want without having to remove parts of your prompt.

Below, by placing the concept “energetic modern sci-fi castle and city” at the front of our prompt, we were able to generate an image that emphasizes a futuristic civilization and deprioritize the tokens about the environment, while maintaining the same look as the original image.

rugged temperate rainy climate, landscape photography, Canon EOS R5 24mm lens, wide-angle shot, cinematic ambience, energetic modern sci-fi castle and city –seed 4215541482

energetic modern sci-fi castle and city, Canon EOS R5 24mm lens, wide-angle shot, cinematic ambience, rugged temperate rainy climate, landscape photography –seed 4215541482
Overpowered Tokens
Not all tokens are created equal. Some tokens are so famous and high-value that they overpower the prompt, even if we place them at the end to try to divert focus from them.

Here are two examples of ultra high-value tokens. In example #1, I tested MidJourney’s capability to combine two famous subjects: the children’s show ‘Dora the Explorer’ and the famous painting ‘Starry Night’ by Van Gogh. ‘Starry Night’ is so famous and popular that it completely overrides the other two tokens. It applies the distinct brushwork of ‘Starry Night’ to the entire image, missing the intent of the prompt. The best MidJourney can do is to have Dora walk through the frame. By removing the overpowered token and replacing it with “priceless artwork”, I was able to refocus the image generator, resulting in a much better example of the original prompt.

Dora the Explorer walking around paris, finding Van Goghs Starry Night –seed 1278245832

Dora the Explorer walking around paris, finding priceless artwork –seed 1278245832
The next example demonstrates how a high-value token embedded within a word can similarly hijack the image generation process. Words like “dog”, “cat”, “man”, “woman”, akin to our famous token in the first example, tend to steer the image generator towards a singular focus. In this instance, “dog” was part of the subject token and led MidJourney to create a yellow Labrador in the middle of a dogwood tree. To mitigate the impact of this high-value token, I had to ‘uplevel’ the token by using the scientific name for my subject. By employing a more specific name for the subject, you can “focus out” the image generator and reduce the emphasis on the high-value token. Adding ‘Cornus florida’ to the prompt successfully generated an image of a dogwood tree without the high-value token dominating.
Dogwood –seed 753181390

Cornus florida dogwood –seed 753181390