Your tensors don't fit, and the error message knows it
A debugging library that intercepts cryptic matrix-mismatch exceptions and redraws them with actual tensor shapes attached.
What it does
TensorSensor wraps your NumPy, PyTorch, JAX, or TensorFlow code and rewrites the exception messages you get when matrix dimensions collide. Instead of matmul: Input operand 1 has a mismatch in its core dimension 0, you get Cause: @ on tensor operand W w/shape (764, 100) and operand X.T w/shape (764, 200). It also draws AST diagrams showing every sub-expression’s shape.
The interesting bit
The author built a custom parser that re-evaluates your assignment statements to capture intermediate shapes, then injects that context back into the error. It’s a small act of interpreter-level revenge against one of deep learning’s most tedious debugging rituals.
Key highlights
- Works across NumPy, PyTorch, JAX, TensorFlow, Keras, and fastai with optional dependency installs (
[torch],[tensorflow],[jax],[all]) - Two modes:
tsensor.clarify()for augmented exceptions,tsensor.astviz()for full computation-tree diagrams - Requires actual Graphviz
dotbinary (not just the Python package) for AST visualization - Version 1.0 as of December 2021; tested against TensorFlow 2.5.0, PyTorch 1.10.0, JAX 0.2.20
Caveats
- M1 Macs hit illegal instruction errors in many Anaconda-installed tensor libraries as of September 2021 (PyTorch excepted)
- Custom parser only handles assignment statements and expressions; inline method bodies and
\line continuations break it - Side effects in re-evaluated statements will execute twice; not thread-safe with
threading
Verdict
Grab it if you’re teaching deep learning or still squinting at gufunc signature errors. Skip if your debugging is already handled by a typed tensor library or you live entirely in method-chained one-liners.
Frequently asked
- What is parrt/tensor-sensor?
- A debugging library that intercepts cryptic matrix-mismatch exceptions and redraws them with actual tensor shapes attached.
- Is tensor-sensor open source?
- Yes — parrt/tensor-sensor is open source, released under the MIT license.
- What language is tensor-sensor written in?
- parrt/tensor-sensor is primarily written in Jupyter Notebook.
- How popular is tensor-sensor?
- parrt/tensor-sensor has 804 stars on GitHub.
- Where can I find tensor-sensor?
- parrt/tensor-sensor is on GitHub at https://github.com/parrt/tensor-sensor.