Practical overview
When it fits
Use it when a tensor or matrix expression fails with an unhelpful dimension error, or when you need to trace shapes through a more complex expression.
Who it is for
- Developers debugging tensor dimensions in deep-learning expressions.
- Python programmers using NumPy, PyTorch, JAX, TensorFlow, Keras or fastai.
Documented uses
- Identify which operator and operand dimensions caused a matrix-algebra exception.
- Visualize tensor shapes in Python expressions or inspect shapes across an expression tree.
Requirements & limits
The repository declares an MIT license and documents installation with pip.
- The README names NumPy, PyTorch, JAX, TensorFlow, Keras and fastai as supported contexts.
- AST visualization requires Graphviz's dot executable in addition to the Python library.
- Parsing is limited to assignments and expressions; backslash continuations are unsupported.
- Clarify may re-evaluate statements, so functions with side effects can run; concurrent calls from multiple threads are discouraged.
Check current requirements in the official documentation. Source-based guidance does not mean OpenViST has run or independently tested this project.
Install Tensor Sensor and prepare AST visualization
Install the library and, if you plan to display AST visualizations, prepare the Graphviz executable it requires.
Before you start
- Python with pip
- For AST visualization, the Graphviz dot executable
Steps
Install the base package with the command below.
pip install tensor-sensorIf needed, install a framework dependency group with the command below, the command below, or the command below; the README also lists
tensor-sensor[all].pip install tensor-sensor[torch]pip install tensor-sensor[tensorflow]pip install tensor-sensor[jax]For AST visualization, install Graphviz: the README gives
brew install graphvizfor Mac andconda install python-graphvizfor Windows.
Expected outcome
The README says installation provides the `tsensor` module; Graphviz's dot executable is required for `tsensor.astviz()` displays.
Guide limitations
- The base package installation does not install framework dependencies.
- The README's platform instructions are specific to Mac and Windows.
- Tensor Sensor parses assignments and expressions; it cannot handle backslash continuations.
Add shape context around a tensor expression
Use the documented `clarify` context to obtain shape-aware diagnostics for an expression.
Before you start
- Tensor Sensor installed as
tsensor - A Python expression using a named tensor context such as NumPy
Steps
Define the tensors used by the expression.
Place the expression in a
with tsensor.clarify() as c:block, as in the README'sY = W @ X.T + bexample.Inspect the resulting visualization or augmented exception for operator and operand-shape information.
Expected outcome
The README example shows an augmented matrix-multiplication error identifying the operator and the shapes of its operands.
Guide limitations
- The routines parse assignments or expressions and do not handle a one-line function body in the shown form.
- Statements may be re-evaluated, so functions with side effects can run.
- Do not call
clarify()from multiple Python threads.
Sources & review
Source record details
- Source availability
- Active
- Sources checked
- 6 November 2026
- Original website title
- parrt/tensor-sensor · Official homepage title · retained in its source language

