ComfyUI Node

Split Sentences

Chop prose captions in two at a sentence boundary

By NMWave·Created 2 years ago·Updated 6 months ago· 6
Split Sentences
    • STRING
    • STRING
    sentence
    length1

    Split Tags is built for comma-separated Danbooru tags, but a lot of modern captioning flows speak prose. JoyCaption and other natural-language taggers dump out full sentences, and natural-language models like Flux or Qwen-Image want to be prompted in sentences too. Split Sentences is the prose version of Split Tags: it takes a block of text and cuts it into two pieces at a sentence boundary - the first length sentences in one output, everything after in the other.

    That's handy when you're captioning a training set, or when you want to split a caption into a "subject setup" part and a "detail" part to feed different conditioning. It's the same "carve, don't lose anything" idea as its sibling node, just boundary-aware about where it cuts.

    How it works

    Under the hood it uses a regex split: re.split(r'(?<=[.!?])\s+', sentence), which breaks the text after every period, exclamation mark, or question mark that's followed by whitespace. Then it joins the first length sentences into output one and the rest into output two.

    Two inputs:

    • sentence - the prose caption (wired in from a tagger or text node).
    • length - how many sentences land in the first output. Default 1, min 1.

    Two STRING outputs. If the text has fewer sentences than length, you get the first sentence alone in output one and the remainder in output two; if there's only one sentence total, output two comes back empty. Silent and forgiving, but check your wiring if a split "isn't happening."

    Install

    Part of the "Nader Tagging" pack. ComfyUI Manager → search "Nader Tagging" → install → restart. Manual:

    cd ComfyUI/custom_nodes
    git clone https://github.com/NMWave/ComfyUI-Nader-Tagging
    

    No dependencies, no models to fetch.

    Where people get burned

    The sentence-boundary regex is the weak spot, and it's worth knowing exactly how naive it is. It splits after any . ! or ? followed by whitespace - it doesn't understand abbreviations. "Dr. Smith walks in. The cat watches." will split after "Dr." and give you "Dr." as a standalone sentence in output one. Same for "e.g.", "vs.", and decimals. For short caption prose that's usually fine; for dense technical text you'll want to check the first output.

    There's also a subtlety with spacing: the split only fires when the punctuation is followed by whitespace, so "Hello!World" (no space) won't split. That's a feature for minified text and a trap if your captions came from somewhere that strips spaces after punctuation.

    Keep it for sentence-shaped input and it does exactly what it says on the tin. Run it before your CLIP encode or as a caption-prep step in training, and you get clean, boundary-safe chunks instead of arbitrary mid-word cuts.

    CategoryNMWave/text

    Inputs (2)

    NameTypeDefaultDescription
    sentenceSTRING
    lengthINT1

    Outputs (2)

    NameTypeDescription
    STRINGSTRING
    STRINGSTRING