Ptn Embedding RNN Linear
A text classifier in one node
- PTMODEL
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 -
tanhorrelu. - bias, batch_first, dropout, bidirectional - RNN settings;
dropoutonly 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_sizemust cover your tokenizer's vocab, and token IDs must be ints in range. - Dropout doing nothing -
dropoutonly affects intermediate layers; withnum_layers = 1it'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_classificationdoc is the authoritative walkthrough.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| vocabulary_size | INT | 100001–1000000 | — |
| input_size | INT | 11–1000000 | — |
| hidden_size | INT | 11–1000000 | — |
| num_layers | INT | 11–1000 | — |
| nonlinearity | COMBO | 2 options: tanh, relu | |
| bias | BOOLEAN | true | — |
| batch_first | BOOLEAN | true | — |
| dropout | FLOAT | 0.000–1 | — |
| bidirectional | BOOLEAN | false | — |
| linear_output_size | INT | 11–1000000 | — |
| linear_bias | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |