Datasets:

Languages:
English
Tags:
Not-For-All-Audiences
License:
Gaeros commited on
Commit
3ffa5d4
1 Parent(s): 3b16b7a

tag normalizer notebook: add blacklist

Browse files
notebooks/Normalize tags T2I dataset.ipynb CHANGED
@@ -147,16 +147,10 @@
147
  },
148
  {
149
  "cell_type": "markdown",
150
- "id": "554e0048-761a-494b-9573-4fb60d55ff98",
151
  "metadata": {},
152
  "source": [
153
- "# Edit caption files\n",
154
- "\n",
155
- "Loads, normalize and remove implied tags from a files in a sd-script hierarchy of directories.\n",
156
- "\n",
157
- "Unknown tags are kept untouched.\n",
158
- "\n",
159
- "Specific to kade's format, captions are detected as tags ending with a period and are moved to the end of the file."
160
  ]
161
  },
162
  {
@@ -169,7 +163,7 @@
169
  "name": "stdout",
170
  "output_type": "stream",
171
  "text": [
172
- "tags=[6, 5, 17, 'unknown tag'] implied={0, 15}\n"
173
  ]
174
  },
175
  {
@@ -196,9 +190,7 @@
196
  "source": [
197
  "# We will use tagset_normalizer.encode()/decode() to normalize tags. Demo:\n",
198
  "tags, implied = tagset_normalizer.encode(['solo', 'male', 'canine', 'mammal', 'unknown tag'])\n",
199
- "print(f'{tags=} {implied=}')\n",
200
- "\n",
201
- "tagset_normalizer.decode(tags)\n",
202
  "\n",
203
  "tagset_normalizer.encode?"
204
  ]
@@ -206,6 +198,63 @@
206
  {
207
  "cell_type": "code",
208
  "execution_count": 5,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  "id": "5200e13d-983c-463c-aa8e-33429515d63e",
210
  "metadata": {},
211
  "outputs": [],
@@ -237,6 +286,8 @@
237
  " tags, captions = load_caption(file)\n",
238
  " orig_tags = tags\n",
239
  " tags, implied = tagset_normalizer.encode(tags)\n",
 
 
240
  " counter.update(tags)\n",
241
  " tags = tagset_normalizer.decode(tags)\n",
242
  " if tags == orig_tags:\n",
@@ -251,7 +302,7 @@
251
  },
252
  {
253
  "cell_type": "code",
254
- "execution_count": 6,
255
  "id": "d4741937-f1fd-4a1c-b3ed-9698e3d76a79",
256
  "metadata": {},
257
  "outputs": [
@@ -262,21 +313,19 @@
262
  "solo count=10877 (e621:general)\n",
263
  "rating_explicit count=9363 (e621:general)\n",
264
  "anthro count=7274 (e621:general)\n",
265
- "nude count=5894 (e621:general)\n",
266
  "female count=4525 (e621:general)\n",
267
- "hi res count=4378 (e621:meta)\n",
268
  "digital media \\(artwork\\) count=4245 (e621:meta)\n",
269
  "erection count=3952 (e621:general)\n",
270
  "male count=3821 (e621:general)\n",
271
  "looking at viewer count=3600 (e621:general)\n",
272
  "duo count=3555 (e621:general)\n",
273
- "balls count=3496 (e621:general)\n",
274
  "tail count=3485 (e621:general)\n",
275
  "nipples count=3474 (e621:general)\n",
276
  "open mouth count=3264 (e621:general)\n",
277
  "smile count=3089 (e621:general)\n",
278
  "blush count=2956 (e621:general)\n",
279
- "english text count=2939 (e621:meta)\n",
280
  "rating_safe count=2764 (e621:general)\n",
281
  "white fur count=2338 (e621:general)\n",
282
  "furry count=2275 (e621:invalid)\n",
@@ -284,32 +333,30 @@
284
  "navel count=2252 (e621:general)\n",
285
  "tongue out count=2160 (e621:general)\n",
286
  "outside count=2069 (e621:general)\n",
287
- "absurd res count=1986 (e621:meta)\n",
288
  "standing count=1982 (e621:general)\n",
289
  "muscular male count=1977 (e621:general)\n",
290
  "breasts count=1957 (e621:general)\n",
291
  "butt count=1947 (e621:general)\n",
292
- "pussy count=1915 (e621:general)\n",
293
  "simple background count=1910 (e621:general)\n",
294
- "penis count=1866 (e621:general)\n",
 
295
  "wolf count=1847 (e621:species)\n",
296
  "brown fur count=1799 (e621:general)\n",
297
  "claws count=1738 (e621:general)\n",
298
  "abs count=1678 (e621:general)\n",
299
  "animal ears count=1662 (e621:general)\n",
300
  "male focus count=1653 (e621:general)\n",
301
- "dialogue count=1602 (e621:general)\n",
302
  "big breasts count=1557 (e621:general)\n",
303
  "thick thighs count=1550 (e621:general)\n",
304
  "anus count=1525 (e621:general)\n",
305
- "furry male count=1511 (unknown)\n",
306
  "eyes closed count=1486 (e621:general)\n",
307
  "rating_questionable count=1480 (e621:general)\n",
308
  "sitting count=1464 (e621:general)\n",
309
  "pecs count=1452 (e621:general)\n",
310
  "watersports count=1448 (e621:general)\n",
311
  "horn count=1444 (e621:general)\n",
312
- "uncensored count=1405 (e621:meta)\n",
313
  "humanoid penis count=1392 (e621:general)\n",
314
  "spread legs count=1343 (e621:general)\n",
315
  "white background count=1335 (e621:general)\n",
@@ -318,12 +365,12 @@
318
  "fur count=1311 (e621:general)\n",
319
  "long hair count=1228 (e621:general)\n",
320
  "grey fur count=1223 (e621:general)\n",
321
- "invalid tag count=1216 (e621:invalid)\n",
322
  "detailed background count=1206 (e621:general)\n",
323
- "teeth count=1178 (e621:general)\n",
 
324
  "black fur count=1152 (e621:general)\n",
 
325
  "urine stream count=1148 (e621:general)\n",
326
- "clothed count=1137 (e621:general)\n",
327
  "fangs count=1129 (e621:general)\n",
328
  "male/female count=1101 (e621:general)\n",
329
  "black nose count=1100 (e621:general)\n",
@@ -357,8 +404,12 @@
357
  "by kenno arkkan count=868 (e621:artist)\n",
358
  "male peeing count=865 (e621:general)\n",
359
  "tongue count=852 (e621:general)\n",
360
- "bottomless count=836 (e621:general)\n",
361
- "interspecies count=833 (e621:general)\n"
 
 
 
 
362
  ]
363
  }
364
  ],
