Ptn RNN Linear
Ptn RNN Linear goes from sequences straight to class scores
- PTMODEL
PtnRNNLinear is the "I want a working text classifier, not a hobby" version of the pack's RNN node. It's the same vanilla nn.RNN under the hood, but with a linear layer already bolted on the end, so the model you get out the PTMODEL port can eat a sequence and spit out class scores directly. It's the model node used in the pack's rnn_classification.json example, and it saves you from wiring an RNN to a separate head and praying the shapes line up.
Why you'd reach for it
A bare RNN returns a sequence of hidden states - useful, but not a prediction. To classify you need to condense that sequence and project it to class scores. This node does both. If you look at rnn_classification.json, the pattern is: GloVe tokenized data → this model → Ptn BCEWithLogitsLoss for the loss, Pto Adam to optimize, Pto Lr Scheduler Reduce On Plateau to babysit the learning rate, and Pt Train RNN Model to run the loop. Everything before the training node is just assembling the pieces; this node is the piece that makes the model mean something.
How it works
The node builds an nn.RNN with the same settings as Ptn RNN (input_size, hidden_size, num_layers, tanh/relu, batch_first, dropout, bidirectional), then passes the RNN's full output sequence through a pooling step and a nn.Linear head. The pooling is a mean over the valid (non-padded) tokens in the sequence - the source explicitly skips padding when averaging, which is the kind of detail that quietly matters when your batches have wildly different sequence lengths. Output width of the linear layer is linear_output_size; its input width is hidden_size × 2 if you went bidirectional, because both directions get concatenated.
Inputs that matter
- input_size - features per timestep (embedding dimension for text).
- hidden_size - RNN width; your capacity knob.
- num_layers - RNN depth; >1 enables dropout between layers.
- nonlinearity -
tanhorrelu. - bidirectional - doubles effective hidden size and helps with short sequences.
- linear_output_size - the classifier head's output width. Set this to your number of classes (1 for binary classification with BCEWithLogits).
- linear_bias - bias in the head; leave
True.
Output is a single PTMODEL, ready for Pt Train RNN Model or the predict/evaluate nodes.
Where people get burned
Set linear_output_size to the wrong count and you'll train fine but get nonsense - for binary classification this pack uses BCEWithLogits, so the head should output 1 score, not 2. batch_first defaults to True here (deliberately opposite to raw PyTorch), so feed [Batch, Seq, Token] tensors and don't flip it. And remember the RNN is still an RNN: stack more than a couple of num_layers and the vanishing-gradient problem shows up exactly as it would anywhere else.
Installing it
Part of ComfyUI-Pt-Wrapper (HowToSD's no-code PyTorch pack, a spin-off of ComfyUI-Data-Analysis). ComfyUI Manager → search "ComfyUI-Pt-Wrapper", or:
cd ComfyUI/custom_nodes
git clone https://github.com/HowToSD/ComfyUI-Pt-Wrapper
Restart after; the first boot is slow while pandas, scikit-learn, transformers, sentencepiece, peft and friends install. No model downloads for the node itself - the example workflow fetches its dataset when run.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| 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.0000–1 | — |
| bidirectional | BOOLEAN | false | — |
| linear_output_size | INT | 11–1000000 | — |
| linear_bias | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| PTMODEL | PTMODEL | — |