BHS Links
BHSLinks
Order

Canada — AI / 30-11-2026

How Tensors Power Real Training in Deep Learning

Tensors are the data structure under every model

Open any deep learning tutorial and within the first few paragraphs you will meet a tensor. The word sounds intimidating, borrowed as it is from physics and differential geometry, but in machine learning it means something narrower and more practical: a rectangular container of numbers with a fixed number of axes, plus the rules for doing arithmetic on it. That is the whole idea. A scalar is a tensor with zero axes, a vector has one, a matrix has two, and the colour values of a batch of images might have four.

Why does this matter to anyone training a model in Toronto or Vancouver? Because the tensor is where your data lives and where gradients accumulate. When you read Deep Learning with Python, Second Edition, the author builds almost everything from tensors first, before touching layers or loss functions. Once you understand shape, axis and dtype, most error messages stop being cryptic and start pointing at a real mistake in your code.

The other thing to know is that tensors are not just NumPy arrays with a fancier name. Library tensors carry a device location, usually a GPU, and a record of the operations that produced them. That record is what makes automatic differentiation possible, and it is why a training loop can compute the gradient of a loss with respect to millions of weights without you writing a single derivative by hand.

Shape, axis and the mistakes that cost hours

Shape is the number of elements along each axis, written as a tuple. A batch of 64 grayscale images at 28 by 28 pixels has shape 64 by 1 by 28 by 28. A fully connected layer expects a flat vector per sample, so you reshape to 64 by 784. Get the order wrong and the model still runs, which is worse than a crash; it quietly learns nothing useful because the channels and pixels have been scrambled.

Broadcasting, the rule that saves and ruins code

Broadcasting lets operations work between tensors of different shapes when the trailing dimensions are compatible. Adding a tensor of shape 1 by 10 to one of shape 64 by 10 works, because the single row is repeated across the batch. Subtracting a mean of shape 10 from a tensor of shape 64 by 10 by 3 will fail, and the fix is almost always an explicit unsqueeze or a keepdim argument in the reduction.

A common Canadian example: a team at a Vancouver company trains a model on sensor readings from equipment in Sudbury. They compute per-channel means over a batch but forget that the reduction collapses the axis they later rely on. The training loss plateaus, someone spends an afternoon printing shapes, and the fix is one argument. Printing shapes at every step is the habit that prevents this class of bug.

Dtype matters too. Canadian privacy rules and internal data handling policies aside, plain numerical mistakes abound: integer tensors cannot hold gradients, and half precision on older GPUs can produce silent overflow. Start in 32-bit floats, profile, and only then move to mixed precision.

How tensors behave on the hardware you actually own

A CPU tensor and a GPU tensor with the same numbers are different objects, and operations between them raise an error. Moving data across the bus is often the slowest part of a small training step, which is why feeding your data efficiently matters more than raw GPU speed for many student projects. If you are choosing a laptop for deep learning, an entry-level discrete GPU with enough memory for your batch size will outperform a CPU-only machine by a wide margin, and cloud rentals in Canadian regions are a reasonable alternative when a single experiment runs for hours.

Memory is the constraint people underestimate. Every tensor you keep alive during the forward pass is needed again in the backward pass unless you checkpoint it. On a modest 8 GB card, a batch that fits in memory during evaluation can fail during training for exactly this reason. Reducing batch size, freeing intermediate tensors, and using gradient accumulation are the standard fixes.

Autograd is the other half of the story. Libraries track operations on tensors that require gradients, build a graph, and walk it backwards. Calling detach or wrapping a block in a no-gradient context tells the library to skip the bookkeeping, which is essential during evaluation and inference. Forgetting to zero gradients each step is the classic beginner error: losses drift upward and nobody knows why.

Where tensors show up beyond image classifiers

The same machinery runs fraud detection models at Canadian banks, algorithmic trading research at fintech firms, and natural language pipelines that use spaCy for tokenization before handing off to a transformer. Symbolic AI versus machine learning debates aside, the tensor is the common substrate for anything gradient-based, whether it is a recommendation system or a model that estimates credit risk.

As models move into production, machine learning operations teams care about tensors in a different way: shapes and dtypes become part of the serving contract. Export a model to ONNX or TorchScript and the input specification is a tensor shape. Change it without updating the client, and requests fail in production. Documenting input shapes is as important as documenting endpoints.

Advice for anyone starting this week: write ten lines that create tensors, inspect their shape and dtype, and reshape them until the intuition sticks. Then build a two-layer network from scratch on a small dataset. That exercise teaches more about deep learning than any course module on AI introduction, because every concept you meet later, from attention to adversarial machine learning, is expressed in the same language of shaped numbers and gradients.

Related resources