diff --git a/README.md b/README.md index 4938cfb..8389f9c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ git clone https://github.com/toshiaki1729/stable-diffusion-webui-text2prompt.git It's doing nothing special; 1. Danbooru tags and it's descriptions are in the `data` folder - - descriptions are generated from wiki and already tokenised + - descriptions are generated from wiki and already tokenized - [all-mpnet-base-v2](https://huggingface.co/sentence-transformers/all-mpnet-base-v2) model is used to tokenize the text - for now, some tags (such as <1k tagged or containing title of the work) are deleted to prevent from "noisy" result 1. Tokenize your input text and calculate cosine similarity with all tag descriptions @@ -39,13 +39,16 @@ git clone https://github.com/toshiaki1729/stable-diffusion-webui-text2prompt.git ### More detailed $i \in N = \\{1, 2, ..., n\\}$ for index number of the tag cosine similarity between tag description $d_i$ and your text $t$ : $S_C(d_i, t) = s_i$ - probablity for the tag to be chosen : $P_i$ + probability for the tag to be chosen : $P_i$ - ### "Method to convert similarity into probablity" + ### "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}}$ + + $$p_i = \text{clamp}(s_i, 0, 1)^{\text{Power}} = \text{max}(s_i, 0)^{\text{Power}}$$ + #### "Softmax" - - $p_i = \text{softmax}(s_i)$ + + $$p_i = \sigma(\\{s_n|n \in N\\})_i = \dfrac{e^{s_i}}{ \Sigma_{j \in N}\ e^{s_j} }$$ ### "Sampling method" #### "NONE" @@ -56,18 +59,18 @@ git clone https://github.com/toshiaki1729/stable-diffusion-webui-text2prompt.git $$ P_i = \begin{cases} - \frac{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 \\} \\ + \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)" - - $N_p \subset N$ such that $\Sigma_{i \in N_p}\ p_i\ \geq p$ - - set $N_p=\emptyset$ at first, and add $k$ into $N_p$ where $p_k$ is the $k$-th largest in $\\{p_n | n \in N \\}$, while the equation holds. - + - 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} -\frac{p_i}{\Sigma p_j \text{ for all }j \in N_p} & \text{if } i \in N_p \\ +\dfrac{p_i}{\Sigma p_j \text{ for all }j \in N_p} & \text{if } i \in N_p \\ 0 & \text{otherwise} \\ \end{cases} $$