Using Underscores in a Stable Diffusion Prompt

Underscores (_) in Stable Diffusion prompts serve an important function – they allow you to specify multiple words or phrases as a single token. This can help the AI model better understand and generate images based on your prompt.

Here are some key things to know about using underscores:

How Underscores Work

  • Underscores combine multiple words into a single token that the AI model recognizes as a unit. For example:

This whole phrase would be understood by the model as a single concept instead of separate words.

  • Spaces between words are ignored when there is an underscore. So cat_playing_with_yarn is seen as a single token, while cat playing with yarn would be interpreted as 3 separate tokens.
  • The model has been trained to recognize phrases with underscores as cohesive ideas. So it can generate images reflecting the full concept instead of getting confused by separate words.

When to Use Underscores

Here are some cases where using underscores in your prompt can be helpful:

  • Specifying a subject or theme: Use underscores to indicate the overall topic or subject matter you want generated. For example: sci_fi_cityscape.
  • Linking related descriptors: Combine descriptive terms with underscores so they are seen as related instead of separate ideas. For example: muscular_heroic_warrior.
  • Avoiding unwanted mixes: Using underscores prevents the model from mixing incompatible ideas from separate words in the prompt. For example, using angel_wings instead of angel wings prevents it from generating an angel with literal wing-shaped objects.
  • Emphasizing style/medium: Styles and mediums work well linked by underscores, like impressionist_oil_painting or art_deco_architecture.

Prompt Structure Tips

  • Place underscores between words you want to link, but use spaces between separate modifier phrases:
  heroic_warrior wearing armor standing on mountain 
  • Avoid overusing underscores, as too many can overspecify the prompt and limit the AI’s creativity. Generally use them only for key theme phrases.
  • Pay attention to order – place the most important phrase first when linking terms: warrior_wearing_armor not wearing_armor_warrior

Prompt Examples Using Underscores

Here are some examples of good prompts using underscores effectively:

Specifying a Theme/Subject

underwater_ruins, highly detailed digital painting
japanese_courtyard with blooming sakura trees, oil painting  
dragon_wizard casting spell, trending on artstation

Linking Related Descriptors

muscular_heroic_warrior wearing futuristic armor
wise_powerful_wizard with long white beard

Avoiding Unwanted Mixes

fairy_wings on a glowing pixie, by Greg Rutkowski
angel_halo above the head of a praying nun

Emphasizing Style/Medium

steampunk_airship soaring through clouds, matte painting
impressionist_landscape with sparkling lake, by Claude Monet
art_deco_poster advertising luxury cruise ship  

Advanced Prompt Engineering with Underscores

As you get more advanced, you can use underscores for some additional prompt engineering tactics:

Create “Concept Tokens”

Invent new concept tokens that don’t exist yet by linking words with underscores. For example:

star_bridge connecting two galaxies
tree_castle with elaborate wood carvings

Because these terms don’t already exist, the AI has more creative freedom in generating them.

Guide Association Strength

Use more or less underscores to indicate association strength between terms. For example:

sword_and_sorcery_wizard (high association)
sword and sorcery wizard (lower association)

Fewer underscores mean the terms have lower affinity and can be mixed more freely.

Isolate Key Elements

Set apart key elements from modifiers by only using underscores on the core phrase. For example:

heroic_warrior wearing armor standing on mountain
family_portrait against a white background 

This keeps the model focused on the main theme.

Useful Stable Diffusion Resources:

Using underscores deliberately in Stable Diffusion prompts gives you more control over the AI model and allows you to engineer better results. Take time to experiment with different prompt structures to see what works best. With practice, you’ll be able to create incredibly detailed and creative images through thoughtful prompt design.