Nodes/ComfyUI-Pt-Wrapper/Ptn Embedding RNN Linear
ComfyUI Node

Ptn Embedding RNN Linear

A text classifier in one node

By HowToSD·Created about a year ago·Updated about a year ago· 7
Ptn Embedding RNN Linear
    • PTMODEL
    vocabulary_size10000
    input_size1
    hidden_size1
    num_layers1
    nonlinearity
    biastrue
    batch_firsttrue
    dropout0.00
    bidirectionalfalse
    linear_output_size1
    linear_biastrue

    Ptn Embedding RNN Linear is a complete text-classification model in a single node from the HowToSD/ComfyUI-Pt-Wrapper pack: embedding lookup, a recurrent layer, and a linear classification head, all wired together. Feed it token IDs and it outputs a score per class. It's the "I want to classify text with a classic sequence model and not assemble three nodes" option, and it's the architecture behind the pack's RNN text-classification training workflow.

    Why you'd reach for it

    Recurrent networks process sequences one step at a time, carrying a hidden state that acts as memory - old-school, but still a great way to learn what sequence modeling feels like before you get to Transformers. This node packages the whole thing: an embedding layer turns token IDs into vectors, an RNN reads them in order and accumulates a representation, and a linear layer maps that representation to class scores. If you're following the pack's "training an RNN for classification" guide, this is the model node it uses. And because every piece is configurable, it doubles as a learning tool for what each knob does.

    How it works

    It's an nn.Embedding feeding an nn.RNN, then a mean-pooling step over the valid (non-padded) tokens, then an nn.Linear classifier. The RNN's nonlinearity is either tanh (classic) or relu; weights get sensible initialization (kaiming for relu, xavier for tanh). batch_first matters: this pack defaults it to True, so your input should be (batch, seq, token) rather than PyTorch's own (seq, batch, token) default - a real footgun if you're coming from raw PyTorch. bidirectional doubles the hidden state by also reading the sequence backward, which usually helps classification. linear_output_size is your class count. Output is a PTMODEL ready for a training node.

    The inputs

    • vocabulary_size / input_size - vocab size, and the embedding vector size (which is also the RNN's input size).
    • hidden_size / num_layers - RNN hidden state width and how many stacked RNN layers.
    • nonlinearity - tanh or relu.
    • bias, batch_first, dropout, bidirectional - RNN settings; dropout only applies between stacked layers.
    • linear_output_size / linear_bias - classifier head size (number of classes) and bias.

    Output: PTMODEL.

    Installing the pack

    In the "Training" category. Install via ComfyUI Manager (search "ComfyUI-Pt-Wrapper") or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
    

    Restart ComfyUI. The pack installs transformers, datasets, peft, scikit-learn, gensim and more; example datasets download on demand.

    Common issues

    • batch_first - this pack's default (True) is the opposite of PyTorch's RNN default. If you feed (seq, batch, token)-shaped data because you're used to torch, flip the flag or transpose.
    • Embedding vs tokenizer mismatch - vocabulary_size must cover your tokenizer's vocab, and token IDs must be ints in range.
    • Dropout doing nothing - dropout only affects intermediate layers; with num_layers = 1 it's silently a no-op. That's expected, not a bug.
    • Thin support - single-author educational pack, essentially absent from r/comfyui. The repo's training_rnn_for_classification doc is the authoritative walkthrough.
    CategoryTraining

    Inputs (11)

    NameTypeDefaultDescription
    vocabulary_sizeINT100001–1000000
    input_sizeINT11–1000000
    hidden_sizeINT11–1000000
    num_layersINT11–1000
    nonlinearityCOMBO2 options: tanh, relu
    biasBOOLEANtrue
    batch_firstBOOLEANtrue
    dropoutFLOAT0.000–1
    bidirectionalBOOLEANfalse
    linear_output_sizeINT11–1000000
    linear_biasBOOLEANtrue

    Outputs (1)

    NameTypeDescription
    PTMODELPTMODEL