Learn about Tensors and how to use them in one of the most famous machine learning libraries, pytorch
One of most important libraries in the Deep Learning field (and inclusively, where ChatGPT was built upon) is pytorch
. Along with the Tensorflow framework, pytorch
is one of the most famous neural network training frameworks available for software developers and data scientists. Apart from its usability and simple API, it excels in flexibility and memory usage, making it extremely fast in multi-dimensional calculus (one of the major components behind backpropagation, the important technique that is used to optimize Neural Network’s weights) — these details make it one of the most sought after libraries by companies when it comes to build Deep Learning models.
In this blog post, we’re going to check some basic operations using pytorch
and understand how we can work with the tensor
object! Tensors are mathematical representations of data that are commonly addressed by different names:
- 1 element Tensor: commonly called the scalar, consists of a single mathematical value.
- 1-Dimensional Tensor: consisting of n examples, they are normally called 1-D vectors and stores different mathematical elements in a single dimension.
- 2-Dimensional Tensors: commonly called matrices, are able to store data in two dimensions. Think of a normal SQL table or an excel spreadsheet.
- 3-Dimensional Tensors and beyond: Data organized with this dimensionality are normally harder to visualize and are generally called n-dimensional tensors.
With this small introduction on mathematical concepts, let’s explore how to use pytorch
in Python!
As we’ve described, the tensor object is a mathematical generalization of n-dimensional objects that can expand to virtually any dimension. Although in the context of Deep Learning, tensors
are generally multidimensional, we can also create single element tensors (normally called scalars) using torch
(although named pytorch
, we use the name torch
to manipulate the library in Python).