Why Do AI Prompts Use Brackets?
Difficultylevel:
Industry:
Modality:
Specialisedtopics:
Technique:
Introduction
In the world of AI-generated content, particularly with text-to-image models, using brackets in prompts is a powerful technique. This article explores their use, focusing specifically on Stable Diffusion models.
The Core Purpose of Brackets in AI Prompts
Brackets in AI prompts are a form of prompt engineering used to direct the model’s attention to specific elements. This technique, commonly applied in diffusion models like Stable Diffusion developed by Stability AI1, helps users emphasise or de-emphasise different aspects of the generated image.
How It Works: The Technical Details
Brackets ({}, []) and numerical attention (e.g., (word:1.3)) are custom features in interfaces such as Automatic11112 and InvokeAI3, which extend the functionality of Stable Diffusion. Here’s how they work:
Tokenization: The prompt is broken into tokens, each mapped to an integer ID.
Embedding: Tokens are converted into vectors (e.g., 768 dimensions for CLIP4) to represent their meanings.
Positional Embedding: Sequence information is added to maintain context.
Transformer Processing: Token and positional embeddings are combined to capture relationships between words.
Attention Weighting:
- Brackets: Modify attention; for instance, ((word)) increases influence, while [[word]] reduces it.
- Numerical Attention: (word:1.3) applies a specific multiplication factor to the attention weight.
Note: These features are custom to tools like Automatic11112 and InvokeAI3 and are not part of the original CLIP4 or baseline Stable Diffusion models.
Types of Brackets and Their Effects
Different bracket types can be used to apply varying levels of emphasis to words or phrases in your prompts:
Bracket Type | Example | Emphasis Level |
---|---|---|
Single brackets | (word) | Slight emphasis |
Double brackets | ((word)) | Moderate emphasis |
Triple brackets | (((word))) | Strong emphasis |
Square brackets | [word] | Reduced emphasis |
Numerical Attention
For fine-tuned control, you can use (word:weight):
- (word:1.5) increases the attention weight by a factor of 1.5 (50%).
- (word:0.25) decreases the attention weight by a factor of 1.75 (75%).
Example: “I want to see a (beautiful:1.5) (scary:0.5) [haunted:0.25] forest.” Here, “beautiful” is highlighted, “scary” is downplayed, and “haunted” is diminished due to the square brackets.
Why Word Weighting Matters
Word weighting allows for precise control over the final image, helping you to:
- Highlight key elements
- Downplay less important aspects
- Achieve more intentional results
This level of control is crucial for creative projects that require precise visual balance.
A Practical Guide to Using Brackets in AI Prompts
With the theory of bracket usage covered, let’s see it in action. The following examples demonstrate the impact of brackets on prompts and their resulting images.
Basic Bracket Usage
Specs for the examples:
- Model: SDXL-Lightning 4 Step5
- Seed: 141119621523812
Example 1: Emphasising a Single Element
- Without brackets: A red apple on a wooden table
- With brackets: A ((red apple)) on a wooden table
In the bracketed version, the apple appears more vibrant and becomes the central focus of the image.
Example 2: De-emphasising an Element
- Without brackets: A bustling cityscape with a bright sun
- With brackets: A bustling cityscape with a [bright sun]
Here, the square brackets around “bright sun” result in a more subdued sun, allowing the cityscape to become more prominent.
Advanced Bracket Techniques
Example 3: Multiple Emphasis Levels
- Base prompt: A forest with a river and mountains
- With varied emphasis: A ((forest)) with a (river) and [mountains]
This example shows how different levels of bracketing can create a hierarchy of focus within the image.
Example 4: Combining Positive and Negative Emphasis
- Without brackets: A vintage car in front of a modern building
- With brackets: A ((vintage car)) in front of a [modern building]
This combination results in a more prominent and detailed vintage car, while the modern building recedes into the background.
Tips for Effective Bracket Usage
- Start subtle: Begin with single brackets and gradually increase emphasis as needed.
- Balance is key: Overusing brackets can lead to unnatural-looking images.
- Experiment: Different models may interpret brackets slightly differently, so don’t be afraid to experiment.
- Combine with other techniques: Brackets can be used alongside other prompt engineering techniques for even more control.
Remember, the goal is to guide the AI toward your vision, not to force it. With practice, you’ll develop an intuition for how to use brackets most effectively in your prompts.
ComfyUI vs Other Tools
ComfyUI6 offers greater sensitivity in handling prompt strengths by not normalizing them. For example, a prompt like (masterpiece:1.2) (best:1.3) (quality:1.4) girl is applied exactly as specified, allowing for precise control over each element. In contrast, interfaces like a11112 UI normalize prompt strengths by averaging them across all tokens, resulting in weights such as (masterpiece:0.98) (best:1.06) (quality:1.14) (girl:0.81). This normalization leads to less sensitive and more balanced weighting of each prompt component. The direct application in ComfyUI makes it ideal for users seeking detailed adjustments in their image generation.
Advanced Models and Techniques
Recent advancements in AI models have further refined the process of prompt interpretation and image generation:
- Stable Diffusion XL (SDXL): This model, introduced in the paper “SDXL: Improving Latent Diffusion Models for High-Resolution Image Synthesis”7, offers enhanced capabilities in generating high-quality images from prompts.
- Stable Diffusion 3 (SD3): The latest iteration, detailed in “Stable Diffusion 3: Delivering Unprecedented Performance, Quality, and Adaptability in Image Generation”8, introduces a novel architecture that improves prompt processing and image quality.
- Direct Preference Optimisation (DPO): This fine-tuning technique, explained in “Direct Preference Optimisation: Your Language Model is Secretly a Reward Model”9, has been applied to models like SD3 to enhance prompt understanding and image aesthetics.
- Takara.ai Image Datasets: We applied the bracket prompt engineering technique to create stunning artwork in our Open Source datasets, demonstrating the practical application of these techniques in large-scale image generation projects. View them in our Art Gallery.
Other companies are also making significant strides in this field. For example, Black Forest Labs’ Flux.110 model shows similar architectural advancements and performance to SD38. Although not a Stable Diffusion model, many prompt engineering techniques, including bracket use, might also apply to Flux.1.
Conclusion
Brackets in AI prompts offer precise control over image generation. Though not part of the base Stable Diffusion model, they are widely used in popular interfaces. Experiment with different combinations to see their effects and stay updated with the latest model documentation.
If you’re interested in another advanced technique, this time for LLM’s, see our Mega Prompts guide.
GitHub Repository for the Stable Diffusion Web UI by AUTOMATIC1111 ↩︎ ↩︎ ↩︎
GitHub Repository for InvokeAI, an Open-Source Toolkit for Generative AI ↩︎ ↩︎
Research Paper on Diffusion Models and Their Applications, 2021 ↩︎ ↩︎
Research on Innovative Techniques in Generative Modeling, 2024 ↩︎
Why do I get different images from the a1111 UI even when I use the same seed? ↩︎
Rombach et al., 2023, SDXL: A Scalable Latent Diffusion Model for High-Resolution Image Synthesis ↩︎
Research on Scaled Rectified Flow Transformers for Enhanced Image Synthesis, 2024 ↩︎ ↩︎
Last modified: November 8, 2024