@@ -375,7 +426,7 @@
375
  },
376
  {
377
  "cell_type": "code",
378
- "execution_count": 7,
379
  "id": "2b9cf8a6-61e2-4806-99fb-f92403294f08",
380
  "metadata": {},
381
  "outputs": [
@@ -383,7 +434,7 @@
383
  "name": "stdout",
384
  "output_type": "stream",
385
  "text": [
386
- "furry male(1511), feet out of frame(306), furry sticker(306), furry with furry(290), animal focus(287), male pubic hair(251), furry with non-furry(243), wolf boy(243), gynomorph female(224), intersex intersex(140), male masturbation(125), gynomorph male(118), armpits(116), navel hair(107), by spaceengine(94), gynomorph gynomorph(91), male ambiguous(89), fox girl(87), tiger boy(87), photo \\(medium\\)(78), score explicit(63), clothed nude(60), greg rutkowski(54), five nights at freddy's security breach(53), blp(52), avery palmer(50), hamgas(48), bare pectorals(47), digimon \\(creature\\)(47), cum on boy(39), two-tone skin(39), non- breasts(35), animal hands(34), black male underwear(29), by jwst(29), leopard ears(28), non- balls(28), ground vehicle(27), cum on pectorals(25), white male underwear(25), female ambiguous(25), fox boy(24), by hubble(24), rabbit girl(22), andromorph male(22), painting \\(medium\\)(22), demon horns(19), herm male(19), webcomic character(19), lion boy(18), herm female(18), dharrel(18), fish boy(17), krystal(17), shower \\(place\\)(15), flame-tipped tail(15), tiger girl(14), genderswap \\(mtf\\)(14), sidepec(13), animal collar(13), heart-shaped chest(13), gynomorph herm(13), foot out of frame(12), animalization(12), In the picture(12), arrow \\(projectile\\)(11), naked shirt(11), colored tongue(11), herm herm(11), generation 9(11), planet pov(11), score safe(11), futa with female(10), futanari masturbation(10), ringtail(10), faux traditional media(10), ambiguous ambiguous(10), dock(9), dappled sunlight(8), scar on leg(8), fewer digits(8), webcomic(8), balls on floor(8), breasts squeezed together(7), goat girl(7), fishnets(7), pectoral cleavage(7), slingshot swimsuit(7), 6+boys(7), planted(7), white thighhighs(7), full-package futanari(7), red thighhighs(7), cowboy western(7), deviantart username(7), off on(7), regional form \\(\\)(7), score questionable(7), In a dimly lit room(7), In the background(7)\n"
387
  ]
388
  }
389
  ],
 
