ComfyUI Node

Tag Generator

Let Danbooru's real co-occurrence statistics finish your prompt

By alchemine·Created about a year ago·Updated a day ago· 2
Tag Generator
    • processed_text
    • generated_tags
    text
    n10
    ratingexplicit
    temperature1.00
    top_k50
    top_p0.95
    min_p0.00
    seed0
    min_count100
    categories
    blacklist

    You prompt in Danbooru tags - 1girl, night, city, rain - because that's the language Illustrious, NoobAI and Pony actually speak. TagGenerator extends a prompt like night, city, rain with the tags that show up alongside those tags across 9.23 million Danbooru posts: cityscape, building, night sky, scenery, road. It's prompt autocomplete built from the board's own statistics, running fully offline and reproducible from a seed.

    How it works

    It's an LM-style sampler, one tag per step. Each step's distribution is a naive Bayes over Danbooru solo-post co-occurrence: log P(tag) plus the sum of log lift against every tag already in the context. Each pick joins the context and re-conditions the next step. Tags whose co-occurrence lift sits far below 1 - the pair avoids each other on the board - get vetoed, so the output can't contradict itself. temperature 0.0 is a deterministic argmax; above that you get the usual top_k / top_p / min_p filters applied in that order, and seed makes the whole draw reproducible.

    The statistics come from a co-occurrence table the author rebuilt from a 2026 snapshot: 20,811 tags over 9.23M posts. It ships as a 72MB numpy file (suggest_v1.0.npz) that downloads from the pack's GitHub release on first use and is verified by sha256. If it can't download, the node logs suggest artifact not found and passes your text through unchanged - nothing breaks, you just get nothing extra.

    The inputs that matter

    • rating - check this first. The default is explicit, and the node is honest about what that means: the co-occurrence tables are built per cumulative rating tier (general < sensitive < questionable < explicit), and any tag whose own rating exceeds your request is masked. Want mild content? Set general or sensitive - this isn't a filter bolted on after the fact, it changes which statistics the sampler is even allowed to see. random rolls one of the four from the seed.
    • categories - restrict which axes can contribute, optionally with counts: "pose:2, clothes:3" admits only pose and clothes tags and caps each. With n at 0, those caps become the target length - the way to get a balanced prompt instead of whatever the stats happen to favour.
    • n - how many tags. 0 means auto length, drawn from the corpus length distribution, and generation stops early when no candidate is at least twice as likely as chance given the context. The data has nothing left to say.
    • blacklist - a regex matched against each candidate tag ("hair|eyes" drops every hair and eye tag). It filters candidates rather than results, so you still get n tags back. An unparseable pattern is logged and ignored.
    • text, seed, temperature, top_k, top_p, min_p, min_count - min_count drops rare tags; at its default of 100 it's effectively no filtering, because rare tags are already held back three other ways. Raise it if a prompt keeps surfacing tags too obscure for your model to have learned.

    Outputs and where it sits

    processed_text is your prompt with the generated tags appended - wire it into a CLIP Text Encode. generated_tags is just the new tags, handy for inspecting what the sampler added. It's the offline, seedable sibling of the pack's Danbooru Related Tags Retriever, which queries the live API for the same job. Good uses: bulking out a sparse prompt, or discovering the actual board vocabulary for a scene instead of guessing what people tag a beach with. If you're on a natural-language model (Flux, Z-Image), skip it - tag autocomplete only helps models trained on tags.

    Install

    ComfyUI Manager: search for ComfyUI-Alchemine-Pack, install, restart. Or manually:

    cd ComfyUI/custom_nodes
    git clone https://github.com/alchemine/comfyui-alchemine-pack
    pip install -r requirements.txt
    

    then restart. The pack's only Python dependency is python-dotenv; no model, no API key. Budget for the first-run 72MB download.

    Troubleshooting

    Empty generated_tags with processed_text equal to your input on the first run almost always means the 72MB artifact is still downloading or failed - watch the console for the [TagSuggest] downloading ... line and let it finish once. Beyond that there's little to break; the node needs no model and nothing at load time.

    CategoryAlcheminePack/Prompt

    Inputs (11)

    NameTypeDefaultDescription
    textSTRING
    nINT100–100
    ratingCOMBOexplicit5 options: general, sensitive, questionable, explicit, random
    temperatureFLOAT1.000–5
    top_kINT500–500
    top_pFLOAT0.950–1
    min_pFLOAT0.000–1
    seedINT00–18446744073709550000
    min_countINT100100–1000000
    categoriesoptSTRING
    blacklistoptSTRING

    Outputs (2)

    NameTypeDescription
    processed_textSTRING
    generated_tagsSTRING