ComfyUI Node

TagReplace

Same-category tag swap, with the author's own 'might not work' warning

By sugarkwork·Created 2 years ago·Updated 6 months ago· 87
TagReplace
    • result
    tags
    replace_tags
    match0.30

    TagReplace swaps tags for other tags of the same kind. Give it a prompt that says long hair and tell it you want twintails, and because both belong to the hair-styling category, the swap happens - long hair becomes twintails and the rest of the prompt survives. That's the pitch. And the author's own README hedges it in a way you should read before trusting it: this node is explicitly marked "under testing, might not work properly." So treat it as a useful experiment, not a guaranteed tool.

    What it actually does

    This is the cleverest node in the pack, and it works off the same category dictionary as the others. Every tag in the input and every candidate in replace_tags gets looked up in the category map - long_hair comes back with something like hair, hair_style, and twintails comes back with the same pair. The node then measures how much two tags' category sets overlap using a Jaccard-style score: shared categories divided by total categories. If the best match clears your threshold, the tag is replaced; otherwise it's left alone.

    That's where match comes in. It's a float from 0.0 to 1.0, defaulting to 0.3. The author's guidance: 1.0 means only tags with identical category sets get replaced, and around 0.3 is the sweet spot. If nothing is swapping, lower the value; if everything is swapping, raise it. "long hair → twintails" works because both tags share hair_style - the intersection is a large fraction of the union.

    The inputs that matter

    • tags - your prompt.
    • replace_tags - the tags you want substituted in.
    • match - the similarity threshold, default 0.3.

    Output is result, a STRING. Note the output is joined with ", " (comma-space), which is fine for ComfyUI text nodes but differs from the pack's other nodes if you're diffing outputs.

    Where people get burned

    Two traps, and the second one is the one that'll bite.

    First, category overlap is fuzzy in a way that produces surprises. smile and grin share the expression category, so at a low threshold one happily replaces the other - which may or may not be what you wanted. The lower you go, the more "close enough" replacements happen, and "close enough" is doing a lot of work here.

    Second, and this is the gotcha: any replacement tag that never matched anything gets appended to the end of the output. Give it twintails, blue_eyes and if nothing in your prompt looks like eye-color, you get your original prompt plus a stray blue_eyes tacked on. The prompt silently grows. The author flagged this node as under testing for a reason - check your output before you wire it into a batch.

    Install

    Same pack as everything else. ComfyUI Manager, search "comfyui_tag_filter":

    cd ComfyUI/custom_nodes
    git clone https://github.com/sugarkwork/comfyui_tag_fillter
    

    Restart after. No dependencies, no model downloads - the whole engine is the bundled category JSON plus a couple hundred lines of Python.

    Categorytext

    Inputs (3)

    NameTypeDefaultDescription
    tagsSTRING
    replace_tagsSTRING
    matchFLOAT0.30

    Outputs (1)

    NameTypeDescription
    resultSTRING