Tensor
In machine learning a tensor is a multi-dimensional array of numbers of a single data type, the basic container that holds a model's inputs, weights and outputs.
TensorFlow's documentation defines tensors as multi-dimensional arrays with a uniform type. A single number is a rank-0 tensor, or scalar. A list of numbers is a rank-1 tensor, or vector. A table is a rank-2 tensor, or matrix. Add more axes and you get higher-rank tensors. Google's machine learning glossary calls the tensor the primary data structure in TensorFlow programs, most commonly a scalar, vector or matrix.
Three words describe a tensor. Its rank is the number of axes. Its shape is the number of elements along each axis. Its size is the total number of elements, the product of the shape. A batch of 32 colour photos, each 224 by 224 pixels with three colour channels, fits in a tensor of shape [32, 224, 224, 3]: rank 4, holding 4,816,896 numbers. TensorFlow's guide notes the usual convention of putting the batch axis first, then spatial axes, then features.
Almost everything a neural network does is arithmetic on tensors. The input, the model's weights, the intermediate activations and the output are all tensors, and the heavy lifting is multiplying them together. Text becomes a tensor of token numbers, then a tensor of embeddings. Each tensor also has a data type, such as 32-bit or 16-bit floating point numbers or 8-bit integers, and storing values at lower precision is the basis of quantisation.
The word is stamped on the industry's tools. Google's TensorFlow framework is built around tensors, Google's custom AI chip is the Tensor Processing Unit, and NVIDIA introduced Tensor Cores, circuits that multiply small matrices very quickly, with its Volta GPU architecture in 2017. PyTorch, the other framework most often named alongside it, also uses tensors as its core data type.
A note for anyone with a physics or maths background: the machine learning usage is looser than theirs. In mathematics a tensor is defined by how it behaves when coordinates change. Machine learning data tensors are not bound by those transformation rules, so they should not be confused with tensors in the mathematical sense. In AI writing, tensor simply means a multi-dimensional array of numbers.
A tensor is a grid of numbers with any number of dimensions. A single number, a list, a table and a stack of tables are all tensors, of rank 0, 1, 2 and 3. Machine learning frameworks use tensors to hold data, model weights and results. A matrix is one particular kind of tensor, with exactly two axes: rows and columns. Tensors generalise this to any number of axes, so a colour image is naturally a three-axis tensor and a batch of images a four-axis one. Because tensors are its basic data structure: Google's glossary describes the tensor as the primary data structure in TensorFlow programs. Computations in the framework take tensors as inputs, transform them and pass tensors on to the next operation. Tensor Cores are specialised circuits in NVIDIA GPUs that perform small matrix multiplications very quickly, the core operation in neural networks. NVIDIA introduced them with its Volta architecture in 2017.Common questions
What is a tensor in simple terms?
What is the difference between a tensor and a matrix?
Why is it called TensorFlow?
What are Tensor Cores?
Search for "tensor shape rank", "PyTorch tensors tutorial" or "TensorFlow tensor guide" to see tensors in code. The official documentation for TensorFlow, PyTorch and NumPy is the most reliable source, and introductory machine learning courses cover the basics well. If you meet the word in physics or pure mathematics, look for sources in those fields, since the meaning there is stricter.Finding more
Working out what this means for your business?
Aileron Shift builds the systems behind this site: AI newsrooms that research, write and publish on their own, marketing automation and WordPress hosting for companies that need to move faster than their competitors.