147
  },
148
  {
149
  "cell_type": "markdown",
150
+ "id": "d800f096-c8cc-4ae6-81f6-52b48df423b1",
151
  "metadata": {},
152
  "source": [
153
+ "# Create the blacklist"
 
 
 
 
 
 
154
  ]
155
  },
156
  {
 
163
  "name": "stdout",
164
  "output_type": "stream",
165
  "text": [
166
+ "tags=[6, 5, 17, 'unknown tag'] decoded=['solo', 'male', 'canine', 'unknown tag'] implied={0, 15}\n"
167
  ]
168
  },
169
  {
 
190
  "source": [
191
  "# We will use tagset_normalizer.encode()/decode() to normalize tags. Demo:\n",
192
  "tags, implied = tagset_normalizer.encode(['solo', 'male', 'canine', 'mammal', 'unknown tag'])\n",
193
+ "print(f'{tags=} decoded={tagset_normalizer.decode(tags)} {implied=}')\n",
 
 
194
  "\n",
195
  "tagset_normalizer.encode?"
196
  ]
 
198
  {
199
  "cell_type": "code",
200
  "execution_count": 5,
201
+ "id": "07c76e90-535c-4512-ab99-90196a1ef35f",
202
+ "metadata": {},
203
+ "outputs": [
204
+ {
205
+ "name": "stdout",
206
+ "output_type": "stream",
207
+ "text": [
208
+ "hi res, 32016, 1621, 1897, 2002, 1860, 1940, 1798, 1889, 2011, 1970, 1896, 1845, 2013, story, 3, non- breasts, text, 1936, by third-party edit, absurd res, 9:16, 135:256, 18th century, 1890, 4:7, 1991, 2008, english text, 1914, 11:8, 1857, 2024, 1963, 4:5, 2004, 2:1, 1869, non- nipples, 1983, 1780, 1992, 1862, 256:135, 1962, 8888, 5:6, 1885, translated, 72016, 1846, 2112, hard translated, 1925, story at source, 1873, 1887, 2003, 612, story in description, 1894, 1879, 1880, 1876, smaller version at source, 1974, 1:1, 7:4, 1921, 1545, 1994, 1872, 1993, 20520, 1926, 1833, 1534, 1874, 1900, ambiguous gender, 12, 100000, 1957, 1850, 2005, 10000, 1858, 1:2, 2:3, 1566, 1965, context at source, ancient art, 1945, 682, 1955, 2022, 1956, 1837, 80085, 1975, 196, 1969, 1995, 2023, non- balls, watermarked at source, 1868, 1938, 9:14, 1916, 204, unavailable at source, 1903, 1893, 2021, 20th century, 1899, 1842, 2020, better version at source, 1979, 007, 19th century, 15th century, 2009, 1913, 1768, 2012, 2019, 1600, 1920, 1911, 1906, 1982, 1998, 2018, 3:1, 1980, 1886, 5000, 1976, 1865, 1923, 1843, 1763, 16th century, 2010, 1950, 2017, 1990, 1910, 14:9, 2007, 1971, 1841, 1908, 1823, 1438, reference image at source, 0048, 5:4, 1918, 911, 1794, 2016, 7:3, 1988, 1870, 1820, 1944, 1895, 1772, 2006, translation edit, 3:5, 1799, 1924, 20000, 1875, 1931, 1985, 6:13, 1922, 1867, sketch at source, 1989, 1907, 3:4, by conditional dnp, 1978, 1928, widescreen, superabsurd res, 1864, 1973, 1829, 1814, 1968, 1942, uncensored version at source, 1959, 1882, 19, 1901, 1927, alternate version at source, 2015, 1898, 33, 16:9, feet out of frame, 1904, 1912, 4:3, poll at source, 1891, 58008, 44, 1010, 3000, 1964, 1585, 1883, 1905, 1844, invalid tag, 666, 2014, 4k, 1946, 1917, 2000, 5:8, 1997, 1861, 2001, 1863, 6:5, 5:3, 1987, 1915, 1878, 1909, 1977, 17th century, 3:2, 343, 1:3, 1877, 1996, 4, 1853, censored version at source, 1881, 1967, 1981, 1871, 1999, 1986, 16:10, uncensored, 1919, 1984, 1972, 30000, 1939, dialogue at source, 022\n"
209
+ ]
210
+ }
211
+ ],
212
+ "source": [
213
+ "# Manual blacklist: a list of e621 tags or unknown tag strings\n",
214
+ "blacklist = r\"\"\"\n",
215
+ "invalid tag, by conditional dnp, \n",
216
+ "hi res, absurd res, superabsurd res, 4k,\n",
217
+ "uncensored, ambiguous gender,\n",
218
+ "translation edit, story in description,\n",
219
+ "non- balls, non- nipples, non- breasts, feet out of frame\n",
220
+ "\"\"\"\n",
221
+ "blacklist = (t.strip() for t in blacklist.split(','))\n",
222
+ "blacklist = set(t for t in blacklist if len(t) > 0)\n",
223
+ "# multiline is ok, but don't forget the comma on line endings\n",
224
+ "assert not any('\\n' in t for t in blacklist)\n",
225
+ "\n",
226
+ "# blacklist years, digits only tags, and aspect ratios\n",
227
+ "all_tags = tagset_normalizer.tag_normalizer.idx2tag\n",
228
+ "RE_BLACKLIST = re.compile(r'(\\d+|\\d+:\\d+)')\n",
229
+ "blacklist.update(t for t in all_tags if RE_BLACKLIST.fullmatch(t))\n",
230
+ "# blacklist tags enging with ' at source'\n",
231
+ "blacklist.update(t for t in all_tags if t.endswith(' at source'))\n",
232
+ "\n",
233
+ "# Encode the blacklist to ids\n",
234
+ "blacklist, implied = tagset_normalizer.encode(blacklist)\n",
235
+ "# Also blacklist tags implied by blacklisted tags\n",
236
+ "blacklist = set(blacklist) | implied\n",
237
+ "\n",
238
+ "print(', '.join(tagset_normalizer.decode(blacklist)))"
239
+ ]
240
+ },
241
+ {
242
+ "cell_type": "markdown",
243
+ "id": "554e0048-761a-494b-9573-4fb60d55ff98",
244
+ "metadata": {},
245
+ "source": [
246
+ "# Edit caption files\n",
247
+ "\n",
248
+ "Loads, normalize and remove implied tags from a files in a sd-script hierarchy of directories.\n",
249
+ "\n",
250
+ "Unknown tags are kept untouched.\n",
251
+ "\n",
252
+ "Specific to kade's format, captions are detected as tags ending with a period and are moved to the end of the file."
253
+ ]
254
+ },
255
+ {
256
+ "cell_type": "code",
257
+ "execution_count": 6,
258
  "id": "5200e13d-983c-463c-aa8e-33429515d63e",
259
  "metadata": {},
260
  "outputs": [],
 
286
  " tags, captions = load_caption(file)\n",
287
  " orig_tags = tags\n",
288
  " tags, implied = tagset_normalizer.encode(tags)\n",
289
+ " tags = [t for t in tags if t not in blacklist]\n",
290
+ " \n",
291
  " counter.update(tags)\n",
292
  " tags = tagset_normalizer.decode(tags)\n",
293
  " if tags == orig_tags:\n",
 
302
  },
303
  {
304
  "cell_type": "code",
305
+ "execution_count": 7,
306
  "id": "d4741937-f1fd-4a1c-b3ed-9698e3d76a79",
307
  "metadata": {},
308
  "outputs": [
 
313
  "solo count=10877 (e621:general)\n",
314
  "rating_explicit count=9363 (e621:general)\n",
315
  "anthro count=7274 (e621:general)\n",
316
+ "nude count=5906 (e621:general)\n",
317
  "female count=4525 (e621:general)\n",
 
318
  "digital media \\(artwork\\) count=4245 (e621:meta)\n",
319
  "erection count=3952 (e621:general)\n",
320
  "male count=3821 (e621:general)\n",
321
  "looking at viewer count=3600 (e621:general)\n",
322
  "duo count=3555 (e621:general)\n",
323
+ "balls count=3492 (e621:general)\n",
324
  "tail count=3485 (e621:general)\n",
325
  "nipples count=3474 (e621:general)\n",
326
  "open mouth count=3264 (e621:general)\n",
327
  "smile count=3089 (e621:general)\n",
328
  "blush count=2956 (e621:general)\n",
 
329
  "rating_safe count=2764 (e621:general)\n",
330
  "white fur count=2338 (e621:general)\n",
331
  "furry count=2275 (e621:invalid)\n",
 
333
  "navel count=2252 (e621:general)\n",
334
  "tongue out count=2160 (e621:general)\n",
335
  "outside count=2069 (e621:general)\n",
 
336
  "standing count=1982 (e621:general)\n",
337
  "muscular male count=1977 (e621:general)\n",
338
  "breasts count=1957 (e621:general)\n",
339
  "butt count=1947 (e621:general)\n",
 
340
  "simple background count=1910 (e621:general)\n",
341
+ "pussy count=1904 (e621:general)\n",
342
+ "penis count=1864 (e621:general)\n",
343
  "wolf count=1847 (e621:species)\n",
344
  "brown fur count=1799 (e621:general)\n",
345
  "claws count=1738 (e621:general)\n",
346
  "abs count=1678 (e621:general)\n",
347
  "animal ears count=1662 (e621:general)\n",
348
  "male focus count=1653 (e621:general)\n",
349
+ "dialogue count=1595 (e621:general)\n",
350
  "big breasts count=1557 (e621:general)\n",
351
  "thick thighs count=1550 (e621:general)\n",
352
  "anus count=1525 (e621:general)\n",
353
+ "furry male count=1511 (e621:general)\n",
354
  "eyes closed count=1486 (e621:general)\n",
355
  "rating_questionable count=1480 (e621:general)\n",
356
  "sitting count=1464 (e621:general)\n",
357
  "pecs count=1452 (e621:general)\n",
358
  "watersports count=1448 (e621:general)\n",
359
  "horn count=1444 (e621:general)\n",
 
360
  "humanoid penis count=1392 (e621:general)\n",
361
  "spread legs count=1343 (e621:general)\n",
362
  "white background count=1335 (e621:general)\n",
 
365
  "fur count=1311 (e621:general)\n",
366
  "long hair count=1228 (e621:general)\n",
367
  "grey fur count=1223 (e621:general)\n",
 
368
  "detailed background count=1206 (e621:general)\n",
369
+ "teeth count=1177 (e621:general)\n",
370
+ "clothed count=1175 (e621:general)\n",
371
  "black fur count=1152 (e621:general)\n",
372
+ "canine count=1151 (e621:species)\n",
373
  "urine stream count=1148 (e621:general)\n",
 
374
  "fangs count=1129 (e621:general)\n",
375
  "male/female count=1101 (e621:general)\n",
376
  "black nose count=1100 (e621:general)\n",
 
404
  "by kenno arkkan count=868 (e621:artist)\n",
405
  "male peeing count=865 (e621:general)\n",
406
  "tongue count=852 (e621:general)\n",
407
+ "bottomless count=834 (e621:general)\n",
408
+ "interspecies count=833 (e621:general)\n",
409
+ "short hair count=828 (e621:general)\n",
410
+ "sweat count=825 (e621:general)\n",
411
+ "pawpads count=819 (e621:general)\n",
412
+ "by zaush count=819 (e621:artist)\n"
413
  ]
414
  }
415
  ],
 
