Upload 2 files
Browse files
Google Colab Notebooks/sd_token_similarity_calculator.ipynb
CHANGED
|
@@ -251,10 +251,32 @@
|
|
| 251 |
"\n"
|
| 252 |
],
|
| 253 |
"metadata": {
|
| 254 |
-
"id": "rUXQ73IbonHY"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
},
|
| 256 |
-
"execution_count":
|
| 257 |
-
"outputs": [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 258 |
},
|
| 259 |
{
|
| 260 |
"cell_type": "code",
|
|
@@ -2857,8 +2879,104 @@
|
|
| 2857 |
"\n"
|
| 2858 |
],
|
| 2859 |
"metadata": {
|
| 2860 |
-
"id": "JR0wl2ecj6RJ"
|
| 2861 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2862 |
},
|
| 2863 |
"execution_count": null,
|
| 2864 |
"outputs": []
|
|
|
|
| 251 |
"\n"
|
| 252 |
],
|
| 253 |
"metadata": {
|
| 254 |
+
"id": "rUXQ73IbonHY",
|
| 255 |
+
"outputId": "18df4768-39a6-4ca9-8c5a-47317001e907",
|
| 256 |
+
"colab": {
|
| 257 |
+
"base_uri": "https://localhost:8080/"
|
| 258 |
+
}
|
| 259 |
},
|
| 260 |
+
"execution_count": 1,
|
| 261 |
+
"outputs": [
|
| 262 |
+
{
|
| 263 |
+
"output_type": "stream",
|
| 264 |
+
"name": "stdout",
|
| 265 |
+
"text": [
|
| 266 |
+
"/content\n",
|
| 267 |
+
"/content\n",
|
| 268 |
+
"Cloning into 'text-to-image-prompts'...\n",
|
| 269 |
+
"remote: Enumerating objects: 6051, done.\u001b[K\n",
|
| 270 |
+
"remote: Counting objects: 100% (4169/4169), done.\u001b[K\n",
|
| 271 |
+
"remote: Compressing objects: 100% (2335/2335), done.\u001b[K\n",
|
| 272 |
+
"remote: Total 6051 (delta 2075), reused 3837 (delta 1821), pack-reused 1882 (from 1)\u001b[K\n",
|
| 273 |
+
"Receiving objects: 100% (6051/6051), 37.71 MiB | 6.04 MiB/s, done.\n",
|
| 274 |
+
"Resolving deltas: 100% (2075/2075), done.\n",
|
| 275 |
+
"Updating files: 100% (3079/3079), done.\n",
|
| 276 |
+
"Filtering content: 100% (776/776), 2.23 GiB | 38.41 MiB/s, done.\n"
|
| 277 |
+
]
|
| 278 |
+
}
|
| 279 |
+
]
|
| 280 |
},
|
| 281 |
{
|
| 282 |
"cell_type": "code",
|
|
|
|
| 2879 |
"\n"
|
| 2880 |
],
|
| 2881 |
"metadata": {
|
| 2882 |
+
"id": "JR0wl2ecj6RJ"
|
| 2883 |
+
},
|
| 2884 |
+
"execution_count": null,
|
| 2885 |
+
"outputs": []
|
| 2886 |
+
},
|
| 2887 |
+
{
|
| 2888 |
+
"cell_type": "code",
|
| 2889 |
+
"source": [
|
| 2890 |
+
"# @title Create random suffix pairings\n",
|
| 2891 |
+
"import random\n",
|
| 2892 |
+
"import json\n",
|
| 2893 |
+
"import pandas as pd\n",
|
| 2894 |
+
"import os\n",
|
| 2895 |
+
"import shelve\n",
|
| 2896 |
+
"import torch\n",
|
| 2897 |
+
"from safetensors.torch import save_file\n",
|
| 2898 |
+
"\n",
|
| 2899 |
+
"\n",
|
| 2900 |
+
"def my_mkdirs(folder):\n",
|
| 2901 |
+
" if os.path.exists(folder)==False:\n",
|
| 2902 |
+
" os.makedirs(folder)\n",
|
| 2903 |
+
"\n",
|
| 2904 |
+
"\n",
|
| 2905 |
+
"output_folder = '/content/output/prefix_suffix_pairs/'\n",
|
| 2906 |
+
"my_mkdirs(output_folder)\n",
|
| 2907 |
+
"\n",
|
| 2908 |
+
"_prompts = {}\n",
|
| 2909 |
+
"_text_encodings = {}\n",
|
| 2910 |
+
"nA = 0\n",
|
| 2911 |
+
"\n",
|
| 2912 |
+
"try: loaded3\n",
|
| 2913 |
+
"except:\n",
|
| 2914 |
+
" loaded3 = True\n",
|
| 2915 |
+
" if True:\n",
|
| 2916 |
+
" tmp = '/content/text-to-image-prompts/vocab/text_encodings/prefix/'\n",
|
| 2917 |
+
" for item in ['common','average','rare','weird','exotic'] :\n",
|
| 2918 |
+
" url = tmp + item\n",
|
| 2919 |
+
" prefix, text_encodings, PREFIX_NUM_VOCAB_ITEMS = append_from_url(_prompts , _text_encodings, nA , url , '')\n",
|
| 2920 |
+
" #------#\n",
|
| 2921 |
+
"\n",
|
| 2922 |
+
" if True :\n",
|
| 2923 |
+
" tmp = '/content/text-to-image-prompts/vocab/text_encodings/suffix/'\n",
|
| 2924 |
+
" for item in ['common','average','rare','weird','exotic'] :\n",
|
| 2925 |
+
" url = tmp + item\n",
|
| 2926 |
+
" suffix , text_encodings, SUFFIX_NUM_VOCAB_ITEMS = append_from_url(_prompts , _text_encodings, nA , url , '')\n",
|
| 2927 |
+
" #------#\n",
|
| 2928 |
+
"\n",
|
| 2929 |
+
" if False :\n",
|
| 2930 |
+
" url = '/content/text-to-image-prompts/vocab/text_encodings/emoji/'\n",
|
| 2931 |
+
" prompts , emojis_text_encodings, NUM_VOCAB_ITEMS = append_from_url(_prompts , _text_encodings, nA , url , '')\n",
|
| 2932 |
+
" #------#\n",
|
| 2933 |
+
"#--------#\n",
|
| 2934 |
+
"\n",
|
| 2935 |
+
"if False:\n",
|
| 2936 |
+
" item3 = '#uc# '\n",
|
| 2937 |
+
" while (item3.find('#uc#')>-1 or (not item3.isalpha())) :\n",
|
| 2938 |
+
" item3 = prompts[f'{random.randint(0,NUM_VOCAB_ITEMS)}']\n",
|
| 2939 |
+
" item3 = item3.replace('</w>', '')\n",
|
| 2940 |
+
" #------#\n",
|
| 2941 |
+
"\n",
|
| 2942 |
+
" item4 = '#uc# '\n",
|
| 2943 |
+
" while (item4.find('#uc#')>-1 or (not item4.isalpha())) :\n",
|
| 2944 |
+
" item4 = prompts[f'{random.randint(0,NUM_VOCAB_ITEMS)}']\n",
|
| 2945 |
+
" item4 = item4.replace('</w>', '')\n",
|
| 2946 |
+
" #------#\n",
|
| 2947 |
+
"#------#\n",
|
| 2948 |
+
"\n",
|
| 2949 |
+
"\n",
|
| 2950 |
+
"output = ''\n",
|
| 2951 |
+
"%cd {output_folder}\n",
|
| 2952 |
+
"with open('prefix_suffix_pairs' + '.txt', 'w') as f:\n",
|
| 2953 |
+
" for iter in range (200000):\n",
|
| 2954 |
+
" item = '#uc# '\n",
|
| 2955 |
+
" while (not item.isalpha()) :\n",
|
| 2956 |
+
" item = prefix[f'{random.randint(0,PREFIX_NUM_VOCAB_ITEMS)}']\n",
|
| 2957 |
+
" item = item.replace('</w>', '')\n",
|
| 2958 |
+
"\n",
|
| 2959 |
+
" item2 = '#uc# '\n",
|
| 2960 |
+
" while (item2.find('#uc#')>-1 or (not item2.isalpha())) :\n",
|
| 2961 |
+
" item2 = suffix[f'{random.randint(0,SUFFIX_NUM_VOCAB_ITEMS)}']\n",
|
| 2962 |
+
" item2 = item2.replace('</w>', '')\n",
|
| 2963 |
+
"\n",
|
| 2964 |
+
" item3 = '#uc# '\n",
|
| 2965 |
+
" while (item3.find('#uc#')>-1 or (not item3.isalpha())) :\n",
|
| 2966 |
+
" item3 = suffix[f'{random.randint(0,SUFFIX_NUM_VOCAB_ITEMS)}']\n",
|
| 2967 |
+
" item3 = item3.replace('</w>', '')\n",
|
| 2968 |
+
" #------#\n",
|
| 2969 |
+
"\n",
|
| 2970 |
+
" #------#\n",
|
| 2971 |
+
" output = output + item + '-' + item2 + ' ' + item3\n",
|
| 2972 |
+
" # + ' ' + item4\n",
|
| 2973 |
+
" output = output + ' \\n'\n",
|
| 2974 |
+
" #---------#\n",
|
| 2975 |
+
" f.write(str(output))"
|
| 2976 |
+
],
|
| 2977 |
+
"metadata": {
|
| 2978 |
+
"cellView": "form",
|
| 2979 |
+
"id": "64c0zJDDChN7"
|
| 2980 |
},
|
| 2981 |
"execution_count": null,
|
| 2982 |
"outputs": []
|