ComfyUI-BooruGacha

ComfyUI custom nodes for generating and normalizing booru-style tags for image generation. Ships with curated datasets covering ~54k categorized Danbooru tags across 45+ categories.

Latest version: 2026-04-06 always on this rentry if I ever update it.

Nodes

  • Booru Gacha Search

Normalizes comma-separated user input to matching Danbooru tags. Handles typos, spacing differences, and natural-language variations via string matching with semantic search fallback. Weight syntax (tag:1.2) is preserved through normalization.

  • Booru Gacha Roll

Randomly generates Danbooru tags from selected categories with a dynamic UI. Add categories (hair color, location, pose, artist, etc.) via a hierarchical menu, configure count and weight per category, and control how much tag popularity influences selection. Seed-controlled for reproducible results.

  • Booru Gacha Ban List

Builds a ban list from user-specified concepts by expanding them via token overlap and co-occurrence statistics. For example, banning cum automatically catches cum_in_pussy, cum_on_body, etc. The expansion slider controls how aggressively related tags are included. The same_category toggle (on by default) prevents cross-category leaks, banning 3d (art style) won't accidentally ban super_mario_3d_world (copyright). Connect the output to the ban_list input on Search, Roll, or Combine nodes.

  • Booru Gacha Tag Expand

Expands input tags into related tags to reinforce a concept. For example, catgirl expands into cat_ears, cat_tail, animal_ear_fluff, etc. Uses a hybrid approach: token overlap provides the conceptual link, while co-occurrence statistics rank and supplement with contextually relevant tags (e.g. beach becomes ocean, sand, bikini). Three scoring modes control ranking: Similarity (Jaccard), Association (PMI), and Weighted (LMI). A scope dropdown restricts expansions to the same group, subgroup, or category. Weight decays by rank so the most related expansions carry the most influence. Accepts an optional BANLIST to exclude unwanted expansions.

  • Booru Gacha Combine

Merges multiple tag string inputs into a single deduplicated list. Dynamic "Add Input"/"Remove Last" buttons let you wire as many sources as needed. Earlier inputs take priority when duplicates are found (preserving weight). Accepts an optional BANLIST connection for final-stage hard filtering.

  • Booru Gacha Combine Bans

Merges multiple BANLIST inputs into one unified ban set. Dynamic inputs like the Combine node. Useful when you have several Ban List nodes targeting different concepts and want to feed a single combined ban into your workflow.

Install

1
2
3
cd ComfyUI/custom_nodes
Extract ComfyUI-BooruGacha.zip into here
pip install -r ComfyUI-BooruGacha/requirements.txt

Restart ComfyUI. The sentence-transformer model (all-MiniLM-L6-v2) used for semantic search (as in you type in a thing that isnt a real tag so it tries to find the closest thing that makes at least some amount of sense) is downloaded automatically on first use from HF and embeddings are cached locally once they are generated. Takes like a few seconds on the very first run. Everything else after that is super fast and barely uses any ram and no gpu at all.

Technical info

This was made over the weekend and I haven't tested it on a fresh install of ComfyUI but the requirements are very simple as i'm shipping the dataset inside the data folder and it should work tm. The original data is the danbooru2024 raw dataset and rule34.xxx full datasets.

I have a bunch of scripts that take in these raw datasets and normalize them to account for tags that have little differences between the sites and such, rule34.xxx has 19M posts while danbooru only has 8M so rule34 gives alot of good correlation data. The outputs are always danbooru-only names since all models are trained on danbooru-only inputs.

My data generation workflow looks kinda like this

normalize_tags.py > categorize_tags.py > curate_tags.py (optional) > build_cooccurrence.py
                              (rerun to apply curations)

The categorize tags step is the main source of the juice, its a six-layer classification pipeline assigning each tag a (group, subgroup, category) - the first layers are more authoritative and catch most things with high confidence, the lower a tag falls over the lower the confidence.

Layer Confidence Method Description
L1 63.0 Source metadata Danbooru category codes (artist=1, copyright=3, character=4, meta=5)
L2 31.0 Hand curation Loaded from hand_curation.parquet; runs before wiki to win on fine splits (colors, counts)
L3 15.0 Wiki parsing Extracts [[tag]] links from danbooru tag_group:* wiki pages (~60 groups)
L4 7.0 Regex heuristics ~120+ suffix/prefix patterns (*_hair, holding_*, *_(cosplay), etc.)
L5 1.0–3.0 LLM ensemble 3 models x 3 passes; confidence = 1.0 + 2.0 * vote_fraction
L6 1.0 Fallback Uncategorized: group=general, subgroup=NULL, category=NULL

For anything that isn't a hard match I categorized via LLM calls, 3 different models, 3 votes each, totalling 9 votes for every single tag. Only the highest votes/cross llm agreements won. Was quite expensive not gonna lie but totally worth it. It also runs a separate classification at the end for the filtering column (age rating) that gives us sfw, nudity, sexual, gore for every single tag with some hard-coded in.

6 top-level groups: artist, character, copyright, meta, character_count, general

Within general, 11 subgroups with ~45 fine-grained categories:

  • identity: gender, species_type, body_type, age_presentation, camera_framing, shot_focus
  • hair: hair_color, hair_length, hair_style, hair_ornament
  • face: eye_color, eye_feature, gaze, facial_expression, facial_hair, facial_mark
  • body: skin_color, body_part, body_feature, animal_feature
  • clothing: headwear, eyewear, neckwear, topwear, bottomwear, outfit, legwear, footwear, underwear, handwear, sleeves, accessory, clothing_state
  • action: pose, gesture, action, interaction
  • sexual: sexual_act, sexual_position, sexual_object
  • scene: background, location, lighting, weather_time
  • entity: object, weapon, food_drink, vehicle, creature, plant
  • effects: visual_effect, body_fluid, censoring
  • style: art_style, art_medium

Tag Co-occurrence Dataset

This is the big annoying one, it computes how often tag pairs appear together across all 19M posts from both sites, scored by three metrics. LMI (Local Mutual Information) is the primary ranking metric - it naturally surfaces specific associations over generic ones.

The result is the following set of scores available for every single tag:

  • PMI = log2(cooccur * total_posts / (freq_a * freq_b)) how surprising the co-occurrence is
  • LMI = cooccur * PMI PMI weighted by frequency (balances specificity and volume)
  • Jaccard = cooccur / (freq_a + freq_b - cooccur) bounded similarity [0, 1]

It also expands to both directions (a/b and b/a) and keeps top-K (100) neighbors per anchor tag by LMI which ensures tags that co-occur on one side also show up on the other side.

This shit took almost a terabyte of ram to run in a reasonable amount of time due to n*n over so many posts but hey its done now and only took like 30 minutes.

Edit

Pub: 06 Apr 2026 07:19 UTC

Views: 104