426
  },
427
  {
428
  "cell_type": "code",
429
+ "execution_count": 8,
430
  "id": "2b9cf8a6-61e2-4806-99fb-f92403294f08",
431
  "metadata": {},
432
  "outputs": [
 
434
  "name": "stdout",
435
  "output_type": "stream",
436
  "text": [
437
+ "furry sticker(306), furry with furry(290), animal focus(287), male pubic hair(251), furry with non-furry(243), gynomorph female(224), intersex intersex(140), male masturbation(125), gynomorph male(118), navel hair(107), by spaceengine(94), gynomorph gynomorph(91), male ambiguous(89), tiger boy(87), photo \\(medium\\)(78), score explicit(63), clothed nude(60), greg rutkowski(54), five nights at freddy's security breach(53), blp(52), avery palmer(50), hamgas(48), bare pectorals(47), digimon \\(creature\\)(47), cum on boy(39), two-tone skin(39), animal hands(34), black male underwear(29), by jwst(29), leopard ears(28), ground vehicle(27), legendary(27), cum on pectorals(25), white male underwear(25), female ambiguous(25), by hubble(24), andromorph male(22), painting \\(medium\\)(22), demon horns(19), herm male(19), lion boy(18), herm female(18), dharrel(18), colored nipples(17), krystal(17), shower \\(place\\)(15), flame-tipped tail(15), genderswap \\(mtf\\)(14), sidepec(13), animal collar(13), heart-shaped chest(13), gynomorph herm(13), foot out of frame(12), animalization(12), In the picture(12), arrow \\(projectile\\)(11), naked shirt(11), colored tongue(11), herm herm(11), generation 9(11), planet pov(11), score safe(11), futa with female(10), futanari masturbation(10), whistle(10), ringtail(10), faux traditional media(10), ambiguous ambiguous(10), dappled sunlight(8), scar on leg(8), fewer digits(8), balls on floor(8), breasts squeezed together(7), pectoral cleavage(7), slingshot swimsuit(7), 6+boys(7), planted(7), white thighhighs(7), full-package futanari(7), red thighhighs(7), cowboy western(7), deviantart username(7), off on(7), regional form \\(\\)(7), score questionable(7), In a dimly lit room(7), In the background(7), with a long(7), jaguar ears(6), bar \\(place\\)(6), scar on chest(6), poke ball \\(basic\\)(6), digital media \\\\(artwork\\\\)(6), traialas(6), (toes)(6), slushie \\(character\\)(6), In the bedroom(6), naked cloak(5), jack-o' challenge(5), elbow rest(5)\n"
438
  ]
439
  }
440
  ],