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