Token Classification (NER)
Pull the people, places, and organizations out of any text
- entities_json
Named-entity recognition (NER) is one of those NLP tasks that sounds academic until you have a wall of text and need to find the names in it. TokenClassificationPipeline is the pack's NER node: give it a sentence, and it returns a JSON list of the entities it found - people, organizations, locations - each with a label and a confidence score. In a ComfyUI context that means you can extract structured facts from a caption, a log, or a scraped block of text and feed those facts into other parts of the graph. It's niche, but it's the kind of niche that saves you from writing a regex from hell.
It's from kadirnar/ComfyUI-Transformers, the HF-pipeline wrapper pack. The default model is dslim/bert-base-NER (~420 MB), a BERT fine-tuned for NER with the standard PER/ORG/LOC/MISC tag set.
How it works
The mechanism is pipeline("token-classification", model=model_name, aggregation_strategy=...). Here's the subtlety that makes or breaks this node: a token classifier labels tokens (sub-word pieces), and the aggregation_strategy dropdown decides how those token labels get glued back into entities.
simple(default) - merges adjacent tokens into words, then merges across word boundaries. This is the "give me entities" mode and what you want 95% of the time.first/average/max- merge strategies that differ in how the entity's confidence score is computed (first token's score, average, or max). Fine-tune if you care about score semantics.none- returns raw per-token labels. Great for debugging, useless for most real use.
The output is entities_json, a formatted JSON array, e.g. [{"entity": "B-PER", "word": "Alice", "score": 0.99}, ...]. It's a string, so it needs a Show Text node to read, and if you want to act on the entities you'll be parsing that JSON.
Inputs and outputs
text- multiline STRING, the source text.model_name- defaultdslim/bert-base-NER; free text, so you can drop in any token-classification model (there are strong RoBERTa NER models on the Hub).aggregation_strategy- the enum dropdown above. The only input beginners actually touch.- Output:
entities_json- STRING.
One honest caveat about the default model: dslim/bert-base-NER is trained on CoNLL-2003, an old news-wire dataset. It's good at "Apple CEO Tim Cook" style text and mediocre at slang, web copy, or non-English. If your text isn't formal prose, expect misses.
Installing it
Standard pack install - ComfyUI Manager (search "ComfyUI-Transformers") or:
cd ComfyUI/custom_nodes
git clone https://github.com/kadirnar/ComfyUI-Transformers
cd ComfyUI-Transformers
pip install -r requirements.txt
then restart. README's cd custom/nodes is a typo; the requirements drag in transformers>=4.42 plus the usual heavy stack. First run downloads BERT from the Hub to ~/.cache/huggingface.
Common issues
- Entities missing or merged weirdly. Usually the aggregation strategy - try
simplefirst, and if the model is splitting things oddly, look atnoneto see the raw tokens and diagnose. - Only gets uppercase-ish proper nouns. That's CoNLL-2003's bias, not your fault. Swap the model for a more modern NER checkpoint if you process casual text.
- Model reload on every run. The pack ships a pipeline cache but never uses it in these nodes, so each execution pays a load cost.
Realistic verdict: this is a "you know who you are" node. Most image workflows will never touch it. But if you're building an automation graph that ingests text - batch captions, log analysis, prompt pipelines with structured inputs - having proper NER as a drop-in block beats hand-rolling token logic every time.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| text | STRING | — | |
| model_name | STRING | dslim/bert-base-NER | — |
| aggregation_strategy | COMBO | simple | 5 options: simple, first, average, max, none |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| entities_json | STRING | — |