Nodes/ComfyUI-Transformers/Text Classification
ComfyUI Node

Text Classification

Give your graph a sentiment check before it spends a generation

By kadirnar·Created 3 years ago·Updated 7 months ago· 25
Text Classification
    • label
    • score
    text
    model_namedistilbert-base-uncased-finetuned-sst-2-english

    You've got a string, you want a verdict. That's the entire pitch for TextClassificationPipeline: paste or feed in some text, and it returns a label (like "POSITIVE" or "NEGATIVE") plus a confidence score. Out of the box it's a sentiment analyzer, but the model is a free-text field, so the same node becomes a toxicity filter, a topic router, or whatever classifier you can find on the Hub. In ComfyUI terms, this is a decision node - its output can gate what happens next in the graph.

    It comes from kadirnar/ComfyUI-Transformers, the pack that wraps Hugging Face's transformers.pipeline() as one node per task. The default model is distilbert-base-uncased-finetuned-sst-2-english - a distilled (read: half-size) BERT fine-tuned on the Stanford Sentiment Treebank. At ~260 MB it's small enough to run comfortably on CPU, which matters because most people running this pack are running it in a text branch of an image workflow, not on the GPU doing the sampling.

    How it works

    Under the hood it's a one-liner: pipeline("text-classification", model=model_name), then the node plucks the top result and returns label and score as separate outputs. That's the whole mechanism - Hugging Face's pipeline handles tokenization, inference, and softmax normalization, and this node just formats the winner. Because it takes the top-1 only, you always get one label with its score; if you want the full ranked list, the zero-shot nodes in this same pack give you a JSON dump instead.

    The useful trick is that model_name is a plain string, so you can swap the sentiment model for any text classifier on the Hub. Community favorites for gating workflows include the unitary/toxic-bert family (toxicity scoring) and various zero-label classifiers. Just know that which labels come back depends entirely on the model you pick - the node doesn't tell you what its labels mean.

    Inputs and outputs

    • text - multiline STRING, the thing you're judging.
    • model_name - default distilbert-base-uncased-finetuned-sst-2-english; free text, any HF text-classification model.
    • Outputs: label (STRING) and score (FLOAT, 0–1 confidence of the top label).

    The score float is the value worth wiring somewhere: feed it to a threshold node and you can route a branch - e.g., "if confidence in POSITIVE > 0.8, upscale, else re-roll." That's the loop this node enables that a plain text viewer can't.

    Installing it

    Same story as every node in this pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/kadirnar/ComfyUI-Transformers
    cd ComfyUI-Transformers
    pip install -r requirements.txt
    

    or search "ComfyUI-Transformers" in ComfyUI Manager. Restart to pick it up. The README's cd custom/nodes is a typo; the requirements pull in transformers>=4.42 and friends, and transformers is a notorious source of dependency conflicts in ComfyUI's shared Python environment - if another node breaks after installing this pack, that's the usual suspect.

    Common issues

    • First run hangs. It's downloading DistilBERT from the Hub to ~/.cache/huggingface. Give it a minute, watch the console.
    • Labels are uppercase and model-specific. "POSITIVE"/"NEGATIVE" comes from the SST-2 model; a different model returns different strings. Don't hardcode expectations.
    • Repeated runs re-load the model. The pack has a cached pipeline loader that the nodes never actually call, so every execution pays a load cost. Fine for occasional checks, wasteful for a hot loop.

    Honest take: for a one-off "is this text positive?" it's hard to beat - install, run, done. If you're building a serious content-moderation or prompt-routing system, a purpose-built LLM node will serve you better. This one is for lightweight decisions inside the graph, and at that job it's quietly excellent.

    CategoryTransformers/NLP/TextClassification

    Inputs (2)

    NameTypeDefaultDescription
    textSTRING
    model_nameSTRINGdistilbert-base-uncased-finetuned-sst-2-english

    Outputs (2)

    NameTypeDescription
    labelSTRING
    scoreFLOAT