Introduction
Machine Studying depends closely on linear algebra operations, particularly, it’s important to grasp properly how multiplications between matrices (or extra exactly between tensors) work.
I’ve often observed that these approaching the examine of Machine Studying frameworks reminiscent of PyTorch or Tensorflow have many issues when bumping into errors regarding measurement mismatch between tensors. On this brief article, I wish to shed some readability on this and introduce the usage of einsum.
From scalars to tensors
In Machine Studying, we differentiate the info in line with its dimension (dim). It’s common to work with:
- Scalars dim = 0
- Vectors dim = 1
- Matrices dim = 2
- Tensors dim = 3 ( or extra)
In PyTorch we are able to very simply create these knowledge varieties.
import torch# Create a scalar tensor
scalar…