ComfyUI Node

NNT Tensor To Text

Read a tensor without leaving the graph

By inventorado·Created 2 years ago·Updated 2 years ago· 69
NNT Tensor To Text
  • tensor
  • text_output
format_optionplain_text
precision4
max_elements100

Half of learning a neural network toolkit is being able to look at the numbers, and ComfyUI gives you no native way to stare at a torch tensor. NNT Tensor To Text is the "show me the digits" node: it converts any TENSOR into a STRING you can feed into a text display node and actually read. In a pack built for teaching, this is the flashlight you carry everywhere.

It's also the natural opposite of NntTextToTensor - that node parses text into a tensor; this one renders a tensor as text. Together they're the pack's type-conversion bookends.

What it does

Three options shape the output:

  • format_option - plain_text prints the tensor as-is with numpy's array formatting; formatted_text rounds every value to your precision; summary forgets the raw numbers entirely and prints a compact digest: shape, mean, std, min, max.
  • precision - decimal places (default 4).
  • max_elements - the cap on how many values get printed (default 100). This is the node's self-defense: feed it a 10,000-element tensor and it prints the first 100 and appends "… (output truncated to first 100 elements)".

You get one STRING output, text_output.

Why it matters

Concrete uses: after NntRandomTensorGenerator, dump the tensor to check your distribution actually looks uniform-ish. After a training run, wire the model's weights or an intermediate activation into this node and read the scale of the values - you'll spot exploding activations long before the loss plot tells you something's off. And when you're debugging a NntTensorOperations gradient exercise, the gradient_tensor output becomes readable only through something like this.

The summary mode deserves special mention as the underrated option. For a learning workflow it's usually more useful than 100 raw floats: "Tensor Summary: Shape: (100, 10), Mean: 0.4982, Std: 0.2873, Min: -0.0012, Max: 0.9991" tells you in one glance whether your generated data is well-behaved. That's the output you'll reach for when you're not trying to prove a specific math fact.

Install and notes

Pack-level install, once:

cd ComfyUI/custom_nodes
git clone https://github.com/inventorado/ComfyUI_NNT.git
cd ComfyUI_NNT
pip install -r requirements.txt

Restart ComfyUI (or Manager → "ComfyUI Neural Network Toolkit NNT"). The full requirements list is heavy - torch, numpy, pandas, matplotlib, sklearn, transformers, statsmodels, onnx, shap 0.41.0 and friends - so the first install runs long.

One thing to know: the max_elements cap applies before anything is computed, summary included. The node slices the tensor down to the first max_elements values first, then computes mean/std/min/max on that slice - so on a huge tensor the "summary" describes only the head of it, not the whole thing. It just doesn't tell you it truncated (only the raw-number modes append the "… truncated" note). If you need true summary stats on a big tensor, bump max_elements or slice the tensor before it reaches this node.

CategoryNNT Neural Network Toolkit/Tensors

Inputs (4)

NameTypeDefaultDescription
tensorTENSOR
format_optionCOMBOplain_text3 options: plain_text, formatted_text, summary
precisionINT40–10
max_elementsINT1001–1000000

Outputs (1)

NameTypeDescription
text_outputSTRING