This is a NumPy/PyTorch tutorial for CSE 447/517 NLP class (Winter 2021) at the University of Washington. It is divided into three parts: 01_numpy_tutorial.py introduces basic NumPy concepts; 02_pytorch_tutorial.py explains auto-differentiation with PyTorch and walks through a toy multinomial logistic regression classifier in depth; and 03_sentiment_classification_example.py is a more realistic example that handles tokenization, out-of-vocabulary tokens, grouping together and padding similar-lengthed texts, a fairly sophisticated model, GPU utilization, etc. These files (or at least the first two) are designed to be walked through in part of a 50-minute section, so they are quite brief. Each file contains pointers to more comprehensive introductions and examples.

This code has been tested with Python 3.7 and 3.8. You can install the dependencies with pip install -r requirements.txt. PyTorch installation may be a bit more complicated with certain systems and/or CUDA drivers. Refer to the install instruction in their official website if you run into any issue.

The notebook version of these files (perhaps slighly outdated) can be found at:

  1. 01_numpy_tutorial.ipynb
  2. 02_pytorch_tutorial.ipynb
  3. 03_sentiment_classification_example.ipynb