Generates anime tags using databases and models for tokenizing.
Go to file
toshiaki1729 374325e3e2 Squashed commit of the following:
commit 0571f2dab8bf3d8e1826f0fb5d53ca5b9bfcf6b0
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 01:05:27 2022 +0900

    Update README.md

commit b4a5164081662db9085e2b5c17af6e98473180ff
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:44:25 2022 +0900

    remove

commit 127946a3d200825eb15244ad09db5361db8bf89c
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:28:28 2022 +0900

    Revert "remove"

    This reverts commit f7666de150d1bb8acdcedcb0b82ddfb939206088.

commit f7666de150d1bb8acdcedcb0b82ddfb939206088
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:26:44 2022 +0900

    remove

commit 41b99ba60bd59050384bdd55a498395e4148bfda
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:26:20 2022 +0900

    Update .gitignore

commit 2fdce554bdd92bc87dce13181aa67c58d523d830
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:24:56 2022 +0900

    Update .gitignore

commit 50927e064e5ffe052d785038f4c7de851ede6c91
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:23:49 2022 +0900

    upload database

commit 39172118e8d8fac2ed7f3aab0c53e2a6e89c16b3
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:22:34 2022 +0900

    Update .gitignore

commit 7c6225ade3a55fdf342eb2b3617302edab595192
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:21:25 2022 +0900

    Create test

commit 8010ec05a5e7836fc004450bc82cc3ce93d975ad
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:20:22 2022 +0900

    Update .gitignore

commit 6265874465281db81a3935f651537ac9c6cfc30a
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Wed Dec 28 00:17:17 2022 +0900

    update README.md

commit 3f52e109aa0b7a41f4970b11b933c7f57c7ddd62
Merge: 180c4c5 867a48a
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Tue Dec 27 23:20:32 2022 +0900

    Merge branch 'main' into feature/well-filtered-database

commit 180c4c5b414058939eb47dfe7783eb561c5da65e
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Tue Dec 27 23:19:51 2022 +0900

    implement dynamic database loader

commit fdccc1a9cb9a80ce9b4042892afc9922a20e6524
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Sun Dec 25 19:39:32 2022 +0900

    Update README.md

commit b539cbf4d3791777e424883b2a5bd64a73de9bf0
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Sun Dec 25 19:34:11 2022 +0900

    remove thread lock to allow generating prompt while doing other tasks

commit 43b5bfd73a549f2bced6704cdcfacb1483648b17
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Sun Dec 25 19:26:26 2022 +0900

    update README

commit 58df449f36678de2e9b35726315d53a281bdc380
Author: toshiaki1729 <116595002+toshiaki1729@users.noreply.github.com>
Date:   Sun Dec 25 19:05:30 2022 +0900

    add new language model and database

    The size of data will be so large
2022-12-28 01:10:02 +09:00
.github/workflows Create codeql.yml 2022-12-25 00:47:05 +09:00
data/danbooru Squashed commit of the following: 2022-12-28 01:10:02 +09:00
pic Squashed commit of the following: 2022-12-28 01:10:02 +09:00
scripts Squashed commit of the following: 2022-12-28 01:10:02 +09:00
.gitattributes Initial commit 2022-12-24 22:00:14 +09:00
.gitignore Squashed commit of the following: 2022-12-28 01:10:02 +09:00
README.md Squashed commit of the following: 2022-12-28 01:10:02 +09:00

README.md

text2prompt

This is an extension to make prompt from simple text for Stable Diffusion web UI by AUTOMATIC1111.
Currently, only prompts consisting of some danbooru tags can be generated.

Installation

Extensions tab on WebUI

Copy https://github.com/toshiaki1729/stable-diffusion-webui-text2prompt.git into "Install from URL" tab and "Install".

Install Manually

To install, clone the repository into the extensions directory and restart the web UI.
On the web UI directory, run the following command to install:

git clone https://github.com/toshiaki1729/stable-diffusion-webui-text2prompt.git extensions/text2prompt

Usage

  1. Type some words into "Input Theme"
  2. Push "Generate" button

Tips

  • For more creative result
    • increase "k value" or "p value"
    • disable "Use weighted choice"
    • use "Cutoff and Power" and decrease "Power"
    • or use "Softmax" (may generate unwanted tags more often)
  • For more strict result
    • decrease "k value" or "p value"
    • use "Cutoff and Power" and increase "Power"
  • You can enter very long sentences, but the more specific it is, the fewer results you will get.

How it works

It's doing nothing special;

  1. Danbooru tags and it's descriptions are in the data folder
  2. Tokenize your input text and calculate cosine similarity with all tag descriptions
  3. Choose some tags depending on their similarities

Database (Optional)

You can choose the following dataset if needed.
Download the following, unzip and put its contents into text2prompt-root-dir/data/danbooru/.

Tag description all-mpnet-base-v2 all-MiniLM-L6-v2
well filtered (recommended) download (preinstalled) download
normal (same as previous one) download download
full (noisy) download download

well filtered: Tags are removed if their description include the title of the work. These tags are heavily related to a specific work, meaning they are not "general" tags.
normal: Tags containing the title of a work, like tag_name(work_name), are removed.
full: Including all tags.


More detailed description

i \in N = \\{1, 2, ..., n\\} for index number of the tag
s_i = S_C(d_i, t) for cosine similarity between tag description d_i and your text t P_i for probability for the tag to be chosen

"Method to convert similarity into probability"

"Cutoff and Power"

$p_i = \text{clamp}(s_i, 0, 1)^{\text{Power}} = \text{max}(s_i, 0)^{\text{Power}

"Softmax"

$p_i = \sigma(\\{s_n|n \in N\\})_i = \dfrac{e^{s_i}}{ \Sigma_{j \in N}\ e^{s_j} 

"Sampling method"

Yes, it doesn't sample like other "true" language models do, so "Filtering method" might be better.

"NONE"

$P_i = p_

"Top-k"

$
P_i = \begin{cases} 
\dfrac{p_i}{\Sigma p_j \text{ for all top-}k} & \text{if } p_i \text{ is top-}k \text{ largest in } \\{p_n | n \in N \\} \\
0 & \text{otherwise} \\
\end{cases}

"Top-p (Nucleus)"

  • Find smallest N_p \subset N such that \Sigma_{i \in N_p}\ p_i\ \geq p
    • set N_p=\emptyset at first, and add index of p_{(k)} into N_p where p_{(k)} is the k-th largest in \\{p_n | n \in N \\} for k = 1, 2, ..., n, until the equation holds.

P_i = \begin{cases} 
\dfrac{p_i}{\Sigma p_j \text{ for all }j \in N_p} & \text{if } i \in N_p \\
0 & \text{otherwise} \\
\end{cases}

Finally, the tags will be chosen randomly while the number \leq "Max number of tags".