pip3 install torch torchvision
Broadcast Semantics: the 1D operation can also apply on higher dimension (In short, if a PyTorch operation supports broadcast, then its Tensor arguments can be automatically expanded to be of equal sizes (without making copies of the data).)
- can't broadcast:
torch.dot
(unlikenumpy.dot
)
- PyTorch use dynamic computational graph while TensorFlow use static one.
- Kaggle PyTorch Dataset and DataLoader
- PyTorch Data Loading and Processing Tutorial
- How to get mini-batches in pytorch in a clean and efficient way?
- A detailed example of how to generate your data in parallel with PyTorch
- 莫煩Python - Batch Training
Customized
- torch.utils.data
from torch.utils.data import DataLoader, Dataset
Ready-made
from torchtext.datasets import text_classification
- Use
ipdb
. (import ipdb; ipdb.set_trace()
) - Usually print tensor shape can find the problem easier
Use a PrintLayer
class PrintLayer(nn.Module):
def __init__(self):
super(PrintLayer, self).__init__()
def forward(self, x):
# Do your print / debug stuff here
print(x)
return x
model = nn.Sequential(
nn.Linear(1, 5),
PrintLayer(), # Add Print layer for debug
nn.ReLU(),
nn.Linear(5,1),
nn.LogSigmoid(),
)
x = Variable(torch.randn(10, 1))
output = model(x)
- Get Started
- PyTorch Tutorial
- github
- Learning PyTorch with Exmaples
- Tensors
- Autograd
- nn Module
- Deep Learning for NLP with Pytorch
- PyTorch Examples
- Learning PyTorch with Examples
- yunjey/pytorch-tutorial - PyTorch Tutorial for Deep Learning Researchers
- INTERMT/Awesome-PyTorch-Chinese
- PyTorchZeroToAll - Quick 3~4 day lecture materials for HKUST students
- L1aoXingyu/pytorch-beginner - pytorch tutorial for beginners
- xiaobaoonline/pytorch-in-action - Source code of book PyTorch機器學習從入門到實戰
- pytorch handbook (Chinese)
- sgrvinod/a-PyTorch-Tutorial-to-Sequence-Labeling - a PyTorch Tutorial to Sequence Labeling
- jcjohnson/pytorch-examples: Simple examples to introduce PyTorch
- chenyuntc/pytorch-book: PyTorch tutorials and fun projects including neural talk, neural style, poem writing, anime generation
BiRNN
Embedding
Attention
- williamFalcon/pytorch-lightning - The lightweight PyTorch wrapper for ML researchers. Scale your models. Write less boilerplate
- Swall0w/torchstat: Model analyzer in PyTorch
- harvardnlp/pytorch-struct: Fast, general, and tested differentiable structured prediction in PyTorch
NLP
- PyTorch-NLP - Supporting Rapid Prototyping with a Toolkit (including Datasets and Neural Network Layers)
- AllenNLP - An open-source NLP research library, built on PyTorch
- torchtext
- huggingface/pytorch-transformers
- threelittlemonkeys/lstm-crf-pytorch: LSTM-CRF in PyTorch
CV
- pytorch/vision: Datasets, Transforms and Models specific to Computer Vision
- facebookresearch/pytorch3d: PyTorch3D is FAIR's library of reusable components for deep learning with 3D data
Others
torch.bmm
vs.torch.mm
vs.torch.matmul
torch.permute
vs.torch.transpose
vs.torch.view
Why optimizer.zero_grad()
?
nn.Module in list can't be auto assign .to(device)
, put it in nn.ModuleList and use it as normal list will solve the problem