Course set-up

In [1]:
__author__ = "Christopher Potts"
__version__ = "CS224u, Stanford, Spring 2020"

This notebook covers the steps you'll need to take to get set up for CS224u.


We recommend installing the free Anaconda Python distribution, which includes IPython, Numpy, Scipy, matplotlib, scikit-learn, NLTK, and many other useful packages. This is not required, but it's an easy way to get all these packages installed. Unless you're very comfortable with Python package management and like installing things, this is the option for you!

Please be sure that you download the Python 3 version, which currently installs Python 3.7. Although our code is largely compatible with Python 2, we're not supporting Python 2.

One you have Anaconda installed, it makes sense to create a virtual environment for the course. In a terminal, run

conda create -n nlu python=3.7 anaconda

to create an environment called nlu.

Then, to enter the environment, run

conda activate nlu

To leave it, you can just close the window, or run

conda deactivate nlu

If your version of Anaconda is older than version 4.4 (see anaconda --version), then replace conda with source in the above (and consider upgrading your Anaconda!).

This page has more detailed instructions on managing virtual environments with Anaconda.

The course Github repository

The core materials for the course are on Github:

We'll be working in this repository a lot, and it will receive updates throughout the quarter, as we add new materials and correct bugs.

If you're new to git and Github, we recommend using Github's Desktop Apps. Then you just have to clone our repository and sync your local copy with the official one when there are updates.

If you are comfortable with git in the command line, you can type the following command to clone the course's Github repo:

git clone

Main data distribution

The datasets needed to run the course notebooks and complete the assignments are in the following zip archive:

We recommend that you download it, unzip it, and place it in the same directory as your local copy of this Github repository. If you decide to put it somewhere else, you'll need to adjust the paths given in the "Set-up" sections of essentially all the notebooks.

Additional installations

Be sure to do these additional installations from inside your virtual environment for the course!

Installing the package requirements

Just run

pip install -r requirements.txt

from inside the course directory to install the core additional packages.

People who aren't using Anaconda should edit requirements.txt so that it installs all the prerequisites that come with Anaconda. For Anaconda users, there's no need to edit it or even open it.


The PyTorch library has special installation instructions depending on your computing environment. For Anaconda users, we recommend

conda install pytorch torchvision -c pytorch

For non-Anaconda users, or if you have a CUDA-enabled GPU, we recommend following the instructions posted here:

For this course, you should be running at least version 1.3.0:

In [2]:
import torch



We won't work too much with TensorFlow in this course, but the mittens package, which implements GloVe, will be much faster if TensorFlow is available.

To install TensorFlow, with Anaconda or another environment:

pip install tensorflow

If you have a CUDA-enabled GPU, you should instead do

pip install tensorflow-gpu

If you're using an older version of Anaconda, you might be better off with

conda install -c conda-forge tensorflow

For additional instructions:

For this course, you should be running at least version 1.13.0.

NLTK data

Anaconda comes with NLTK but not with its data distribution. To install that, open a Python interpreter and run import nltk; If you decide to download the data to a different directory than the default, then you'll have to set NLTK_DATA in your shell profile. (If that doesn't make sense to you, then we recommend choosing the default download directory!)

Jupyter notebooks

The majority of the materials for this course are Jupyter notebooks, which allow you to work in a browser, mixing code and description. It's a powerful form of literate programming, and increasingly a standard for open science.

To start a notebook server, navigate to the directory where you want to work and run

jupyter notebook --port 5656

The port specification is optional.

This should launch a browser that takes you to a view of the directory you're in. You can then open notebooks for working and create new notebooks.

A major advantage of working with Anaconda is that you can switch virtual environments from inside a notebook, via the Kernel menu. If this isn't an option for you, then run this command while inside your virtual environment:

python -m ipykernel install --user --name nlu --display-name "nlu"

(If you named your environment something other than nlu, then change the --name and --display-name values.)

Additional discussion of Jupyter and kernels.