Sign In

Make your own Textual Inversions with just a simple Prompt (Embedding Merge Tutorial)

Make your own Textual Inversions with just a simple Prompt (Embedding Merge Tutorial)

The Easy Guide to Creating Textual Inversions with Stable Diffusion

Last Updated Feb 2024 (Originally Published Mid 2023)

Preface

This guide provides a straightforward method to create your own Textual Inversions (TIs). While it doesn't replace traditional training, which offers numerous advantages, it serves as an efficient way to store prompts for future use. Note that this tool now works with SDXL and outputs safetensors by default, eliminating the need for manual conversion.

Introduction to the Tool

This tool is an extension for the AUTOMATIC1111/stable-diffusion-webui, designed for creating and merging Textual Inversion embeddings at runtime from string literals. You can find it on the Stable Diffusion WebUI Embedding Merge GitHub page. The Usage and some of the updated text is heavily borrowed from the original repository, please note it was added for better clarification on how to make your Embedding.

Purpose

Stable Diffusion interprets your prompts using tokens, which are multidimensional numerical vectors that represent words and phrases. This extension allows you to create new words by merging different vectors, potentially combining meanings. However, results may vary, and it's a feature worth experimenting with.

How to Install an Extension via Automatic1111 WebUI

  1. Open Automatic1111 WebUI:

    • Launch your Automatic1111 WebUI in your browser.

  2. Go to Extensions Tab:

    • Navigate to the "Extensions" tab in the WebUI.

  3. Install from URL:

    • Click on "Install from URL."

  4. Paste the GitHub URL:

    • Paste the following URL into the provided box: https://github.com/klimaleksus/stable-diffusion-webui-embedding-merge.

  5. Install the Extension:

    • Click the "Install" button to install the extension.

  6. Reload the UI:

    • After installation, reload your WebUI to apply the changes.

How to Create a Textual Inversion

  1. Install and Restart:

    • Ensure the extension is installed and restart the UI.

  2. Prepare Your Prompt:

    • Use the txt2img or img2img tools to create a prompt. Ensure it is correctly spaced and under 75 tokens for SD 1.5, and up to 77 vector tokens for SDXL.

  3. Checking Token Length:

    • In the WebUI, you can check your token length in either the Text to Image or Image to Image tabs. Note that the limit refers to the number of tokens, not words. Tokens are subword units used by the model to process text. For example, "running" might be split into "run" and "ning" as two tokens.

  4. Safety of PT Files:

    • Creating your own PT files in A1111 is safe. As of 2024, you do not need to convert your files to safetensors; the output now comes as safetensors by default.

  5. Input Your Prompt:

    • Paste your prompt into the larger text box in the tool.

    • Enter a relevant token name for your TI in the second text box.

  6. Troubleshooting:

    • If it fails, check your spacing and token count. Remove unnecessary words or phrases to meet the token limit.

  7. Training vs. Creating TIs:

    • Training TIs usually yields better results. This method is a quick alternative but may not be as effective.

Usage Instructions

The EM tab in the extension can be used to:

  • Inspect your prompt or specific words.

  • Create TI embeddings from text fragments with or without merging.

  • Check the correctness of your merge expressions.

Merging Tokens

Use the syntax < 'one thing' + 'another thing' > to merge terms "one thing" and "another thing" into a single embedding in your positive or negative prompts at runtime.

Examples:

  • < 'your words' * 0.5 > to adjust the influence of "your words".

  • (< 'one' + 'two' >:0.9) to use attention with round brackets.

Viewing Text or Embedding Vectors

Paste your prompt into the textbox in the EM tab to see how it is parsed by the WebUI. The extension will show detected Textual Inversion embeddings along with literal text tokens. This helps ensure your prompt is interpreted as expected.

Test Merge Expressions

Enter a "merge expression" in the EM tab to see how it will be parsed and combined by the extension. For example, 'greg rutkowski'/4 + 'gustav dore'*0.75.

Expression syntax includes:

  • 'one' + 'two' for addition.

  • 'text' * NUM for multiplication.

  • 'text' : NUM to change vector count.

  • Use curly brackets {} if other extensions interfere with the angular bracket syntax.

Using Merge Expressions in Prompts

You can place merge expressions in angular or curly brackets in your txt2img or img2img prompts. The extension will create temporary TI embeddings that replace the expressions, allowing for complex prompt structures.

Several Merge Expressions

Combine different subjects or styles using merge expressions:

  • A realistic photo of the < 'girl' + 'doll' > in a rainbow dress standing on a shore.

  • Art by < 'greg rutkowski' * X + 'hayao miyazaki' * Y > style.

Changing Word Weights

Adjust the influence of words in your prompt:

  • A < 'peacock' * X > is standing on top of < 'giraffe' * Y >.

  • worst quality, ugly, < 'bad anatomy,':0 > blurry, cropped.

High multipliers can increase the presence of a concept, while lower values can diminish it.

Practical Examples

To merge strings of unequal length, pad the shortest one with zero vectors:

  • 'close-up', 00, 00 + 'out-of-frame' + 'cropped', 00, 00, 00, 00

  • 'up', 00, 00 + 'of-frame' + 'cropped', 00, 00, 00

Use Cases

  • Prepare a prompt for actual training by using existing embeddings for initialization.

  • Test and refine merge expressions before creating a regular TI embedding.

Earth & Dusk Community and Support

Join our supportive community and access additional resources:

Celebrations and Awareness

Support Plural Pride Month and Disability Pride Month in July. Learn more about the plural community at The Plural Association.

Enjoy the Journey

Explore and experiment with the features of this extension to enhance your creative prompts. Never be ashamed of your quirks; embrace them and join our community for support and inspiration.

23

Comments