ComfyUI Node

TagDetector

Rescue tags from messy strings that aren't comma-separated

By sugarkwork·Created 2 years ago·Updated 6 months ago· 89
TagDetector
    • tags
    tags
    max_join4

    TagDetector is the pack's salvage operation. Every other node in this family assumes you're feeding it clean, comma-separated tags - which is true if your tagger output went through ComfyUI as a proper string. But tags have a way of arriving as garbage: pasted from an EXIF comment, scraped from a filename, joined with spaces instead of commas, or wrapped in (tag:1.2) emphasis you didn't ask for. TagDetector looks at arbitrary text and tries to pull out the tags hiding in it.

    The mechanism is a two-pass lookup against the same bundled category file every node here uses. First pass: the text gets split on spaces and every punctuation delimiter you can think of - commas, underscores, semicolons, pipes, brackets, slashes, the lot - producing candidate words. Second pass: it rebuilds multi-word tags by joining up to max_join words with underscores (long + hairlong_hair) and keeps any candidate that actually exists in the category file. Default max_join is 4, so it'll consider up to four-word compounds.

    Everything that comes out is a real, known tag. That's the elegant part - instead of trusting the delimiters, it trusts the vocabulary. If a word sequence isn't in the 67k-entry file, it's dropped.

    The honest caveat

    The README says it plainly: "detection can fail." The author's own description, not mine. Failure modes are what you'd expect from a dictionary-based approach. A tag that isn't in the category file can't be detected, no matter how clearly it's in your text. And multi-word tags with unusual word orders - or tags where the middle words are stopword-ish - can get under-merged or over-merged. The max_join knob exists to tune the tradeoff: higher catches longer compounds but risks gluing unrelated words together into nonsense that (luckily) gets filtered out by the vocabulary check anyway.

    Practical notes

    • tags input: the messy string. Default empty.
    • max_join input: max words per candidate tag, default 4.
    • tags output: the detected, comma-joined, known tags.
    • Emphasis from the input isn't preserved - you get bare tags back, clean for re-weighting.

    This pairs naturally with TagEmpty: detect first, and if nothing survives the vocabulary check, let TagEmpty swap in a fallback prompt. It also shines as a one-time cleanup when you paste a character's tag list from a wiki page that used spaces and hyphens instead of commas. Don't put it in the hot path of a fast workflow - the multi-word merging is a bit of brute force - but for batch cleanup it's a genuinely useful little tool.

    Install

    Same pack, same story: ComfyUI Manager search "comfyui_tag_filter", or

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

    Restart. No dependencies, no model downloads. The only moving part is the category JSON that ships with the repo - and since this node's whole accuracy depends on that file's coverage, an unknown tag is not a bug in TagDetector, it's a gap in the vocabulary.

    Categorytext

    Inputs (2)

    NameTypeDefaultDescription
    tagsSTRING
    max_joinINT4

    Outputs (1)

    NameTypeDescription
    tagsSTRING