├── docs ├── errata.rst ├── day2 │ ├── prefpractice.rst │ ├── adventures │ │ ├── conv_then_rnn.rst │ │ ├── index.rst │ │ ├── lvg.rst │ │ ├── interpolation.rst │ │ └── lookups.rst │ ├── patterns │ │ ├── stacking.rst │ │ ├── index.rst │ │ ├── gating.rst │ │ └── attention.rst │ └── warmup.rst ├── recipes │ ├── packed_sequences.rst │ ├── index.rst │ ├── compute_conv_size.rst │ └── load_pretrained_vectors.rst ├── .gitignore ├── _build │ ├── html │ │ ├── objects.inv │ │ ├── _static │ │ │ ├── up.png │ │ │ ├── down.png │ │ │ ├── file.png │ │ │ ├── minus.png │ │ │ ├── plus.png │ │ │ ├── comment.png │ │ │ ├── up-pressed.png │ │ │ ├── ajax-loader.gif │ │ │ ├── comment-close.png │ │ │ ├── down-pressed.png │ │ │ ├── comment-bright.png │ │ │ ├── fonts │ │ │ │ ├── Lato-Bold.ttf │ │ │ │ ├── Lato-Regular.ttf │ │ │ │ ├── Inconsolata-Bold.ttf │ │ │ │ ├── RobotoSlab-Bold.ttf │ │ │ │ ├── Inconsolata-Regular.ttf │ │ │ │ ├── RobotoSlab-Regular.ttf │ │ │ │ ├── fontawesome-webfont.eot │ │ │ │ ├── fontawesome-webfont.ttf │ │ │ │ └── fontawesome-webfont.woff │ │ │ ├── css │ │ │ │ └── badge_only.css │ │ │ ├── pygments.css │ │ │ ├── js │ │ │ │ └── theme.js │ │ │ ├── doctools.js │ │ │ ├── underscore.js │ │ │ └── basic.css │ │ ├── .buildinfo │ │ ├── _sources │ │ │ ├── faq.rst.txt │ │ │ ├── download_data.rst.txt │ │ │ ├── index.rst.txt │ │ │ └── environment_setup.rst.txt │ │ ├── genindex.html │ │ ├── search.html │ │ ├── searchindex.js │ │ ├── faq.html │ │ ├── download_data.html │ │ └── index.html │ └── doctrees │ │ ├── faq.doctree │ │ ├── index.doctree │ │ ├── environment.pickle │ │ ├── download_data.doctree │ │ └── environment_setup.doctree ├── day1 │ ├── index.rst │ └── takehome.rst ├── Makefile ├── faq.rst ├── download_data.rst ├── index.rst ├── environment_setup.rst └── conf.py ├── datautils ├── __init__.py └── vocabulary.py ├── day_1 ├── local_settings.py ├── figures │ └── intro_to_pytorch │ │ ├── computational_graph_forward.svg │ │ ├── pytorch_variable.svg │ │ └── computational_graph_backward.svg └── 0_Using_Pretrained_Embeddings.ipynb ├── day_2 └── local_settings.py ├── requirements.txt ├── README.md ├── data └── README.md ├── modelzoo └── README.md ├── LICENSE ├── LOCAL_RUN_README.md ├── .gitignore └── settings.py /docs/errata.rst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /datautils/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/day2/prefpractice.rst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/recipes/packed_sequences.rst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/day2/adventures/conv_then_rnn.rst: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | _build/ 2 | _static/ 3 | _templates/ 4 | -------------------------------------------------------------------------------- /docs/day2/patterns/stacking.rst: -------------------------------------------------------------------------------- 1 | Stacking 2 | ======== 3 | -------------------------------------------------------------------------------- /day_1/local_settings.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('..') 3 | 4 | import settings, datautils -------------------------------------------------------------------------------- /day_2/local_settings.py: -------------------------------------------------------------------------------- 1 | import sys 2 | sys.path.append('..') 3 | 4 | import settings, datautils -------------------------------------------------------------------------------- /docs/day2/patterns/index.rst: -------------------------------------------------------------------------------- 1 | NN Patterns 2 | =========== 3 | 4 | .. toctree:: 5 | 6 | attention 7 | -------------------------------------------------------------------------------- /docs/_build/html/objects.inv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/objects.inv -------------------------------------------------------------------------------- /docs/_build/doctrees/faq.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/doctrees/faq.doctree -------------------------------------------------------------------------------- /docs/_build/html/_static/up.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/up.png -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | pandas 2 | nltk 3 | annoy 4 | seaborn 5 | numpy 6 | matplotlib 7 | scikit-learn 8 | tqdm 9 | ipywidgets 10 | -------------------------------------------------------------------------------- /docs/_build/doctrees/index.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/doctrees/index.doctree -------------------------------------------------------------------------------- /docs/_build/html/_static/down.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/down.png -------------------------------------------------------------------------------- /docs/_build/html/_static/file.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/file.png -------------------------------------------------------------------------------- /docs/_build/html/_static/minus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/minus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/plus.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/plus.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/comment.png -------------------------------------------------------------------------------- /docs/_build/doctrees/environment.pickle: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/doctrees/environment.pickle -------------------------------------------------------------------------------- /docs/_build/html/_static/up-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/up-pressed.png -------------------------------------------------------------------------------- /docs/_build/doctrees/download_data.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/doctrees/download_data.doctree -------------------------------------------------------------------------------- /docs/_build/html/_static/ajax-loader.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/ajax-loader.gif -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-close.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/comment-close.png -------------------------------------------------------------------------------- /docs/_build/html/_static/down-pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/down-pressed.png -------------------------------------------------------------------------------- /docs/_build/html/_static/comment-bright.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/comment-bright.png -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Lato-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/Lato-Bold.ttf -------------------------------------------------------------------------------- /docs/day1/index.rst: -------------------------------------------------------------------------------- 1 | Day 1 2 | ===== 3 | 4 | Here you will find things from Day 1! 5 | 6 | .. toctree:: 7 | :maxdepth: 2 8 | 9 | takehome 10 | -------------------------------------------------------------------------------- /docs/_build/doctrees/environment_setup.doctree: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/doctrees/environment_setup.doctree -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Lato-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/Lato-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Inconsolata-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/Inconsolata-Bold.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/RobotoSlab-Bold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/RobotoSlab-Bold.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/Inconsolata-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/Inconsolata-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/RobotoSlab-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/RobotoSlab-Regular.ttf -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.eot: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/fontawesome-webfont.eot -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/fontawesome-webfont.ttf -------------------------------------------------------------------------------- /docs/day2/adventures/index.rst: -------------------------------------------------------------------------------- 1 | Choose Your Own Adventures 2 | ========================== 3 | 4 | .. toctree:: 5 | 6 | interpolation 7 | lookups 8 | lvg 9 | 10 | -------------------------------------------------------------------------------- /docs/_build/html/_static/fonts/fontawesome-webfont.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joosthub/pytorch-nlp-tutorial-sf2017/master/docs/_build/html/_static/fonts/fontawesome-webfont.woff -------------------------------------------------------------------------------- /docs/_build/html/.buildinfo: -------------------------------------------------------------------------------- 1 | # Sphinx build info version 1 2 | # This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done. 3 | config: 77310103d1aff3f411f58103adc33d75 4 | tags: 645f666f9bcd5a90fca523b33c5a78b7 5 | -------------------------------------------------------------------------------- /docs/recipes/index.rst: -------------------------------------------------------------------------------- 1 | Recipes and PyTorch patterns 2 | ============================ 3 | 4 | 5 | In this section, you will find a set of recipes for doing various things with PyTorch. 6 | 7 | .. toctree:: 8 | 9 | load_pretrained_vectors 10 | compute_conv_size 11 | -------------------------------------------------------------------------------- /docs/day2/patterns/gating.rst: -------------------------------------------------------------------------------- 1 | Gating 2 | ====== 3 | 4 | 5 | 6 | .. code-block:: python 7 | 8 | 9 | resetgate = F.sigmoid(i_r + h_r) 10 | inputgate = F.sigmoid(i_i + h_i) 11 | newgate = F.tanh(i_n + resetgate * h_n) 12 | hy = newgate + inputgate * (hidden - newgate) 13 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Natural Language Processing (NLP) with PyTorch 2 | 3 | Welcome to the repository for the training tutorial as the 2017 O'Reilly AI Conference 4 | in San Francisco on September 16 and 17, 2017. 5 | 6 | You can visit the Read-The-Docs rendering of this repository at [dl4nlp.info](http://dl4nlp.info) 7 | 8 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # Data Folder 2 | 3 | There are several files you will need. you can download them in zip format 4 | from [here](https://drive.google.com/file/d/0B2hg7DTHpfLsdHhEUVhHWU5hUXc/view?usp=sharing). 5 | 6 | 7 | The files you need are: 8 | 9 | - surnames.csv 10 | - trump.csv 11 | - glove.6B.100d.txt 12 | - zhnews.csv 13 | - firstnames.csv 14 | - amazon_train_small.csv 15 | 16 | -------------------------------------------------------------------------------- /docs/recipes/compute_conv_size.rst: -------------------------------------------------------------------------------- 1 | Compute Convolution Sizes 2 | ========================= 3 | 4 | 5 | .. code-block:: python 6 | 7 | import math 8 | 9 | def conv_shape_helper_1d(input_seq_len, kernel_size, stride=1, padding=0, dilation=1): 10 | kernel_width = dilation * (kernel_size - 1) + 1 11 | tensor_size = input_seq_len + 2 * padding 12 | return math.floor((tensor_size - kernel_width) / stride + 1) 13 | -------------------------------------------------------------------------------- /docs/day1/takehome.rst: -------------------------------------------------------------------------------- 1 | Take-Home Exercises 2 | =================== 3 | 4 | Exercise 1 5 | ---------- 6 | 7 | Implement Deep Continuous Bag-of-Words (CBOW). 8 | `Here is a link to the paper! `_ 9 | 10 | 11 | Exercise 2 12 | ---------- 13 | 14 | Complete ConvNet example to do evaluation (in the same manner as the MLP example). 15 | 16 | Exercise 3 17 | ---------- 18 | 19 | Implement a convnet classifier to classify names 20 | 21 | Things to try: with and without padding and changing strides. 22 | 23 | -------------------------------------------------------------------------------- /modelzoo/README.md: -------------------------------------------------------------------------------- 1 | # Model Zoo files 2 | 3 | In this folder, you should place the saved states that we have pre-trained. 4 | 5 | You can download them from [here](https://drive.google.com/file/d/0B2hg7DTHpfLsZW44aTRVd2FrbEE/view?usp=sharing) 6 | 7 | 8 | You should have the following files: 9 | 10 | - trump_twitter.vocab 11 | - surnames_classify.vocab 12 | - charnn_emb16_hid64_surnames_classify.state 13 | - charnn_emb16_hid64_surnames_predict.state 14 | - charnn_emb16_hid64_surnames_conditionally_predict.state 15 | - wordrnn_emb100_hid64_trump_tweets_predict_fresh_train_8_min.state 16 | - wordrnn_emb100_hid64_trump_tweets_predict.state 17 | -------------------------------------------------------------------------------- /docs/Makefile: -------------------------------------------------------------------------------- 1 | # Minimal makefile for Sphinx documentation 2 | # 3 | 4 | # You can set these variables from the command line. 5 | SPHINXOPTS = 6 | SPHINXBUILD = sphinx-build 7 | SPHINXPROJ = pytorch-nlp-tutorial-sf2017 8 | SOURCEDIR = . 9 | BUILDDIR = _build 10 | 11 | # Put it first so that "make" without argument is like "make help". 12 | help: 13 | @$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) 14 | 15 | .PHONY: help Makefile 16 | 17 | # Catch-all target: route all unknown targets to Sphinx using the new 18 | # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). 19 | %: Makefile 20 | @$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O) -------------------------------------------------------------------------------- /docs/faq.rst: -------------------------------------------------------------------------------- 1 | Frequency Asked Questions 2 | ========================= 3 | 4 | On this page, you will find a list of questions that we either anticipate 5 | people will ask or that we have been asked previously. They are intended to 6 | be the first stop for any confusion or trouble that might occur. 7 | 8 | 9 | Do I Need to have a NVIDIA GPU enabled laptop? 10 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11 | 12 | Nope! While having a NVIDIA GPU enabled laptop will make the training run 13 | faster, we provide instructions for people who do not have one. 14 | 15 | If you are plan on working on Natural Language Processing/Deep Learning in the future, 16 | a GPU enabled laptop might be a good investment. 17 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/faq.rst.txt: -------------------------------------------------------------------------------- 1 | Frequency Asked Questions 2 | ========================= 3 | 4 | On this page, you will find a list of questions that we either anticipate 5 | people will ask or that we have been asked previously. They are intended to 6 | be the first stop for any confusion or trouble that might occur. 7 | 8 | 9 | Do I Need to have a NVIDIA GPU enabled laptop? 10 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 11 | 12 | Nope! While having a NVIDIA GPU enabled laptop will make the training run 13 | faster, we provide instructions for people who do not have one. 14 | 15 | If you are plan on working on Natural Language Processing/Deep Learning in the future, 16 | a GPU enabled laptop might be a good investment. 17 | -------------------------------------------------------------------------------- /docs/day2/warmup.rst: -------------------------------------------------------------------------------- 1 | Warm Up Exercise 2 | ================ 3 | 4 | To get you back into the PyTorch groove, let's do some easy exercises. You will have 10 minutes. See how far you can get. 5 | 6 | 1. Use :code:`torch.randn` to create two tensors of size (29, 30, 32) and and (32, 100). 7 | 2. Use :code:`torch.matmul` to matrix multiply the two tensors. 8 | 3. Use :code:`torch.sum` on the resulting tensor, passing the optional argument of :code:`dim=1` to sum across the 1st dimension. Before you run this, can you predict the size? 9 | 4. Create a new long tensor of size (3, 10) from the :code:`np.random.randint` method. 10 | 5. Use this new long tensor to index into the tensor from step 3. 11 | 6. Use :code:`torch.mean` to average across the last dimension in the tensor from step 5. 12 | -------------------------------------------------------------------------------- /docs/download_data.rst: -------------------------------------------------------------------------------- 1 | Getting the Data 2 | ================ 3 | 4 | In this training, there are two options of participating. 5 | 6 | Option 1: Download and Setup things on your laptop 7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8 | 9 | The first option is to download the data below, setup the environment, and download the notebooks when we make them available. 10 | If you choose this options but do not download the data before the first day, we will have several flash drives with the data on it. 11 | 12 | Please visit `this link `_ to download the data. 13 | 14 | 15 | Option 2: Use O'Reilly's online resource through your browser 16 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17 | 18 | The second option is to use an online resource provided by O'Reilly. On the first day of this training, you will be provided with a link to a JupyterHub instance where the environment will be pre-made and ready to go! If you choose this option, you do not have to do anything until you arrive on Sunday. 19 | You are still required to bring your laptop. 20 | 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Joostware AI Research Corp. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/download_data.rst.txt: -------------------------------------------------------------------------------- 1 | Getting the Data 2 | ================ 3 | 4 | In this training, there are two options of participating. 5 | 6 | Option 1: Download and Setup things on your laptop 7 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 8 | 9 | The first option is to download the data below, setup the environment, and download the notebooks when we make them available. 10 | If you choose this options but do not download the data before the first day, we will have several flash drives with the data on it. 11 | 12 | Please visit `this link `_ to download the data. 13 | 14 | 15 | Option 2: Use O'Reilly's online resource through your browser 16 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 17 | 18 | The second option is to use an online resource provided by O'Reilly. On the first day of this training, you will be provided with a link to a JupyterHub instance where the environment will be pre-made and ready to go! If you choose this option, you do not have to do anything until you arrive on Sunday. 19 | You are still required to bring your laptop. 20 | 21 | -------------------------------------------------------------------------------- /docs/recipes/load_pretrained_vectors.rst: -------------------------------------------------------------------------------- 1 | Loading Pretrained Vectors 2 | ========================== 3 | 4 | It can be extremely useful to make a model which had as advantageous starting point. 5 | 6 | To do this, we can set the values of the embedding matrix. 7 | 8 | 9 | .. code-block:: python 10 | 11 | # we give an example of this function in the day 1, word vector notebook 12 | word_to_index, word_vectors, word_vector_size = load_word_vectors() 13 | 14 | 15 | # now, we want to iterate over our vocabulary items 16 | for word, emb_index in vectorizer.word_vocab.items(): 17 | # if the word is in the loaded glove vectors 18 | if word.lower() in word_to_index: 19 | # get the index into the glove vectors 20 | glove_index = word_to_index[word.lower()] 21 | # get the glove vector itself and convert to pytorch structure 22 | glove_vec = torch.FloatTensor(word_vectors[glove_index]) 23 | 24 | # this only matters if using cuda :) 25 | if settings.CUDA: 26 | glove_vec = glove_vec.cuda() 27 | 28 | # finally, if net is our network, and emb is the embedding layer: 29 | net.emb.weight.data[emb_index, :].set_(glove_vec) 30 | -------------------------------------------------------------------------------- /LOCAL_RUN_README.md: -------------------------------------------------------------------------------- 1 | # Running this repository locally 2 | 3 | During the training session, O'Reilly will be providing a JupyterHub for participants. 4 | However, during that time and after the training ends, if you would like to run the contents of this repository, you can do so with the following steps: 5 | 6 | 1. Follow the instructions on [environment setup](http://dl4nlp.info/en/latest/environment_setup.html). 7 | 2. Download the files in the data/ and modelzoo/ folders. The download link is in the `README.md` file in each respective folder. The downloaded files will be zip files. They should be unzipped so that the files are inside these folders. 8 | - in other word, it should be `data/surnames.csv` etc. 9 | - Please make sure this is correct! It may unzip with an extra directory and be `data/data/surnames.csv` and this would be incorrect. 10 | 3. In a terminal with the `dl4nlp` (or equivalent) environment activated (see step 1 if you don't have this), navigate back to the top level (so you can see day_1, etc) and run the following command: 11 | 12 | ```bash 13 | DL4NLPROOT=$(pwd) jupyter notebook --notebook-dir=$(pwd) 14 | ``` 15 | 16 | If you would like to run with CUDA enabled, please run: 17 | 18 | ```bash 19 | ENABLE_CUDA_DL4NLP=1 DL4NLPROOT=$(pwd) jupyter notebook --notebook-dir=$(pwd) 20 | ``` 21 | -------------------------------------------------------------------------------- /docs/day2/adventures/lvg.rst: -------------------------------------------------------------------------------- 1 | A New Load-Vectorize-Generate 2 | ============================= 3 | 4 | In this exercise, you should look into the two datasets that are not included in the exercises. There are two datasets to work with. The first is the Amazon Review dataset. 5 | 6 | .. code-block:: python 7 | 8 | from local_settings import settings 9 | import pandas as pd 10 | 11 | data = pd.read_csv(settings.AMAZON_FILENAME, names=['rating', 'title', 'review']) 12 | print(data.head()) 13 | 14 | The Amazon Reviews Dataset does not come with a precompute train-test split. One thing that would be important is to select a subset to do that. 15 | 16 | The other is the first names dataset. You can load with: 17 | 18 | .. code-block:: python 19 | 20 | from local_settings import settings 21 | import pandas as pd 22 | 23 | data = pd.read_csv(settings.FIRSTNAMES_CSV) 24 | print(data.head()) 25 | 26 | 27 | For these two datasets, you should write a Raw dataset which loads the data. Then, you should write a Vectorizer which creates the relevant vocabularies from the 'fit' method and transforms a raw dataset into a vectorized dataset using the 'transform' method. Finally, you should write a Vectorized datset which implements the required :code:`__len__` and :code:`__getitem__` methods. 28 | 29 | The make_generator can be reused. 30 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | day_1/data/* 2 | # Byte-compiled / optimized / DLL files 3 | __pycache__/ 4 | *.py[cod] 5 | *$py.class 6 | 7 | # C extensions 8 | *.so 9 | 10 | # Distribution / packaging 11 | .Python 12 | env/ 13 | build/ 14 | develop-eggs/ 15 | dist/ 16 | downloads/ 17 | eggs/ 18 | .eggs/ 19 | lib/ 20 | lib64/ 21 | parts/ 22 | sdist/ 23 | var/ 24 | wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | 29 | # PyInstaller 30 | # Usually these files are written by a python script from a template 31 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 32 | *.manifest 33 | *.spec 34 | 35 | # Installer logs 36 | pip-log.txt 37 | pip-delete-this-directory.txt 38 | 39 | # Unit test / coverage reports 40 | htmlcov/ 41 | .tox/ 42 | .coverage 43 | .coverage.* 44 | .cache 45 | nosetests.xml 46 | coverage.xml 47 | *.cover 48 | .hypothesis/ 49 | 50 | # Translations 51 | *.mo 52 | *.pot 53 | 54 | # Django stuff: 55 | *.log 56 | 57 | # Flask stuff: 58 | instance/ 59 | .webassets-cache 60 | 61 | # Scrapy stuff: 62 | .scrapy 63 | 64 | # Sphinx documentation 65 | docs/_build/ 66 | 67 | # PyBuilder 68 | target/ 69 | 70 | # Jupyter Notebook 71 | .ipynb_checkpoints 72 | 73 | # pyenv 74 | .python-version 75 | 76 | # celery beat schedule file 77 | celerybeat-schedule 78 | 79 | # SageMath parsed files 80 | *.sage.py 81 | 82 | # dotenv 83 | .env 84 | 85 | # virtualenv 86 | .venv 87 | venv/ 88 | ENV/ 89 | 90 | # Spyder project settings 91 | .spyderproject 92 | .spyproject 93 | 94 | # Rope project settings 95 | .ropeproject 96 | 97 | # mkdocs documentation 98 | /site 99 | 100 | # mypy 101 | .mypy_cache/ 102 | .DS_Store 103 | amazon_train_small.csv 104 | glove.6B.zip 105 | names_test.csv 106 | names_test_delip_version.csv 107 | names_train.csv 108 | snli_1.0.zip 109 | trump.csv 110 | data/ 111 | -------------------------------------------------------------------------------- /docs/day2/adventures/interpolation.rst: -------------------------------------------------------------------------------- 1 | Exercise: Interpolating Between Vectors 2 | ======================================= 3 | 4 | One fun option for the conditional generation code is to interpolate 5 | between the learned hidden vectors. 6 | 7 | To do this, first look at the code for sampling given a specific nationality: 8 | 9 | .. code-block:: python 10 | :linenos: 11 | 12 | def sample_n_for_nationality(nationality, n=10, temp=0.8): 13 | assert nationality in vectorizer.nationality_vocab.keys(), 'not a nationality we trained on' 14 | keys = [nationality] * n 15 | init_vector = long_variable([vectorizer.nationality_vocab[key] for key in keys]) 16 | init_vector = net.conditional_emb(init_vector) 17 | samples = decode_matrix(vectorizer, 18 | sample(net.emb, net.rnn, net.fc, 19 | init_vector, 20 | make_initial_x(n, vectorizer), 21 | temp=temp)) 22 | return list(zip(keys, samples)) 23 | 24 | As you can see, we create a list of keys that is the length of the number of samples we want (n). 25 | And we use that list to retrieve the correct index from the vocabulary. 26 | Finally, we use that index in the conditional embedding inside the network to get the 27 | initial hidden state for the sampler. 28 | 29 | To do this exercise, write a function that has the following signature: 30 | 31 | .. code-block:: python 32 | 33 | def interpolate_n_samples_from_two_nationalities(nationality1, nationality2, weight, n=10, temp=0.8): 34 | print('awesome stuff here') 35 | 36 | 37 | This should retrieve the :code:`init_vectors` for two different nationalities. Then, using the weight, combine the init vectors as :code:`weight * init_vector1 + (1 - weight) * init_vector2`. 38 | 39 | For fun, after you finish this function, write a for loop which loops over the weight from 0.1 to 0.9 to see how it affects the generation. 40 | -------------------------------------------------------------------------------- /docs/day2/patterns/attention.rst: -------------------------------------------------------------------------------- 1 | Attention 2 | ========= 3 | 4 | Attention is a useful pattern for when you want to take a collection of vectors---whether it be a sequence of vectors representing a sequence of words, or an unordered collections of vectors representing a collection of attributes---and summarize them into a single vector. This has similar analogs to the CBOW examples we saw on Day 1, but instead of just averaging or using max pooling, we are learning a function which learns to compute the weights for each of the vectors before summing them together. 5 | 6 | Importantly, the weights that the attention module is learning is a valid probability distribution. This means that weighting the vectors by the value the attention module learns can additionally be seen as computing the Expection. Or, it could as interpolating. In any case, attention's main use is to select 'softly' amongst a set of vectors. 7 | 8 | The attention vector has several different published forms. The one below is very simple and just learns a single vector as the attention mechanism. 9 | 10 | Using the :code:`new_parameter` function we have been using for the RNN notebooks: 11 | 12 | .. code-block:: python 13 | 14 | def new_parameter(*size): 15 | out = Parameter(FloatTensor(*size)) 16 | torch.nn.init.xavier_normal(out) 17 | return out 18 | 19 | We can then do: 20 | 21 | .. code-block:: python 22 | 23 | class Attention(nn.Module): 24 | def __init__(self, attention_size): 25 | super(Attention, self).__init__() 26 | self.attention = new_parameter(attention_size, 1) 27 | 28 | def forward(self, x_in): 29 | # after this, we have (batch, dim1) with a diff weight per each cell 30 | attention_score = torch.matmul(x_in, self.attention).squeeze() 31 | attention_score = F.softmax(attention_score).view(x_in.size(0), x_in.size(1), 1) 32 | scored_x = x_in * attention_score 33 | 34 | # now, sum across dim 1 to get the expected feature vector 35 | condensed_x = torch.sum(scored_x, dim=1) 36 | 37 | return condensed_x 38 | 39 | 40 | 41 | attn = Attention(100) 42 | x = Variable(torch.randn(16,30,100)) 43 | attn(x).size() == (16,100) 44 | 45 | 46 | -------------------------------------------------------------------------------- /docs/day2/adventures/lookups.rst: -------------------------------------------------------------------------------- 1 | Exercise: Fast Lookups for Encoded Sequences 2 | ========================================== 3 | 4 | Let's suppose that you want to embed or encode something that you want to look up at a later date. 5 | For example, you could be embedded things that need to be identified (such as a song). Or maybe you want to just find the neighbors of a new data point. 6 | 7 | In any case, using the approximate nearest neighbors libraries are wonderful for this. 8 | For this exercise, we will use Spotify's annoy library (we saw this on day 1, in the pretrained word vector notebook). You should aim to complete the following steps: 9 | 10 | 1. Load the network from the Day 2, 01 notebook using the pre-trained weights. 11 | - You could use the 02 notebook, but we want to get a single vector per each sequence. 12 | - So, to use 02, you would need to port the :code:`column_gather` function. 13 | - One reason why you might be interested in doing this is because the 02 objective function learned a better final vector representation. 14 | 2. Given a loaded network with pre-trained weights, write a function which does nearly exactly what the forward function does, but doesn't apply the fully connected layer. 15 | - This is because we want the feature vector just before the fully connected. 16 | - it is common to assume that the penultimate layer has learned more generalizable features than the final layer (which is used in softmax computations and is this used to being normalize inducing a probability distribution). 17 | - The code for this shoud look something like: 18 | 19 | .. code-block:: python 20 | 21 | def get_penultimate(net, x_in, x_lengths=None): 22 | x_in = net.emb(x_in) 23 | x_mid = net.conv(x_in.permute(0, 2, 1)).permute(0, 2, 1) 24 | y_out = net.rnn(x_in) 25 | 26 | if x_lengths is not None: 27 | y_out = column_gather(y_out, x_lengths) 28 | else: 29 | y_out = y_out[:, -1, :] 30 | 31 | return y_out 32 | 33 | 3. As you get penultimate vectors for each datapoint, store them in spotify's annoy. This requires specifying some label for the vector. Using :code:`vectorizer.surname_vocab.lookup` is how you can retrieve the character for each index value in the network inputs. There are some 'decode' functions in the day 2 02 and 03 notebooks. 34 | 4. Once everything is added to spotify's annoy, you can then look up any surname and find the set of nearest neighbors! Kind of cool! this is one way to do the `k nearest neighbor classification rule `_. 35 | -------------------------------------------------------------------------------- /settings.py: -------------------------------------------------------------------------------- 1 | import os 2 | from os.path import join 3 | 4 | 5 | CUDA = bool(os.getenv('ENABLE_CUDA_DL4NLP', False)) 6 | 7 | ROOT_DIR = os.getenv('DL4NLPROOT', None) 8 | if ROOT_DIR is None: 9 | ROOT_DIR = os.getenv('HOME', '.') 10 | DATA_DIR = join(ROOT_DIR, 'data') 11 | DAY1_DIR = join(ROOT_DIR, 'day1') 12 | DAY2_DIR = join(ROOT_DIR, 'day2') 13 | ZOO_DIR = join(ROOT_DIR, 'modelzoo') 14 | 15 | GLOVE_FILENAME = join(DATA_DIR, 'glove.6B.100d.txt') 16 | 17 | FIRSTNAMES_CSV = join(DATA_DIR, 'firstnames.csv') 18 | 19 | SURNAMES_CSV = join(DATA_DIR, 'surnames.csv') 20 | 21 | TRUMP_FILENAME = join(DATA_DIR, 'trump.csv') 22 | 23 | AMAZON_FILENAME = join(DATA_DIR, 'amazon_train_small.csv') 24 | 25 | SNLI_TRAIN_JSON = join(DATA_DIR, 'snli_1.0', 'snli_1.0_train.jsonl') 26 | SNLI_DEV_JSON = join(DATA_DIR, 'snli_1.0', 'snli_1.0_dev.jsonl') 27 | SNLI_TEST_JSON = join(DATA_DIR, 'snli_1.0', 'snli_1.0_test.jsonl') 28 | 29 | ZHNEWS_CSV = join(DATA_DIR, 'zhnews.csv') 30 | 31 | START_TOKEN = "^" 32 | END_TOKEN= "_" 33 | 34 | # used by pytorch backends to ignore non-classes in loss compuations 35 | # best for sequences where not all things that go into the loss computation 36 | # should be included in the loss 37 | IGNORE_INDEX_VALUE = -1 38 | 39 | class ZOO: 40 | charnn_surname_classifer = { 41 | 'filename': join(ZOO_DIR, 42 | 'charnn_emb16_hid64_surnames_classify.state'), 43 | 'vocab': join(ZOO_DIR, 'surnames_classify.vocab'), 44 | 'comments': 'pre-trained surname classifier', 45 | 'date': '09-14-2017', 46 | 'parameters': { 47 | 'embedding_size': 16, 48 | 'hidden_size': 64 49 | } 50 | } 51 | charnn_surname_predicter = { 52 | 'filename': join(ZOO_DIR, 53 | 'charnn_emb16_hid64_surnames_predict.state'), 54 | 'vocab': join(ZOO_DIR, 'surnames_classify.vocab'), 55 | 'comments': 'pre-trained surname sequence prediction (& generation model)', 56 | 'date': '09-14-2017', 57 | 'parameters': { 58 | 'embedding_size': 16, 59 | 'hidden_size': 64 60 | } 61 | } 62 | charnn_surname_conditioned_predicter = { 63 | 'filename': join(ZOO_DIR, 64 | 'charnn_emb16_hid64_surnames_conditionally_predict.state'), 65 | 'vocab': join(ZOO_DIR, 'surnames_classify.vocab'), 66 | 'comments': 'pre-trained surname conditioned sequence prediction (& conditioned generation)', 67 | 'date': '09-14-2017', 68 | 'parameters': { 69 | 'embedding_size': 16, 70 | 'hidden_size': 64 71 | } 72 | } 73 | wordrnn_trump_tweet_predicter = { 74 | 'filename': join(ZOO_DIR, 75 | 'wordrnn_emb100_hid64_trump_tweets_predict.state'), 76 | 'vocab': join(ZOO_DIR, 'trump_twitter.vocab'), 77 | 'comments': 'pre-trained trump sequence prediction (& generation)', 78 | 'date': '09-14-2017', 79 | 'parameters': { 80 | 'embedding_size': 100, 81 | 'hidden_size': 64 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/index.rst.txt: -------------------------------------------------------------------------------- 1 | .. pytorch-nlp-tutorial-sf2017 documentation master file, created by 2 | sphinx-quickstart on Sun Sep 3 13:31:44 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Natural Language Processing (NLP) with PyTorch 7 | ============================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :hidden: 12 | :caption: Extra Resources 13 | 14 | download_data 15 | environment_setup 16 | faq 17 | 18 | .. toctree:: 19 | :hidden: 20 | :caption: Day 1 Materials 21 | 22 | Take Home Exercises 23 | 24 | .. toctree:: 25 | :hidden: 26 | :maxdepth: 3 27 | :caption: Day 2 Materials 28 | 29 | Warm-Up Exercise 30 | Choose Your Own Adventure 31 | Neural Network Patterns 32 | 33 | 34 | Hello! This is a directory of resources for a training tutorial to be 35 | given at the O'Reilly AI Conference in San Francisco on September 17 and 18, 2017. 36 | 37 | Please read below for general information. You can find the github repository at `this link `_. Please note that there are two ways to engage in this training (desribed below). 38 | 39 | More information will be added to this site as the training progresses. 40 | Specifically, we will be adding a 'recipes' section, 'errata' section, and a 'bonus exercise' section as the training progresses! 41 | 42 | General Information 43 | ------------------- 44 | 45 | Prerequisites: 46 | ^^^^^^^^^^^^^ 47 | 48 | - A working knowledge of Python and the command line 49 | - Familiarity with precalc math (multiply matrices, dot products of vectors, etc.) and derivatives of simple functions (If you are new to linear algebra, this video course is handy.) 50 | - A general understanding of machine learning (setting up experiments, evaluation, etc.) (useful but not required) 51 | 52 | Hardware and/or installation requirements: 53 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 54 | 55 | - There are two options: 56 | 1. **Using O'Reilly's online resources**. For this, you only needs a laptop; on the first day, we will provide you with credentials and a URL to use an online computing resource (a JupyterHub instance) provided by O'Reilly. You will be able to access Jupyter notebooks through this and they will persist until the end of the second day of training (September 18th). This option is not limited by what operating system you have. You will need to have a browser installed. 57 | 2. **Setting everything up locally**. For this, you need a laptop with the PyTorch environment set up. This is only recommended if you want to have the environment locally or have a laptop with a GPU. (If you have trouble following the provided instructions or if you find any mistakes, please file an issue `here `_.) This option is limited to Macs and Linux users only (sorry Windows users!). Be sure you check the `LOCAL_RUN_README.md `_. 58 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | .. pytorch-nlp-tutorial-sf2017 documentation master file, created by 2 | sphinx-quickstart on Sun Sep 3 13:31:44 2017. 3 | You can adapt this file completely to your liking, but it should at least 4 | contain the root `toctree` directive. 5 | 6 | Natural Language Processing (NLP) with PyTorch 7 | ============================================== 8 | 9 | .. toctree:: 10 | :maxdepth: 2 11 | :hidden: 12 | :caption: Extra Resources 13 | 14 | download_data 15 | environment_setup 16 | faq 17 | Recipes 18 | 19 | .. toctree:: 20 | :hidden: 21 | :caption: Day 1 Materials 22 | 23 | Take Home Exercises 24 | 25 | .. toctree:: 26 | :hidden: 27 | :maxdepth: 3 28 | :caption: Day 2 Materials 29 | 30 | Warm-Up Exercise 31 | Choose Your Own Adventure 32 | Neural Network Patterns 33 | 34 | 35 | Hello! This is a directory of resources for a training tutorial to be 36 | given at the O'Reilly AI Conference in San Francisco on September 17 and 18, 2017. 37 | 38 | Please read below for general information. You can find the github repository at `this link `_. Please note that there are two ways to engage in this training (desribed below). 39 | 40 | More information will be added to this site as the training progresses. 41 | Specifically, we will be adding a 'recipes' section, 'errata' section, and a 'bonus exercise' section as the training progresses! 42 | 43 | General Information 44 | ------------------- 45 | 46 | Prerequisites: 47 | ^^^^^^^^^^^^^ 48 | 49 | - A working knowledge of Python and the command line 50 | - Familiarity with precalc math (multiply matrices, dot products of vectors, etc.) and derivatives of simple functions (If you are new to linear algebra, this video course is handy.) 51 | - A general understanding of machine learning (setting up experiments, evaluation, etc.) (useful but not required) 52 | 53 | Hardware and/or installation requirements: 54 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 55 | 56 | - There are two options: 57 | 1. **Using O'Reilly's online resources**. For this, you only needs a laptop; on the first day, we will provide you with credentials and a URL to use an online computing resource (a JupyterHub instance) provided by O'Reilly. You will be able to access Jupyter notebooks through this and they will persist until the end of the second day of training (September 18th). This option is not limited by what operating system you have. You will need to have a browser installed. 58 | 2. **Setting everything up locally**. For this, you need a laptop with the PyTorch environment set up. This is only recommended if you want to have the environment locally or have a laptop with a GPU. (If you have trouble following the provided instructions or if you find any mistakes, please file an issue `here `_.) This option is limited to Macs and Linux users only (sorry Windows users!). Be sure you check the `LOCAL_RUN_README.md `_. 59 | -------------------------------------------------------------------------------- /docs/_build/html/_static/css/badge_only.css: -------------------------------------------------------------------------------- 1 | .fa:before{-webkit-font-smoothing:antialiased}.clearfix{*zoom:1}.clearfix:before,.clearfix:after{display:table;content:""}.clearfix:after{clear:both}@font-face{font-family:FontAwesome;font-weight:normal;font-style:normal;src:url("../font/fontawesome_webfont.eot");src:url("../font/fontawesome_webfont.eot?#iefix") format("embedded-opentype"),url("../font/fontawesome_webfont.woff") format("woff"),url("../font/fontawesome_webfont.ttf") format("truetype"),url("../font/fontawesome_webfont.svg#FontAwesome") format("svg")}.fa:before{display:inline-block;font-family:FontAwesome;font-style:normal;font-weight:normal;line-height:1;text-decoration:inherit}a .fa{display:inline-block;text-decoration:inherit}li .fa{display:inline-block}li .fa-large:before,li .fa-large:before{width:1.875em}ul.fas{list-style-type:none;margin-left:2em;text-indent:-0.8em}ul.fas li .fa{width:0.8em}ul.fas li .fa-large:before,ul.fas li .fa-large:before{vertical-align:baseline}.fa-book:before{content:""}.icon-book:before{content:""}.fa-caret-down:before{content:""}.icon-caret-down:before{content:""}.fa-caret-up:before{content:""}.icon-caret-up:before{content:""}.fa-caret-left:before{content:""}.icon-caret-left:before{content:""}.fa-caret-right:before{content:""}.icon-caret-right:before{content:""}.rst-versions{position:fixed;bottom:0;left:0;width:300px;color:#fcfcfc;background:#1f1d1d;border-top:solid 10px #343131;font-family:"Lato","proxima-nova","Helvetica Neue",Arial,sans-serif;z-index:400}.rst-versions a{color:#2980B9;text-decoration:none}.rst-versions .rst-badge-small{display:none}.rst-versions .rst-current-version{padding:12px;background-color:#272525;display:block;text-align:right;font-size:90%;cursor:pointer;color:#27AE60;*zoom:1}.rst-versions .rst-current-version:before,.rst-versions .rst-current-version:after{display:table;content:""}.rst-versions .rst-current-version:after{clear:both}.rst-versions .rst-current-version .fa{color:#fcfcfc}.rst-versions .rst-current-version .fa-book{float:left}.rst-versions .rst-current-version .icon-book{float:left}.rst-versions .rst-current-version.rst-out-of-date{background-color:#E74C3C;color:#fff}.rst-versions .rst-current-version.rst-active-old-version{background-color:#F1C40F;color:#000}.rst-versions.shift-up .rst-other-versions{display:block}.rst-versions .rst-other-versions{font-size:90%;padding:12px;color:gray;display:none}.rst-versions .rst-other-versions hr{display:block;height:1px;border:0;margin:20px 0;padding:0;border-top:solid 1px #413d3d}.rst-versions .rst-other-versions dd{display:inline-block;margin:0}.rst-versions .rst-other-versions dd a{display:inline-block;padding:6px;color:#fcfcfc}.rst-versions.rst-badge{width:auto;bottom:20px;right:20px;left:auto;border:none;max-width:300px}.rst-versions.rst-badge .icon-book{float:none}.rst-versions.rst-badge .fa-book{float:none}.rst-versions.rst-badge.shift-up .rst-current-version{text-align:right}.rst-versions.rst-badge.shift-up .rst-current-version .fa-book{float:left}.rst-versions.rst-badge.shift-up .rst-current-version .icon-book{float:left}.rst-versions.rst-badge .rst-current-version{width:auto;height:30px;line-height:30px;padding:0 6px;display:block;text-align:center}@media screen and (max-width: 768px){.rst-versions{width:85%;display:none}.rst-versions.shift{display:block}} 2 | /*# sourceMappingURL=badge_only.css.map */ 3 | -------------------------------------------------------------------------------- /docs/_build/html/_static/pygments.css: -------------------------------------------------------------------------------- 1 | .highlight .hll { background-color: #ffffcc } 2 | .highlight { background: #eeffcc; } 3 | .highlight .c { color: #408090; font-style: italic } /* Comment */ 4 | .highlight .err { border: 1px solid #FF0000 } /* Error */ 5 | .highlight .k { color: #007020; font-weight: bold } /* Keyword */ 6 | .highlight .o { color: #666666 } /* Operator */ 7 | .highlight .ch { color: #408090; font-style: italic } /* Comment.Hashbang */ 8 | .highlight .cm { color: #408090; font-style: italic } /* Comment.Multiline */ 9 | .highlight .cp { color: #007020 } /* Comment.Preproc */ 10 | .highlight .cpf { color: #408090; font-style: italic } /* Comment.PreprocFile */ 11 | .highlight .c1 { color: #408090; font-style: italic } /* Comment.Single */ 12 | .highlight .cs { color: #408090; background-color: #fff0f0 } /* Comment.Special */ 13 | .highlight .gd { color: #A00000 } /* Generic.Deleted */ 14 | .highlight .ge { font-style: italic } /* Generic.Emph */ 15 | .highlight .gr { color: #FF0000 } /* Generic.Error */ 16 | .highlight .gh { color: #000080; font-weight: bold } /* Generic.Heading */ 17 | .highlight .gi { color: #00A000 } /* Generic.Inserted */ 18 | .highlight .go { color: #333333 } /* Generic.Output */ 19 | .highlight .gp { color: #c65d09; font-weight: bold } /* Generic.Prompt */ 20 | .highlight .gs { font-weight: bold } /* Generic.Strong */ 21 | .highlight .gu { color: #800080; font-weight: bold } /* Generic.Subheading */ 22 | .highlight .gt { color: #0044DD } /* Generic.Traceback */ 23 | .highlight .kc { color: #007020; font-weight: bold } /* Keyword.Constant */ 24 | .highlight .kd { color: #007020; font-weight: bold } /* Keyword.Declaration */ 25 | .highlight .kn { color: #007020; font-weight: bold } /* Keyword.Namespace */ 26 | .highlight .kp { color: #007020 } /* Keyword.Pseudo */ 27 | .highlight .kr { color: #007020; font-weight: bold } /* Keyword.Reserved */ 28 | .highlight .kt { color: #902000 } /* Keyword.Type */ 29 | .highlight .m { color: #208050 } /* Literal.Number */ 30 | .highlight .s { color: #4070a0 } /* Literal.String */ 31 | .highlight .na { color: #4070a0 } /* Name.Attribute */ 32 | .highlight .nb { color: #007020 } /* Name.Builtin */ 33 | .highlight .nc { color: #0e84b5; font-weight: bold } /* Name.Class */ 34 | .highlight .no { color: #60add5 } /* Name.Constant */ 35 | .highlight .nd { color: #555555; font-weight: bold } /* Name.Decorator */ 36 | .highlight .ni { color: #d55537; font-weight: bold } /* Name.Entity */ 37 | .highlight .ne { color: #007020 } /* Name.Exception */ 38 | .highlight .nf { color: #06287e } /* Name.Function */ 39 | .highlight .nl { color: #002070; font-weight: bold } /* Name.Label */ 40 | .highlight .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */ 41 | .highlight .nt { color: #062873; font-weight: bold } /* Name.Tag */ 42 | .highlight .nv { color: #bb60d5 } /* Name.Variable */ 43 | .highlight .ow { color: #007020; font-weight: bold } /* Operator.Word */ 44 | .highlight .w { color: #bbbbbb } /* Text.Whitespace */ 45 | .highlight .mb { color: #208050 } /* Literal.Number.Bin */ 46 | .highlight .mf { color: #208050 } /* Literal.Number.Float */ 47 | .highlight .mh { color: #208050 } /* Literal.Number.Hex */ 48 | .highlight .mi { color: #208050 } /* Literal.Number.Integer */ 49 | .highlight .mo { color: #208050 } /* Literal.Number.Oct */ 50 | .highlight .sb { color: #4070a0 } /* Literal.String.Backtick */ 51 | .highlight .sc { color: #4070a0 } /* Literal.String.Char */ 52 | .highlight .sd { color: #4070a0; font-style: italic } /* Literal.String.Doc */ 53 | .highlight .s2 { color: #4070a0 } /* Literal.String.Double */ 54 | .highlight .se { color: #4070a0; font-weight: bold } /* Literal.String.Escape */ 55 | .highlight .sh { color: #4070a0 } /* Literal.String.Heredoc */ 56 | .highlight .si { color: #70a0d0; font-style: italic } /* Literal.String.Interpol */ 57 | .highlight .sx { color: #c65d09 } /* Literal.String.Other */ 58 | .highlight .sr { color: #235388 } /* Literal.String.Regex */ 59 | .highlight .s1 { color: #4070a0 } /* Literal.String.Single */ 60 | .highlight .ss { color: #517918 } /* Literal.String.Symbol */ 61 | .highlight .bp { color: #007020 } /* Name.Builtin.Pseudo */ 62 | .highlight .vc { color: #bb60d5 } /* Name.Variable.Class */ 63 | .highlight .vg { color: #bb60d5 } /* Name.Variable.Global */ 64 | .highlight .vi { color: #bb60d5 } /* Name.Variable.Instance */ 65 | .highlight .il { color: #208050 } /* Literal.Number.Integer.Long */ -------------------------------------------------------------------------------- /docs/environment_setup.rst: -------------------------------------------------------------------------------- 1 | Environment Setup 2 | ================= 3 | 4 | On this page, you will find not only the list of dependencies to install 5 | for the tutorial, but a description of how to install them. This tutorial assumes 6 | you have a laptop with OSX or Linux. If you use Windows, you might have to install 7 | a virtual machine to get a UNIX-like environment to continue with the rest of this 8 | instruction. A lot of this instruction is more verbose than needed to accomodate 9 | participants of different skill levels. 10 | 11 | **Please note that these are only optional. On the first day of this training, you will be provided with a link to a JupyterHub instance where the environment will be pre-made and ready to go!** 12 | 13 | 0. Get Anaconda 14 | --------------- 15 | 16 | Anaconda is a Python (and R) distribution that aims to provide everything 17 | needed for common scientific and machine learning situations out-of-the-box. 18 | We chose Anaconda for this tutorial as it significantly simplifies Python 19 | dependency management. 20 | 21 | In practice, Anaconda can be used to manage different environment and packages. 22 | This setup document will assume that you have Anaconda installed as your default 23 | Python distribution. 24 | 25 | You can download Anaconda here: https://www.continuum.io/downloads 26 | 27 | After installing Anaconda, you can access its command-line interface 28 | with the :code:`conda` command. 29 | 30 | 31 | 1. Create a new environment 32 | --------------------------- 33 | 34 | Environments are a tool for sanitary software development. By this, we mean that 35 | you can install specific versions of packages without worrying that it breaks 36 | a dependency elsewhere. 37 | 38 | Here is how you can create an environment with Anaconda 39 | 40 | .. code-block:: bash 41 | 42 | conda create -n dl4nlp python=3.6 43 | 44 | 45 | 2. Install Dependencies 46 | ----------------------- 47 | 48 | 2a. Activate the environment 49 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 50 | 51 | After creating the environment, you need to **activate** the environment: 52 | 53 | .. code-block:: bash 54 | 55 | source activate dl4nlp 56 | 57 | After an environment is activated, it might prepend/append itself to your 58 | console prompt to let you know it is active. 59 | 60 | With the environment activated, any installation commands 61 | (whether it is :code:`pip install X`, :code:`python setup.py install` or using 62 | Anaconda's install command :code:`conda install X`) will only install inside 63 | the environment. 64 | 65 | 2b. Install IPython and Jupyter 66 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 67 | 68 | Two core dependencies are IPython and Jupyter. Let's install them first: 69 | 70 | .. code-block:: bash 71 | 72 | conda install ipython 73 | conda install jupyter 74 | 75 | To allow a jupyter notebooks to use this environment as their kernel, it 76 | needs to be linked: 77 | 78 | .. code-block:: bash 79 | 80 | python -m ipykernel install --user --name dl4nlp 81 | 82 | 2c. Installing CUDA (optional) 83 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 84 | 85 | NOTE: CUDA is currently not supported out of the conda package control manager. 86 | Please refer to pytorch's github repository for compilation instructions. 87 | 88 | If you have a CUDA compatible GPU, it is worthwhile to take advantage of it as 89 | it can significantly speedup training and make your PyTorch experimentation more 90 | enjoyable. 91 | 92 | To install CUDA: 93 | 94 | 1. Download CUDA appropriate to your OS/Arch from `here `_. 95 | 2. Follow installation steps for your architecture/OS. For Ubuntu/x86_64, see `here `_. 96 | 3. Download and install CUDNN from `here `_. 97 | 98 | Make sure you have the latest CUDA (8.0) and CUDNN (7.0). 99 | 100 | 2d. Install PyTorch 101 | ^^^^^^^^^^^^^^^^^^^ 102 | 103 | There are instructions on http://pytorch.org which detail how to install it. 104 | If you have been following along so far and have Anaconda installed with CUDA enabled, you can simply do: 105 | 106 | 107 | .. code-block:: bash 108 | 109 | conda install pytorch torchvision cuda80 -c soumith 110 | 111 | The widget on PyTorch.org will let you select the right command line for your specific OS/Arch. 112 | Make sure you have PyTorch 2.0 or higher. 113 | 114 | 2e. Clone (or Download) Repository 115 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 116 | 117 | At this point, you may have already cloned the tutorial repository. But if 118 | you have not, you will need it for the next step. 119 | 120 | .. code-block:: bash 121 | 122 | git clone https://github.com/joosthub/pytorch-nlp-tutorial-sf2017.git 123 | 124 | If you do not have git or do not want to use it, you can also 125 | `download the repository as a zip file `_ 126 | 127 | 2f. Install Dependencies from Repository 128 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 129 | 130 | Assuming the you have cloned (or downloaded and unzipped) the repository, 131 | please navigate to the directory in your terminal. Then, you can do the following: 132 | 133 | .. code-block:: bash 134 | 135 | pip install -r requirements.txt 136 | -------------------------------------------------------------------------------- /docs/_build/html/_sources/environment_setup.rst.txt: -------------------------------------------------------------------------------- 1 | Environment Setup 2 | ================= 3 | 4 | On this page, you will find not only the list of dependencies to install 5 | for the tutorial, but a description of how to install them. This tutorial assumes 6 | you have a laptop with OSX or Linux. If you use Windows, you might have to install 7 | a virtual machine to get a UNIX-like environment to continue with the rest of this 8 | instruction. A lot of this instruction is more verbose than needed to accomodate 9 | participants of different skill levels. 10 | 11 | **Please note that these are only optional. On the first day of this training, you will be provided with a link to a JupyterHub instance where the environment will be pre-made and ready to go!** 12 | 13 | 0. Get Anaconda 14 | --------------- 15 | 16 | Anaconda is a Python (and R) distribution that aims to provide everything 17 | needed for common scientific and machine learning situations out-of-the-box. 18 | We chose Anaconda for this tutorial as it significantly simplifies Python 19 | dependency management. 20 | 21 | In practice, Anaconda can be used to manage different environment and packages. 22 | This setup document will assume that you have Anaconda installed as your default 23 | Python distribution. 24 | 25 | You can download Anaconda here: https://www.continuum.io/downloads 26 | 27 | After installing Anaconda, you can access its command-line interface 28 | with the :code:`conda` command. 29 | 30 | 31 | 1. Create a new environment 32 | --------------------------- 33 | 34 | Environments are a tool for sanitary software development. By this, we mean that 35 | you can install specific versions of packages without worrying that it breaks 36 | a dependency elsewhere. 37 | 38 | Here is how you can create an environment with Anaconda 39 | 40 | .. code-block:: bash 41 | 42 | conda create -n dl4nlp python=3.6 43 | 44 | 45 | 2. Install Dependencies 46 | ----------------------- 47 | 48 | 2a. Activate the environment 49 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 50 | 51 | After creating the environment, you need to **activate** the environment: 52 | 53 | .. code-block:: bash 54 | 55 | source activate dl4nlp 56 | 57 | After an environment is activated, it might prepend/append itself to your 58 | console prompt to let you know it is active. 59 | 60 | With the environment activated, any installation commands 61 | (whether it is :code:`pip install X`, :code:`python setup.py install` or using 62 | Anaconda's install command :code:`conda install X`) will only install inside 63 | the environment. 64 | 65 | 2b. Install IPython and Jupyter 66 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 67 | 68 | Two core dependencies are IPython and Jupyter. Let's install them first: 69 | 70 | .. code-block:: bash 71 | 72 | conda install ipython 73 | conda install jupyter 74 | 75 | To allow a jupyter notebooks to use this environment as their kernel, it 76 | needs to be linked: 77 | 78 | .. code-block:: bash 79 | 80 | python -m ipykernel install --user --name dl4nlp 81 | 82 | 2c. Installing CUDA (optional) 83 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 84 | 85 | NOTE: CUDA is currently not supported out of the conda package control manager. 86 | Please refer to pytorch's github repository for compilation instructions. 87 | 88 | If you have a CUDA compatible GPU, it is worthwhile to take advantage of it as 89 | it can significantly speedup training and make your PyTorch experimentation more 90 | enjoyable. 91 | 92 | To install CUDA: 93 | 94 | 1. Download CUDA appropriate to your OS/Arch from `here `_. 95 | 2. Follow installation steps for your architecture/OS. For Ubuntu/x86_64, see `here `_. 96 | 3. Download and install CUDNN from `here `_. 97 | 98 | Make sure you have the latest CUDA (8.0) and CUDNN (7.0). 99 | 100 | 2d. Install PyTorch 101 | ^^^^^^^^^^^^^^^^^^^ 102 | 103 | There are instructions on http://pytorch.org which detail how to install it. 104 | If you have been following along so far and have Anaconda installed with CUDA enabled, you can simply do: 105 | 106 | 107 | .. code-block:: bash 108 | 109 | conda install pytorch torchvision cuda80 -c soumith 110 | 111 | The widget on PyTorch.org will let you select the right command line for your specific OS/Arch. 112 | Make sure you have PyTorch 2.0 or higher. 113 | 114 | 2e. Clone (or Download) Repository 115 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 116 | 117 | At this point, you may have already cloned the tutorial repository. But if 118 | you have not, you will need it for the next step. 119 | 120 | .. code-block:: bash 121 | 122 | git clone https://github.com/joosthub/pytorch-nlp-tutorial-sf2017.git 123 | 124 | If you do not have git or do not want to use it, you can also 125 | `download the repository as a zip file `_ 126 | 127 | 2f. Install Dependencies from Repository 128 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 129 | 130 | Assuming the you have cloned (or downloaded and unzipped) the repository, 131 | please navigate to the directory in your terminal. Then, you can do the following: 132 | 133 | .. code-block:: bash 134 | 135 | pip install -r requirements.txt 136 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # -*- coding: utf-8 -*- 3 | # 4 | # pytorch-nlp-tutorial-sf2017 documentation build configuration file, created by 5 | # sphinx-quickstart on Sun Sep 3 13:31:44 2017. 6 | # 7 | # This file is execfile()d with the current directory set to its 8 | # containing dir. 9 | # 10 | # Note that not all possible configuration values are present in this 11 | # autogenerated file. 12 | # 13 | # All configuration values have a default; values that are commented out 14 | # serve to show the default. 15 | 16 | # If extensions (or modules to document with autodoc) are in another directory, 17 | # add these directories to sys.path here. If the directory is relative to the 18 | # documentation root, use os.path.abspath to make it absolute, like shown here. 19 | # 20 | # import os 21 | # import sys 22 | # sys.path.insert(0, os.path.abspath('.')) 23 | 24 | 25 | # -- General configuration ------------------------------------------------ 26 | 27 | # If your documentation needs a minimal Sphinx version, state it here. 28 | # 29 | # needs_sphinx = '1.0' 30 | 31 | # Add any Sphinx extension module names here, as strings. They can be 32 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom 33 | # ones. 34 | extensions = ['sphinx.ext.mathjax'] 35 | 36 | # Add any paths that contain templates here, relative to this directory. 37 | templates_path = ['_templates'] 38 | 39 | # The suffix(es) of source filenames. 40 | # You can specify multiple suffix as a list of string: 41 | # 42 | # source_suffix = ['.rst', '.md'] 43 | source_suffix = '.rst' 44 | 45 | # The master toctree document. 46 | master_doc = 'index' 47 | 48 | # General information about the project. 49 | project = 'NLP with PyTorch' 50 | copyright = '2017, Brian McMahan and Delip Rao' 51 | author = 'Brian McMahan and Delip Rao' 52 | 53 | # The version info for the project you're documenting, acts as replacement for 54 | # |version| and |release|, also used in various other places throughout the 55 | # built documents. 56 | # 57 | # The short X.Y version. 58 | version = '' 59 | # The full version, including alpha/beta/rc tags. 60 | release = '' 61 | 62 | # The language for content autogenerated by Sphinx. Refer to documentation 63 | # for a list of supported languages. 64 | # 65 | # This is also used if you do content translation via gettext catalogs. 66 | # Usually you set "language" from the command line for these cases. 67 | language = None 68 | 69 | # List of patterns, relative to source directory, that match files and 70 | # directories to ignore when looking for source files. 71 | # This patterns also effect to html_static_path and html_extra_path 72 | exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store'] 73 | 74 | # The name of the Pygments (syntax highlighting) style to use. 75 | pygments_style = 'sphinx' 76 | 77 | # If true, `todo` and `todoList` produce output, else they produce nothing. 78 | todo_include_todos = False 79 | 80 | 81 | # -- Options for HTML output ---------------------------------------------- 82 | 83 | # The theme to use for HTML and HTML Help pages. See the documentation for 84 | # a list of builtin themes. 85 | # 86 | html_theme = 'sphinx_rtd_theme' 87 | 88 | # Theme options are theme-specific and customize the look and feel of a theme 89 | # further. For a list of options available for each theme, see the 90 | # documentation. 91 | # 92 | # html_theme_options = {} 93 | 94 | # Add any paths that contain custom static files (such as style sheets) here, 95 | # relative to this directory. They are copied after the builtin static files, 96 | # so a file named "default.css" will overwrite the builtin "default.css". 97 | html_static_path = ['_static'] 98 | 99 | 100 | # -- Options for HTMLHelp output ------------------------------------------ 101 | 102 | # Output file base name for HTML help builder. 103 | htmlhelp_basename = 'pytorch-nlp-tutorial-sf2017doc' 104 | 105 | 106 | # -- Options for LaTeX output --------------------------------------------- 107 | 108 | latex_elements = { 109 | # The paper size ('letterpaper' or 'a4paper'). 110 | # 111 | # 'papersize': 'letterpaper', 112 | 113 | # The font size ('10pt', '11pt' or '12pt'). 114 | # 115 | # 'pointsize': '10pt', 116 | 117 | # Additional stuff for the LaTeX preamble. 118 | # 119 | # 'preamble': '', 120 | 121 | # Latex figure (float) alignment 122 | # 123 | # 'figure_align': 'htbp', 124 | } 125 | 126 | # Grouping the document tree into LaTeX files. List of tuples 127 | # (source start file, target name, title, 128 | # author, documentclass [howto, manual, or own class]). 129 | latex_documents = [ 130 | (master_doc, 'pytorch-nlp-tutorial-sf2017.tex', 'pytorch-nlp-tutorial-sf2017 Documentation', 131 | 'Brian McMahan and Delip Rao', 'manual'), 132 | ] 133 | 134 | 135 | # -- Options for manual page output --------------------------------------- 136 | 137 | # One entry per manual page. List of tuples 138 | # (source start file, name, description, authors, manual section). 139 | man_pages = [ 140 | (master_doc, 'pytorch-nlp-tutorial-sf2017', 'pytorch-nlp-tutorial-sf2017 Documentation', 141 | [author], 1) 142 | ] 143 | 144 | 145 | # -- Options for Texinfo output ------------------------------------------- 146 | 147 | # Grouping the document tree into Texinfo files. List of tuples 148 | # (source start file, target name, title, author, 149 | # dir menu entry, description, category) 150 | texinfo_documents = [ 151 | (master_doc, 'pytorch-nlp-tutorial-sf2017', 'pytorch-nlp-tutorial-sf2017 Documentation', 152 | author, 'pytorch-nlp-tutorial-sf2017', 'One line description of project.', 153 | 'Miscellaneous'), 154 | ] 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /docs/_build/html/genindex.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Index — NLP with PyTorch documentation 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 110 | 111 |
112 | 113 | 114 | 120 | 121 | 122 | 123 |
124 |
125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |
142 | 143 |
    144 | 145 |
  • Docs »
  • 146 | 147 |
  • Index
  • 148 | 149 | 150 |
  • 151 | 152 | 153 | 154 |
  • 155 | 156 |
157 | 158 | 159 |
160 |
161 |
162 |
163 | 164 | 165 |

Index

166 | 167 |
168 | 169 |
170 | 171 | 172 |
173 |
174 | 175 |
176 |
177 |
178 | 179 | 180 |
181 | 182 |
183 |

184 | © Copyright 2017, Brian McMahan and Delip Rao. 185 | 186 |

187 |
188 | Built with Sphinx using a theme provided by Read the Docs. 189 | 190 |
191 | 192 |
193 |
194 | 195 |
196 | 197 |
198 | 199 | 200 | 201 | 202 | 203 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 232 | 233 | 234 | 235 | -------------------------------------------------------------------------------- /docs/_build/html/search.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Search — NLP with PyTorch documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 |
49 | 50 | 51 | 109 | 110 |
111 | 112 | 113 | 119 | 120 | 121 | 122 |
123 |
124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 |
141 | 142 |
    143 | 144 |
  • Docs »
  • 145 | 146 |
  • Search
  • 147 | 148 | 149 |
  • 150 | 151 |
  • 152 | 153 |
154 | 155 | 156 |
157 |
158 |
159 |
160 | 161 | 169 | 170 | 171 |
172 | 173 |
174 | 175 |
176 |
177 | 178 |
179 |
180 |
181 | 182 | 183 |
184 | 185 |
186 |

187 | © Copyright 2017, Brian McMahan and Delip Rao. 188 | 189 |

190 |
191 | Built with Sphinx using a theme provided by Read the Docs. 192 | 193 |
194 | 195 |
196 |
197 | 198 |
199 | 200 |
201 | 202 | 203 | 204 | 205 | 206 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 236 | 237 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | -------------------------------------------------------------------------------- /docs/_build/html/searchindex.js: -------------------------------------------------------------------------------- 1 | Search.setIndex({docnames:["day2/patterns/attention","day2/patterns/gating","day2/patterns/index","day2/warmup","index","recipes/compute_conv_size","recipes/index","recipes/load_pretrained_vectors","recipes/packed_sequences"],envversion:51,filenames:["day2/patterns/attention.rst","day2/patterns/gating.rst","day2/patterns/index.rst","day2/warmup.rst","index.rst","recipes/compute_conv_size.rst","recipes/index.rst","recipes/load_pretrained_vectors.rst","recipes/packed_sequences.rst"],objects:{},objnames:{},objtypes:{},terms:{"18th":4,"1st":3,"2015_acl_dan":[],"break":[],"case":0,"class":0,"default":[],"final":7,"function":[0,4,7],"import":5,"long":3,"new":[3,4],"return":[0,5],"super":0,"try":[],"while":[],And:[],But:[],For:4,One:[],The:0,Then:[],There:4,Use:3,Using:[0,4],With:[],__init__:0,abl:4,access:4,accomod:[],across:[0,3],added:4,adding:4,addition:0,advantag:7,adventur:[],affect:[],after:0,aim:[],algebra:4,allow:[],along:[],alreadi:[],also:[],amongst:0,analog:0,ani:[0,4],annoi:[],anticip:[],anyth:[],append:[],appli:[],appropri:[],approxim:[],arch:[],architectur:[],argument:3,arriv:[],assert:[],assum:[],attent:2,attention_s:0,attention_scor:0,attribut:0,avail:[],averag:[0,3],awesom:[],back:3,bag:[],batch:0,becaus:[],been:0,befor:[0,3],being:[],below:[0,4],better:[],between:[],bonu:4,box:[],bring:[],browser:4,can:[0,3,4,7],cbow:0,cell:0,challeng:[],chang:[],charact:[],check:4,choos:[],chose:[],classif:[],classifi:[],code:[],collect:0,column_gath:[],com:[],combin:[],command:4,common:[],compat:[],compil:[],complet:[],comput:[0,4,6],conda:[],condensed_x:0,condit:[],conditional_emb:[],confer:4,confus:[],connect:[],consol:[],continu:[],continuum:[],control:[],conv:[],conv_shape_helper_1d:5,convert:7,convnet:[],convolut:6,cool:[],core:[],correct:[],could:0,cours:4,creat:3,credenti:4,cuda80:[],cuda:7,cudnn:[],current:[],dai:[0,4,7],data:7,datapoint:[],date:[],decod:[],decode_matrix:[],deep:[],def:[0,5],deriv:4,descript:[],desrib:4,detail:[],develop:[],diff:0,differ:0,dilat:5,dim1:0,dim:[0,3],dimens:3,directori:4,distribut:0,dl4nlp:[],document:[],doe:[],doesn:[],doing:6,dot:4,drive:[],each:0,easi:3,edu:[],either:[],els:[],elsewher:[],emb:[0,7],emb_index:7,embed:[0,7],enabl:[],encod:[],end:4,engag:4,enjoy:[],environ:4,errata:4,etc:4,evalu:4,everyth:4,exactli:[],exampl:[0,7],exercis:4,expect:0,experi:4,experiment:[],extrem:7,familiar:4,fanci:[],far:3,fast:[],faster:[],featur:0,file:4,find:[4,6],finish:[],first:4,flash:[],floattensor:[0,7],floor:5,follow:4,form:0,forward:0,francisco:4,from:3,fulli:[],fun:[],futur:[],gate:2,gener:[],generaliz:[],get:[0,3,7],get_penultim:[],git:[],github:4,give:7,given:4,glove:7,glove_index:7,glove_vec:7,good:[],gpu:4,groov:3,h_i:1,h_n:1,h_r:1,had:7,handi:4,has:0,have:[0,3,4],hello:4,here:4,hidden:1,higher:[],home:[],hone:[],how:3,http:[],i_i:1,i_n:1,i_r:1,identifi:[],implement:[],importantli:0,index:[3,7],induc:[],init:0,init_vector1:[],init_vector2:[],init_vector:[],initi:[],input:[],input_seq_len:5,inputg:1,insid:[],instanc:4,instead:0,instruct:4,intend:[],interest:[],interfac:[],interpol:0,interpolate_n_samples_from_two_nation:[],invest:[],ipykernel:[],issu:4,item:7,iter:7,its:[],itself:7,joosthub:[],jupyt:4,jupyterhub:4,just:0,kei:[],kernel:[],kernel_s:5,kernel_width:5,kind:[],know:[],knowledg:4,label:[],languag:[],laptop:4,last:3,later:[],latest:[],layer:7,learn:[0,4],length:[],let:3,level:[],librari:[],like:[],limit:4,line:4,linear:4,link:4,linux:4,list:[],load:6,load_word_vector:7,local:4,local_run_readm:4,long_vari:[],look:[],lookup:[],loop:[],lot:[],lower:7,mac:4,machin:4,made:[],mai:[],main:0,make:7,make_initial_x:[],manag:[],manner:[],math:[4,5],matmul:[0,3],matric:4,matrix:[3,7],matter:7,max:0,mayb:[],mean:[0,3],mechan:0,method:3,might:[],minut:3,mistak:4,miyyer:[],mlp:[],model:7,modul:0,more:4,multipli:[3,4],name:[],nation:[],nationality1:[],nationality_vocab:[],natur:[],navig:[],nearest:[],nearli:[],need:[0,4],neighbor:[],net:7,network:7,new_paramet:0,newgat:1,next:[],nlp:[],none:[],nope:[],normal:[],note:4,notebook:[0,4,7],now:[0,7],number:[],object:[],occur:[],onc:[],one:0,onli:[4,7],onlin:4,oper:4,option:[3,4],org:[],osx:[],our:7,out:0,over:7,own:[],packag:[],pad:5,page:[],paper:[],paramet:0,particip:[],pass:3,pattern:0,pdf:[],penultim:[],peopl:[],per:0,permut:[],persist:4,pip:[],plan:[],pleas:4,point:7,pool:0,port:[],practic:[],pre:[],precalc:4,predict:3,prepend:[],pretend:0,pretrain:6,previous:[],print:[],probabl:0,process:[],product:4,progress:4,prompt:[],provid:4,pub:[],publish:0,python:4,pytorch:[3,7],randint:3,randn:3,random:3,read:4,readi:[],reason:[],recip:4,recommend:4,refer:[],reilli:4,repositori:4,repres:0,represent:[],requir:[],resetg:1,resourc:4,rest:[],result:3,retriev:[],right:[],rnn:0,rule:[],run:3,same:[],sampl:[],sample_n_for_nation:[],sampler:[],san:4,sanitari:[],saw:0,scientif:[],scored_x:0,second:4,section:[4,6],see:3,seen:0,select:0,self:0,septemb:4,sequenc:0,set:[0,4,6,7],set_:7,sever:0,sf2017:[],shoud:[],shoudl:[],should:[],sigmoid:1,signatur:[],significantli:[],similar:0,simpl:[0,4],simpli:[],simplifi:[],singl:0,site:4,situat:[],size:[0,3,6],skill:[],softli:0,softmax:0,softwar:[],some:3,someth:[],song:[],sorri:4,soumith:[],sourc:[],specif:4,specifi:[],speedup:[],spotifi:[],squeez:0,stack:2,start:7,state:[],step:3,still:[],stop:[],store:[],stride:5,structur:7,stuff:[],sum:[0,3],summar:0,sundai:[],support:[],suppos:[],sure:4,surnam:[],surname_vocab:[],system:4,take:0,tanh:1,temp:[],tensor:3,tensor_s:5,termin:[],than:[],thei:4,them:0,thi:[0,3,4,6,7],thing:6,through:4,togeth:0,tool:[],torch:[0,3,7],torchvis:[],train:4,troubl:4,tutori:4,two:[3,4],txt:[],ubuntu:[],umd:[],understand:4,unix:[],unord:0,until:4,unzip:[],url:4,use:[0,4],used:[],useful:[0,4,7],user:4,using:[0,7],valid:0,valu:[0,7],variou:6,vector:[0,4,6],verbos:[],veri:0,version:[],video:4,view:0,virtual:[],visit:[],vocabulari:7,wai:4,want:[0,4,7],weight:[0,7],what:4,when:0,where:[],whether:0,which:[0,7],who:[],why:[],widget:[],window:4,without:[],wonder:[],word:[0,7],word_to_index:7,word_vector:7,word_vector_s:7,word_vocab:7,work:4,worri:[],worthwhil:[],would:[],write:[],www:[],x86_64:[],x_in:0,x_length:[],x_mid:[],xavier_norm:0,y_out:[],you:[0,3,4,6],your:[],zip:[]},titles:["Attention","Gating","NN Patterns","Warm Up Exercise","Natural Language Processing (NLP) with PyTorch","Compute Convolution Sizes","Recipes and PyTorch patterns","Loading Pretrained Vectors","<no title>"],titleterms:{"new":[],Use:[],activ:[],adventur:[],anaconda:[],ask:[],attent:0,between:[],browser:[],choos:[],clone:[],comput:5,convolut:5,creat:[],cuda:[],dai:[],data:[],depend:[],download:[],enabl:[],encod:[],environ:[],exercis:3,fast:[],frequenc:[],from:[],gate:1,gener:4,get:[],gpu:[],hardwar:4,have:[],home:[],inform:4,instal:4,interpol:[],ipython:[],jupyt:[],languag:4,laptop:[],load:7,lookup:[],natur:4,need:[],nlp:4,nvidia:[],onlin:[],option:[],own:[],pattern:[2,6],prerequisit:4,pretrain:7,process:4,pytorch:[4,6],question:[],recip:6,reilli:[],repositori:[],requir:4,resourc:[],sequenc:[],setup:[],size:5,stack:[],take:[],thing:[],through:[],vector:7,warm:3,your:[]}}) -------------------------------------------------------------------------------- /docs/_build/html/_static/js/theme.js: -------------------------------------------------------------------------------- 1 | require=(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o"); 80 | 81 | // Add expand links to all parents of nested ul 82 | $('.wy-menu-vertical ul').not('.simple').siblings('a').each(function () { 83 | var link = $(this); 84 | expand = $(''); 85 | expand.on('click', function (ev) { 86 | self.toggleCurrent(link); 87 | ev.stopPropagation(); 88 | return false; 89 | }); 90 | link.prepend(expand); 91 | }); 92 | }; 93 | 94 | nav.reset = function () { 95 | // Get anchor from URL and open up nested nav 96 | var anchor = encodeURI(window.location.hash); 97 | if (anchor) { 98 | try { 99 | var link = $('.wy-menu-vertical') 100 | .find('[href="' + anchor + '"]'); 101 | // If we didn't find a link, it may be because we clicked on 102 | // something that is not in the sidebar (eg: when using 103 | // sphinxcontrib.httpdomain it generates headerlinks but those 104 | // aren't picked up and placed in the toctree). So let's find 105 | // the closest header in the document and try with that one. 106 | if (link.length === 0) { 107 | var doc_link = $('.document a[href="' + anchor + '"]'); 108 | var closest_section = doc_link.closest('div.section'); 109 | // Try again with the closest section entry. 110 | link = $('.wy-menu-vertical') 111 | .find('[href="#' + closest_section.attr("id") + '"]'); 112 | 113 | } 114 | $('.wy-menu-vertical li.toctree-l1 li.current') 115 | .removeClass('current'); 116 | link.closest('li.toctree-l2').addClass('current'); 117 | link.closest('li.toctree-l3').addClass('current'); 118 | link.closest('li.toctree-l4').addClass('current'); 119 | } 120 | catch (err) { 121 | console.log("Error expanding nav for anchor", err); 122 | } 123 | } 124 | }; 125 | 126 | nav.onScroll = function () { 127 | this.winScroll = false; 128 | var newWinPosition = this.win.scrollTop(), 129 | winBottom = newWinPosition + this.winHeight, 130 | navPosition = this.navBar.scrollTop(), 131 | newNavPosition = navPosition + (newWinPosition - this.winPosition); 132 | if (newWinPosition < 0 || winBottom > this.docHeight) { 133 | return; 134 | } 135 | this.navBar.scrollTop(newNavPosition); 136 | this.winPosition = newWinPosition; 137 | }; 138 | 139 | nav.onResize = function () { 140 | this.winResize = false; 141 | this.winHeight = this.win.height(); 142 | this.docHeight = $(document).height(); 143 | }; 144 | 145 | nav.hashChange = function () { 146 | this.linkScroll = true; 147 | this.win.one('hashchange', function () { 148 | this.linkScroll = false; 149 | }); 150 | }; 151 | 152 | nav.toggleCurrent = function (elem) { 153 | var parent_li = elem.closest('li'); 154 | parent_li.siblings('li.current').removeClass('current'); 155 | parent_li.siblings().find('li.current').removeClass('current'); 156 | parent_li.find('> ul li.current').removeClass('current'); 157 | parent_li.toggleClass('current'); 158 | } 159 | 160 | return nav; 161 | }; 162 | 163 | module.exports.ThemeNav = ThemeNav(); 164 | 165 | if (typeof(window) != 'undefined') { 166 | window.SphinxRtdTheme = { StickyNav: module.exports.ThemeNav }; 167 | } 168 | 169 | },{"jquery":"jquery"}]},{},["sphinx-rtd-theme"]); 170 | -------------------------------------------------------------------------------- /docs/_build/html/faq.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Frequency Asked Questions — NLP with PyTorch documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 53 | 105 | 106 |
107 | 108 | 109 | 115 | 116 | 117 | 118 |
119 |
120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |
137 | 138 |
    139 | 140 |
  • Docs »
  • 141 | 142 |
  • Frequency Asked Questions
  • 143 | 144 | 145 |
  • 146 | 147 | 148 | View page source 149 | 150 | 151 |
  • 152 | 153 |
154 | 155 | 156 |
157 |
158 |
159 |
160 | 161 |
162 |

Frequency Asked Questions

163 |

On this page, you will find a list of questions that we either anticipate 164 | people will ask or that we have been asked previously. They are intended to 165 | be the first stop for any confusion or trouble that might occur.

166 |
167 |

Do I Need to have a NVIDIA GPU enabled laptop?

168 |

Nope! While having a NVIDIA GPU enabled laptop will make the training run 169 | faster, we provide instructions for people who do not have one.

170 |

If you are plan on working on Natural Language Processing/Deep Learning in the future, 171 | a GPU enabled laptop might be a good investment.

172 |
173 |
174 | 175 | 176 |
177 |
178 | 179 |
180 |
181 |
182 | 183 | 191 | 192 | 193 |
194 | 195 |
196 |

197 | © Copyright 2017, Brian McMahan and Delip Rao. 198 | 199 |

200 |
201 | Built with Sphinx using a theme provided by Read the Docs. 202 | 203 |
204 | 205 |
206 |
207 | 208 |
209 | 210 |
211 | 212 | 213 | 214 | 215 | 216 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 245 | 246 | 247 | 248 | -------------------------------------------------------------------------------- /docs/_build/html/download_data.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Getting the Data — NLP with PyTorch documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 |
51 | 52 | 53 | 106 | 107 |
108 | 109 | 110 | 116 | 117 | 118 | 119 |
120 |
121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 |
138 | 139 |
    140 | 141 |
  • Docs »
  • 142 | 143 |
  • Getting the Data
  • 144 | 145 | 146 |
  • 147 | 148 | 149 | View page source 150 | 151 | 152 |
  • 153 | 154 |
155 | 156 | 157 |
158 |
159 |
160 |
161 | 162 |
163 |

Getting the Data

164 |

In this training, there are two options of participating.

165 |
166 |

Option 1: Download and Setup things on your laptop

167 |

The first option is to download the data below, setup the environment, and download the notebooks when we make them available. 168 | If you choose this options but do not download the data before the first day, we will have several flash drives with the data on it.

169 |

Please visit this link to download the data.

170 |
171 |
172 |

Option 2: Use O’Reilly’s online resource through your browser

173 |

The second option is to use an online resource provided by O’Reilly. On the first day of this training, you will be provided with a link to a JupyterHub instance where the environment will be pre-made and ready to go! If you choose this option, you do not have to do anything until you arrive on Sunday. 174 | You are still required to bring your laptop.

175 |
176 |
177 | 178 | 179 |
180 |
181 | 182 |
183 |
184 |
185 | 186 | 194 | 195 | 196 |
197 | 198 |
199 |

200 | © Copyright 2017, Brian McMahan and Delip Rao. 201 | 202 |

203 |
204 | Built with Sphinx using a theme provided by Read the Docs. 205 | 206 |
207 | 208 |
209 |
210 | 211 |
212 | 213 |
214 | 215 | 216 | 217 | 218 | 219 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 248 | 249 | 250 | 251 | -------------------------------------------------------------------------------- /docs/_build/html/_static/doctools.js: -------------------------------------------------------------------------------- 1 | /* 2 | * doctools.js 3 | * ~~~~~~~~~~~ 4 | * 5 | * Sphinx JavaScript utilities for all documentation. 6 | * 7 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /** 13 | * select a different prefix for underscore 14 | */ 15 | $u = _.noConflict(); 16 | 17 | /** 18 | * make the code below compatible with browsers without 19 | * an installed firebug like debugger 20 | if (!window.console || !console.firebug) { 21 | var names = ["log", "debug", "info", "warn", "error", "assert", "dir", 22 | "dirxml", "group", "groupEnd", "time", "timeEnd", "count", "trace", 23 | "profile", "profileEnd"]; 24 | window.console = {}; 25 | for (var i = 0; i < names.length; ++i) 26 | window.console[names[i]] = function() {}; 27 | } 28 | */ 29 | 30 | /** 31 | * small helper function to urldecode strings 32 | */ 33 | jQuery.urldecode = function(x) { 34 | return decodeURIComponent(x).replace(/\+/g, ' '); 35 | }; 36 | 37 | /** 38 | * small helper function to urlencode strings 39 | */ 40 | jQuery.urlencode = encodeURIComponent; 41 | 42 | /** 43 | * This function returns the parsed url parameters of the 44 | * current request. Multiple values per key are supported, 45 | * it will always return arrays of strings for the value parts. 46 | */ 47 | jQuery.getQueryParameters = function(s) { 48 | if (typeof s == 'undefined') 49 | s = document.location.search; 50 | var parts = s.substr(s.indexOf('?') + 1).split('&'); 51 | var result = {}; 52 | for (var i = 0; i < parts.length; i++) { 53 | var tmp = parts[i].split('=', 2); 54 | var key = jQuery.urldecode(tmp[0]); 55 | var value = jQuery.urldecode(tmp[1]); 56 | if (key in result) 57 | result[key].push(value); 58 | else 59 | result[key] = [value]; 60 | } 61 | return result; 62 | }; 63 | 64 | /** 65 | * highlight a given string on a jquery object by wrapping it in 66 | * span elements with the given class name. 67 | */ 68 | jQuery.fn.highlightText = function(text, className) { 69 | function highlight(node) { 70 | if (node.nodeType == 3) { 71 | var val = node.nodeValue; 72 | var pos = val.toLowerCase().indexOf(text); 73 | if (pos >= 0 && !jQuery(node.parentNode).hasClass(className)) { 74 | var span = document.createElement("span"); 75 | span.className = className; 76 | span.appendChild(document.createTextNode(val.substr(pos, text.length))); 77 | node.parentNode.insertBefore(span, node.parentNode.insertBefore( 78 | document.createTextNode(val.substr(pos + text.length)), 79 | node.nextSibling)); 80 | node.nodeValue = val.substr(0, pos); 81 | } 82 | } 83 | else if (!jQuery(node).is("button, select, textarea")) { 84 | jQuery.each(node.childNodes, function() { 85 | highlight(this); 86 | }); 87 | } 88 | } 89 | return this.each(function() { 90 | highlight(this); 91 | }); 92 | }; 93 | 94 | /* 95 | * backward compatibility for jQuery.browser 96 | * This will be supported until firefox bug is fixed. 97 | */ 98 | if (!jQuery.browser) { 99 | jQuery.uaMatch = function(ua) { 100 | ua = ua.toLowerCase(); 101 | 102 | var match = /(chrome)[ \/]([\w.]+)/.exec(ua) || 103 | /(webkit)[ \/]([\w.]+)/.exec(ua) || 104 | /(opera)(?:.*version|)[ \/]([\w.]+)/.exec(ua) || 105 | /(msie) ([\w.]+)/.exec(ua) || 106 | ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec(ua) || 107 | []; 108 | 109 | return { 110 | browser: match[ 1 ] || "", 111 | version: match[ 2 ] || "0" 112 | }; 113 | }; 114 | jQuery.browser = {}; 115 | jQuery.browser[jQuery.uaMatch(navigator.userAgent).browser] = true; 116 | } 117 | 118 | /** 119 | * Small JavaScript module for the documentation. 120 | */ 121 | var Documentation = { 122 | 123 | init : function() { 124 | this.fixFirefoxAnchorBug(); 125 | this.highlightSearchWords(); 126 | this.initIndexTable(); 127 | 128 | }, 129 | 130 | /** 131 | * i18n support 132 | */ 133 | TRANSLATIONS : {}, 134 | PLURAL_EXPR : function(n) { return n == 1 ? 0 : 1; }, 135 | LOCALE : 'unknown', 136 | 137 | // gettext and ngettext don't access this so that the functions 138 | // can safely bound to a different name (_ = Documentation.gettext) 139 | gettext : function(string) { 140 | var translated = Documentation.TRANSLATIONS[string]; 141 | if (typeof translated == 'undefined') 142 | return string; 143 | return (typeof translated == 'string') ? translated : translated[0]; 144 | }, 145 | 146 | ngettext : function(singular, plural, n) { 147 | var translated = Documentation.TRANSLATIONS[singular]; 148 | if (typeof translated == 'undefined') 149 | return (n == 1) ? singular : plural; 150 | return translated[Documentation.PLURALEXPR(n)]; 151 | }, 152 | 153 | addTranslations : function(catalog) { 154 | for (var key in catalog.messages) 155 | this.TRANSLATIONS[key] = catalog.messages[key]; 156 | this.PLURAL_EXPR = new Function('n', 'return +(' + catalog.plural_expr + ')'); 157 | this.LOCALE = catalog.locale; 158 | }, 159 | 160 | /** 161 | * add context elements like header anchor links 162 | */ 163 | addContextElements : function() { 164 | $('div[id] > :header:first').each(function() { 165 | $('\u00B6'). 166 | attr('href', '#' + this.id). 167 | attr('title', _('Permalink to this headline')). 168 | appendTo(this); 169 | }); 170 | $('dt[id]').each(function() { 171 | $('\u00B6'). 172 | attr('href', '#' + this.id). 173 | attr('title', _('Permalink to this definition')). 174 | appendTo(this); 175 | }); 176 | }, 177 | 178 | /** 179 | * workaround a firefox stupidity 180 | * see: https://bugzilla.mozilla.org/show_bug.cgi?id=645075 181 | */ 182 | fixFirefoxAnchorBug : function() { 183 | if (document.location.hash) 184 | window.setTimeout(function() { 185 | document.location.href += ''; 186 | }, 10); 187 | }, 188 | 189 | /** 190 | * highlight the search words provided in the url in the text 191 | */ 192 | highlightSearchWords : function() { 193 | var params = $.getQueryParameters(); 194 | var terms = (params.highlight) ? params.highlight[0].split(/\s+/) : []; 195 | if (terms.length) { 196 | var body = $('div.body'); 197 | if (!body.length) { 198 | body = $('body'); 199 | } 200 | window.setTimeout(function() { 201 | $.each(terms, function() { 202 | body.highlightText(this.toLowerCase(), 'highlighted'); 203 | }); 204 | }, 10); 205 | $('') 207 | .appendTo($('#searchbox')); 208 | } 209 | }, 210 | 211 | /** 212 | * init the domain index toggle buttons 213 | */ 214 | initIndexTable : function() { 215 | var togglers = $('img.toggler').click(function() { 216 | var src = $(this).attr('src'); 217 | var idnum = $(this).attr('id').substr(7); 218 | $('tr.cg-' + idnum).toggle(); 219 | if (src.substr(-9) == 'minus.png') 220 | $(this).attr('src', src.substr(0, src.length-9) + 'plus.png'); 221 | else 222 | $(this).attr('src', src.substr(0, src.length-8) + 'minus.png'); 223 | }).css('display', ''); 224 | if (DOCUMENTATION_OPTIONS.COLLAPSE_INDEX) { 225 | togglers.click(); 226 | } 227 | }, 228 | 229 | /** 230 | * helper function to hide the search marks again 231 | */ 232 | hideSearchWords : function() { 233 | $('#searchbox .highlight-link').fadeOut(300); 234 | $('span.highlighted').removeClass('highlighted'); 235 | }, 236 | 237 | /** 238 | * make the url absolute 239 | */ 240 | makeURL : function(relativeURL) { 241 | return DOCUMENTATION_OPTIONS.URL_ROOT + '/' + relativeURL; 242 | }, 243 | 244 | /** 245 | * get the current relative url 246 | */ 247 | getCurrentURL : function() { 248 | var path = document.location.pathname; 249 | var parts = path.split(/\//); 250 | $.each(DOCUMENTATION_OPTIONS.URL_ROOT.split(/\//), function() { 251 | if (this == '..') 252 | parts.pop(); 253 | }); 254 | var url = parts.join('/'); 255 | return path.substring(url.lastIndexOf('/') + 1, path.length - 1); 256 | }, 257 | 258 | initOnKeyListeners: function() { 259 | $(document).keyup(function(event) { 260 | var activeElementType = document.activeElement.tagName; 261 | // don't navigate when in search box or textarea 262 | if (activeElementType !== 'TEXTAREA' && activeElementType !== 'INPUT' && activeElementType !== 'SELECT') { 263 | switch (event.keyCode) { 264 | case 37: // left 265 | var prevHref = $('link[rel="prev"]').prop('href'); 266 | if (prevHref) { 267 | window.location.href = prevHref; 268 | return false; 269 | } 270 | case 39: // right 271 | var nextHref = $('link[rel="next"]').prop('href'); 272 | if (nextHref) { 273 | window.location.href = nextHref; 274 | return false; 275 | } 276 | } 277 | } 278 | }); 279 | } 280 | }; 281 | 282 | // quick alias for translations 283 | _ = Documentation.gettext; 284 | 285 | $(document).ready(function() { 286 | Documentation.init(); 287 | }); -------------------------------------------------------------------------------- /datautils/vocabulary.py: -------------------------------------------------------------------------------- 1 | from collections import Counter 2 | 3 | import numpy as np 4 | from torch.utils.data import Dataset 5 | import six 6 | 7 | import json 8 | 9 | 10 | class Vocabulary(object): 11 | """ 12 | An implementation that manages the interface between a token dataset and the 13 | machine learning algorithm. 14 | """ 15 | 16 | def __init__(self, use_unks=False, unk_token="", 17 | use_mask=False, mask_token="", use_start_end=False, 18 | start_token="", end_token=""): 19 | """ 20 | Args: 21 | use_unks (bool): The vocabulary will output UNK tokens for out of 22 | vocabulary items. 23 | [default=False] 24 | unk_token (str): The token used for unknown tokens. 25 | If `use_unks` is True, this will be added to the vocabulary. 26 | [default=''] 27 | use_mask (bool): The vocabulary will reserve the 0th index for a mask token. 28 | This is used to handle variable lengths in sequence models. 29 | [default=False] 30 | mask_token (str): The token used for the mask. 31 | Note: mostly a placeholder; it's unlikely the token will be seen. 32 | [default=''] 33 | use_start_end (bool): The vocabulary will reserve indices for two tokens 34 | that represent the start and end of a sequence. 35 | [default=False] 36 | start_token: The token used to indicate the start of a sequence. 37 | If `use_start_end` is True, this will be added to the vocabulary. 38 | [default=''] 39 | end_token: The token used to indicate the end of a sequence 40 | If `use_start_end` is True, this will be added to the vocabulary. 41 | [default=''] 42 | """ 43 | 44 | self._mapping = {} # str -> int 45 | self._flip = {} # int -> str; 46 | self._counts = Counter() # int -> int; count occurrences 47 | self._forced_unks = set() # force tokens to unk (e.g. if < 5 occurrences) 48 | self._i = 0 49 | self._frozen = False 50 | self._frequency_threshold = -1 51 | 52 | # mask token for use in masked recurrent networks 53 | # usually need to be the 0th index 54 | self.use_mask = use_mask 55 | self.mask_token = mask_token 56 | if self.use_mask: 57 | self.add(self.mask_token) 58 | 59 | # unk token for out of vocabulary tokens 60 | self.use_unks = use_unks 61 | self.unk_token = unk_token 62 | if self.use_unks: 63 | self.add(self.unk_token) 64 | 65 | # start token for sequence models 66 | self.use_start_end = use_start_end 67 | self.start_token = start_token 68 | self.end_token = end_token 69 | if self.use_start_end: 70 | self.add(self.start_token) 71 | self.add(self.end_token) 72 | 73 | def iterkeys(self): 74 | for k in self._mapping.keys(): 75 | if k == self.unk_token or k == self.mask_token: 76 | continue 77 | else: 78 | yield k 79 | 80 | def keys(self): 81 | return list(self.iterkeys()) 82 | 83 | def iteritems(self): 84 | for key, value in self._mapping.items(): 85 | if key == self.unk_token or key == self.mask_token: 86 | continue 87 | yield key, value 88 | 89 | def items(self): 90 | return list(self.iteritems()) 91 | 92 | def values(self): 93 | return [value for _, value in self.iteritems()] 94 | 95 | def __getitem__(self, k): 96 | if self._frozen: 97 | if k in self._mapping: 98 | out_index = self._mapping[k] 99 | elif self.use_unks: 100 | out_index = self.unk_index 101 | else: # case: frozen, don't want unks, raise exception 102 | raise VocabularyException("Vocabulary is frozen. " + 103 | "Key '{}' not found.".format(k)) 104 | if out_index in self._forced_unks: 105 | out_index = self.unk_index 106 | elif k in self._mapping: # case: normal 107 | out_index = self._mapping[k] 108 | self._counts[out_index] += 1 109 | else: 110 | out_index = self._mapping[k] = self._i 111 | self._i += 1 112 | self._flip[out_index] = k 113 | self._counts[out_index] = 1 114 | 115 | return out_index 116 | 117 | def add(self, k): 118 | return self.__getitem__(k) 119 | 120 | def add_many(self, x): 121 | return [self.add(k) for k in x] 122 | 123 | def lookup(self, i): 124 | try: 125 | return self._flip[i] 126 | except KeyError: 127 | raise VocabularyException("Key {} not in Vocabulary".format(i)) 128 | 129 | def lookup_many(self, x): 130 | for k in x: 131 | yield self.lookup(k) 132 | 133 | def map(self, sequence, include_start_end=False): 134 | if include_start_end: 135 | yield self.start_index 136 | 137 | for item in sequence: 138 | yield self[item] 139 | 140 | if include_start_end: 141 | yield self.end_index 142 | 143 | def freeze(self, use_unks=False, frequency_cutoff=-1): 144 | self.use_unks = use_unks 145 | self._frequency_cutoff = frequency_cutoff 146 | 147 | if use_unks and self.unk_token not in self: 148 | self.add(self.unk_token) 149 | 150 | if self._frequency_cutoff > 0: 151 | for token, count in self._counts.items(): 152 | if count < self._frequency_cutoff: 153 | self._forced_unks.add(token) 154 | 155 | self._frozen = True 156 | 157 | def unfreeze(self): 158 | self._frozen = False 159 | 160 | def get_counts(self): 161 | return {self._flip[i]: count for i, count in self._counts.items()} 162 | 163 | def get_count(self, token=None, index=None): 164 | if token is None and index is None: 165 | return None 166 | elif token is not None and index is not None: 167 | print("Cannot do two things at once; choose one") 168 | elif token is not None: 169 | return self._counts[self[token]] 170 | elif index is not None: 171 | return self._counts[index] 172 | else: 173 | raise Exception("impossible condition") 174 | 175 | @property 176 | def unk_index(self): 177 | if self.unk_token not in self: 178 | return None 179 | return self._mapping[self.unk_token] 180 | 181 | @property 182 | def mask_index(self): 183 | if self.mask_token not in self: 184 | return None 185 | return self._mapping[self.mask_token] 186 | 187 | @property 188 | def start_index(self): 189 | if self.start_token not in self: 190 | return None 191 | return self._mapping[self.start_token] 192 | 193 | @property 194 | def end_index(self): 195 | if self.end_token not in self: 196 | return None 197 | return self._mapping[self.end_token] 198 | 199 | def __contains__(self, k): 200 | return k in self._mapping 201 | 202 | def __len__(self): 203 | return len(self._mapping) 204 | 205 | def __repr__(self): 206 | return "".format(len(self), self._frozen) 207 | 208 | 209 | def get_serializable_contents(self): 210 | """ 211 | Creats a dict containing the necessary information to recreate this instance 212 | """ 213 | config = {"_mapping": self._mapping, 214 | "_flip": self._flip, 215 | "_frozen": self._frozen, 216 | "_i": self._i, 217 | "_counts": list(self._counts.items()), 218 | "_frequency_threshold": self._frequency_threshold, 219 | "use_unks": self.use_unks, 220 | "unk_token": self.unk_token, 221 | "use_mask": self.use_mask, 222 | "mask_token": self.mask_token, 223 | "use_start_end": self.use_start_end, 224 | "start_token": self.start_token, 225 | "end_token": self.end_token} 226 | return config 227 | 228 | @classmethod 229 | def deserialize_from_contents(cls, content): 230 | """ 231 | Recreate a Vocabulary instance; expect same dict as output in `serialize` 232 | """ 233 | try: 234 | _mapping = content.pop("_mapping") 235 | _flip = content.pop("_flip") 236 | _i = content.pop("_i") 237 | _frozen = content.pop("_frozen") 238 | _counts = content.pop("_counts") 239 | _frequency_threshold = content.pop("_frequency_threshold") 240 | except KeyError: 241 | raise Exception("unable to deserialize vocabulary") 242 | if isinstance(list(_flip.keys())[0], six.string_types): 243 | _flip = {int(k): v for k, v in _flip.items()} 244 | out = cls(**content) 245 | out._mapping = _mapping 246 | out._flip = _flip 247 | out._i = _i 248 | out._counts = Counter(dict(_counts)) 249 | out._frequency_threshold = _frequency_threshold 250 | 251 | if _frozen: 252 | out.freeze(out.use_unks) 253 | 254 | return out 255 | 256 | -------------------------------------------------------------------------------- /docs/_build/html/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Natural Language Processing (NLP) with PyTorch — NLP with PyTorch documentation 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 |
50 | 51 | 52 | 110 | 111 |
112 | 113 | 114 | 120 | 121 | 122 | 123 |
124 |
125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 |
142 | 143 |
    144 | 145 |
  • Docs »
  • 146 | 147 |
  • Natural Language Processing (NLP) with PyTorch
  • 148 | 149 | 150 |
  • 151 | 152 | 153 | View page source 154 | 155 | 156 |
  • 157 | 158 |
159 | 160 | 161 |
162 |
163 |
164 |
165 | 166 |
167 |

Natural Language Processing (NLP) with PyTorch

168 |
169 |
170 |
171 |
172 |
173 |
174 |

Hello! This is a directory of resources for a training tutorial to be 175 | given at the O’Reilly AI Conference in San Francisco on September 17 and 18, 2017.

176 |

Please read below for general information. You can find the github repository at this link. Please note that there are two ways to engage in this training (desribed below).

177 |

More information will be added to this site as the training progresses. 178 | Specifically, we will be adding a ‘recipes’ section, ‘errata’ section, and a ‘bonus exercise’ section as the training progresses!

179 |
180 |

General Information

181 |
182 |

Prerequisites:

183 |
    184 |
  • A working knowledge of Python and the command line
  • 185 |
  • Familiarity with precalc math (multiply matrices, dot products of vectors, etc.) and derivatives of simple functions (If you are new to linear algebra, this video course is handy.)
  • 186 |
  • A general understanding of machine learning (setting up experiments, evaluation, etc.) (useful but not required)
  • 187 |
188 |
189 |
190 |

Hardware and/or installation requirements:

191 |
    192 |
  • 193 |
    There are two options:
    194 |
      195 |
    1. Using O’Reilly’s online resources. For this, you only needs a laptop; on the first day, we will provide you with credentials and a URL to use an online computing resource (a JupyterHub instance) provided by O’Reilly. You will be able to access Jupyter notebooks through this and they will persist until the end of the second day of training (September 18th). This option is not limited by what operating system you have. You will need to have a browser installed.
    2. 196 |
    3. Setting everything up locally. For this, you need a laptop with the PyTorch environment set up. This is only recommended if you want to have the environment locally or have a laptop with a GPU. (If you have trouble following the provided instructions or if you find any mistakes, please file an issue here.) This option is limited to Macs and Linux users only (sorry Windows users!). Be sure you check the LOCAL_RUN_README.md.
    4. 197 |
    198 |
    199 |
    200 |
  • 201 |
202 |
203 |
204 |
205 | 206 | 207 |
208 |
209 | 210 |
211 |
212 |
213 | 214 | 220 | 221 | 222 |
223 | 224 |
225 |

226 | © Copyright 2017, Brian McMahan and Delip Rao. 227 | 228 |

229 |
230 | Built with Sphinx using a theme provided by Read the Docs. 231 | 232 |
233 | 234 |
235 |
236 | 237 |
238 | 239 |
240 | 241 | 242 | 243 | 244 | 245 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 274 | 275 | 276 | 277 | -------------------------------------------------------------------------------- /docs/_build/html/_static/underscore.js: -------------------------------------------------------------------------------- 1 | // Underscore.js 1.3.1 2 | // (c) 2009-2012 Jeremy Ashkenas, DocumentCloud Inc. 3 | // Underscore is freely distributable under the MIT license. 4 | // Portions of Underscore are inspired or borrowed from Prototype, 5 | // Oliver Steele's Functional, and John Resig's Micro-Templating. 6 | // For all details and documentation: 7 | // http://documentcloud.github.com/underscore 8 | (function(){function q(a,c,d){if(a===c)return a!==0||1/a==1/c;if(a==null||c==null)return a===c;if(a._chain)a=a._wrapped;if(c._chain)c=c._wrapped;if(a.isEqual&&b.isFunction(a.isEqual))return a.isEqual(c);if(c.isEqual&&b.isFunction(c.isEqual))return c.isEqual(a);var e=l.call(a);if(e!=l.call(c))return false;switch(e){case "[object String]":return a==String(c);case "[object Number]":return a!=+a?c!=+c:a==0?1/a==1/c:a==+c;case "[object Date]":case "[object Boolean]":return+a==+c;case "[object RegExp]":return a.source== 9 | c.source&&a.global==c.global&&a.multiline==c.multiline&&a.ignoreCase==c.ignoreCase}if(typeof a!="object"||typeof c!="object")return false;for(var f=d.length;f--;)if(d[f]==a)return true;d.push(a);var f=0,g=true;if(e=="[object Array]"){if(f=a.length,g=f==c.length)for(;f--;)if(!(g=f in a==f in c&&q(a[f],c[f],d)))break}else{if("constructor"in a!="constructor"in c||a.constructor!=c.constructor)return false;for(var h in a)if(b.has(a,h)&&(f++,!(g=b.has(c,h)&&q(a[h],c[h],d))))break;if(g){for(h in c)if(b.has(c, 10 | h)&&!f--)break;g=!f}}d.pop();return g}var r=this,G=r._,n={},k=Array.prototype,o=Object.prototype,i=k.slice,H=k.unshift,l=o.toString,I=o.hasOwnProperty,w=k.forEach,x=k.map,y=k.reduce,z=k.reduceRight,A=k.filter,B=k.every,C=k.some,p=k.indexOf,D=k.lastIndexOf,o=Array.isArray,J=Object.keys,s=Function.prototype.bind,b=function(a){return new m(a)};if(typeof exports!=="undefined"){if(typeof module!=="undefined"&&module.exports)exports=module.exports=b;exports._=b}else r._=b;b.VERSION="1.3.1";var j=b.each= 11 | b.forEach=function(a,c,d){if(a!=null)if(w&&a.forEach===w)a.forEach(c,d);else if(a.length===+a.length)for(var e=0,f=a.length;e2;a== 12 | null&&(a=[]);if(y&&a.reduce===y)return e&&(c=b.bind(c,e)),f?a.reduce(c,d):a.reduce(c);j(a,function(a,b,i){f?d=c.call(e,d,a,b,i):(d=a,f=true)});if(!f)throw new TypeError("Reduce of empty array with no initial value");return d};b.reduceRight=b.foldr=function(a,c,d,e){var f=arguments.length>2;a==null&&(a=[]);if(z&&a.reduceRight===z)return e&&(c=b.bind(c,e)),f?a.reduceRight(c,d):a.reduceRight(c);var g=b.toArray(a).reverse();e&&!f&&(c=b.bind(c,e));return f?b.reduce(g,c,d,e):b.reduce(g,c)};b.find=b.detect= 13 | function(a,c,b){var e;E(a,function(a,g,h){if(c.call(b,a,g,h))return e=a,true});return e};b.filter=b.select=function(a,c,b){var e=[];if(a==null)return e;if(A&&a.filter===A)return a.filter(c,b);j(a,function(a,g,h){c.call(b,a,g,h)&&(e[e.length]=a)});return e};b.reject=function(a,c,b){var e=[];if(a==null)return e;j(a,function(a,g,h){c.call(b,a,g,h)||(e[e.length]=a)});return e};b.every=b.all=function(a,c,b){var e=true;if(a==null)return e;if(B&&a.every===B)return a.every(c,b);j(a,function(a,g,h){if(!(e= 14 | e&&c.call(b,a,g,h)))return n});return e};var E=b.some=b.any=function(a,c,d){c||(c=b.identity);var e=false;if(a==null)return e;if(C&&a.some===C)return a.some(c,d);j(a,function(a,b,h){if(e||(e=c.call(d,a,b,h)))return n});return!!e};b.include=b.contains=function(a,c){var b=false;if(a==null)return b;return p&&a.indexOf===p?a.indexOf(c)!=-1:b=E(a,function(a){return a===c})};b.invoke=function(a,c){var d=i.call(arguments,2);return b.map(a,function(a){return(b.isFunction(c)?c||a:a[c]).apply(a,d)})};b.pluck= 15 | function(a,c){return b.map(a,function(a){return a[c]})};b.max=function(a,c,d){if(!c&&b.isArray(a))return Math.max.apply(Math,a);if(!c&&b.isEmpty(a))return-Infinity;var e={computed:-Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;b>=e.computed&&(e={value:a,computed:b})});return e.value};b.min=function(a,c,d){if(!c&&b.isArray(a))return Math.min.apply(Math,a);if(!c&&b.isEmpty(a))return Infinity;var e={computed:Infinity};j(a,function(a,b,h){b=c?c.call(d,a,b,h):a;bd?1:0}),"value")};b.groupBy=function(a,c){var d={},e=b.isFunction(c)?c:function(a){return a[c]};j(a,function(a,b){var c=e(a,b);(d[c]||(d[c]=[])).push(a)});return d};b.sortedIndex=function(a, 17 | c,d){d||(d=b.identity);for(var e=0,f=a.length;e>1;d(a[g])=0})})};b.difference=function(a){var c=b.flatten(i.call(arguments,1));return b.filter(a,function(a){return!b.include(c,a)})};b.zip=function(){for(var a=i.call(arguments),c=b.max(b.pluck(a,"length")),d=Array(c),e=0;e=0;d--)b=[a[d].apply(this,b)];return b[0]}}; 24 | b.after=function(a,b){return a<=0?b():function(){if(--a<1)return b.apply(this,arguments)}};b.keys=J||function(a){if(a!==Object(a))throw new TypeError("Invalid object");var c=[],d;for(d in a)b.has(a,d)&&(c[c.length]=d);return c};b.values=function(a){return b.map(a,b.identity)};b.functions=b.methods=function(a){var c=[],d;for(d in a)b.isFunction(a[d])&&c.push(d);return c.sort()};b.extend=function(a){j(i.call(arguments,1),function(b){for(var d in b)a[d]=b[d]});return a};b.defaults=function(a){j(i.call(arguments, 25 | 1),function(b){for(var d in b)a[d]==null&&(a[d]=b[d])});return a};b.clone=function(a){return!b.isObject(a)?a:b.isArray(a)?a.slice():b.extend({},a)};b.tap=function(a,b){b(a);return a};b.isEqual=function(a,b){return q(a,b,[])};b.isEmpty=function(a){if(b.isArray(a)||b.isString(a))return a.length===0;for(var c in a)if(b.has(a,c))return false;return true};b.isElement=function(a){return!!(a&&a.nodeType==1)};b.isArray=o||function(a){return l.call(a)=="[object Array]"};b.isObject=function(a){return a===Object(a)}; 26 | b.isArguments=function(a){return l.call(a)=="[object Arguments]"};if(!b.isArguments(arguments))b.isArguments=function(a){return!(!a||!b.has(a,"callee"))};b.isFunction=function(a){return l.call(a)=="[object Function]"};b.isString=function(a){return l.call(a)=="[object String]"};b.isNumber=function(a){return l.call(a)=="[object Number]"};b.isNaN=function(a){return a!==a};b.isBoolean=function(a){return a===true||a===false||l.call(a)=="[object Boolean]"};b.isDate=function(a){return l.call(a)=="[object Date]"}; 27 | b.isRegExp=function(a){return l.call(a)=="[object RegExp]"};b.isNull=function(a){return a===null};b.isUndefined=function(a){return a===void 0};b.has=function(a,b){return I.call(a,b)};b.noConflict=function(){r._=G;return this};b.identity=function(a){return a};b.times=function(a,b,d){for(var e=0;e/g,">").replace(/"/g,""").replace(/'/g,"'").replace(/\//g,"/")};b.mixin=function(a){j(b.functions(a), 28 | function(c){K(c,b[c]=a[c])})};var L=0;b.uniqueId=function(a){var b=L++;return a?a+b:b};b.templateSettings={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g,escape:/<%-([\s\S]+?)%>/g};var t=/.^/,u=function(a){return a.replace(/\\\\/g,"\\").replace(/\\'/g,"'")};b.template=function(a,c){var d=b.templateSettings,d="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.escape||t,function(a,b){return"',_.escape("+ 29 | u(b)+"),'"}).replace(d.interpolate||t,function(a,b){return"',"+u(b)+",'"}).replace(d.evaluate||t,function(a,b){return"');"+u(b).replace(/[\r\n\t]/g," ")+";__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');",e=new Function("obj","_",d);return c?e(c,b):function(a){return e.call(this,a,b)}};b.chain=function(a){return b(a).chain()};var m=function(a){this._wrapped=a};b.prototype=m.prototype;var v=function(a,c){return c?b(a).chain():a},K=function(a,c){m.prototype[a]= 30 | function(){var a=i.call(arguments);H.call(a,this._wrapped);return v(c.apply(b,a),this._chain)}};b.mixin(b);j("pop,push,reverse,shift,sort,splice,unshift".split(","),function(a){var b=k[a];m.prototype[a]=function(){var d=this._wrapped;b.apply(d,arguments);var e=d.length;(a=="shift"||a=="splice")&&e===0&&delete d[0];return v(d,this._chain)}});j(["concat","join","slice"],function(a){var b=k[a];m.prototype[a]=function(){return v(b.apply(this._wrapped,arguments),this._chain)}});m.prototype.chain=function(){this._chain= 31 | true;return this};m.prototype.value=function(){return this._wrapped}}).call(this); 32 | -------------------------------------------------------------------------------- /day_1/figures/intro_to_pytorch/computational_graph_forward.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /day_1/figures/intro_to_pytorch/pytorch_variable.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /day_1/0_Using_Pretrained_Embeddings.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "code", 5 | "execution_count": 2, 6 | "metadata": { 7 | "collapsed": false, 8 | "deletable": true, 9 | "editable": true 10 | }, 11 | "outputs": [], 12 | "source": [ 13 | "from __future__ import print_function\n", 14 | "\n", 15 | "from annoy import AnnoyIndex\n", 16 | "import numpy as np\n", 17 | "import torch\n", 18 | "from tqdm import tqdm_notebook as tqdm\n", 19 | "\n", 20 | "from local_settings import settings, datautils" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": 3, 26 | "metadata": { 27 | "collapsed": true, 28 | "deletable": true, 29 | "editable": true 30 | }, 31 | "outputs": [], 32 | "source": [ 33 | "def load_word_vectors(filename=settings.GLOVE_FILENAME):\n", 34 | " word_to_index = {}\n", 35 | " word_vectors = []\n", 36 | " \n", 37 | " with open(filename) as fp:\n", 38 | " for line in tqdm(fp.readlines()):\n", 39 | " line = line.split(\" \")\n", 40 | " \n", 41 | " word = line[0]\n", 42 | " word_to_index[word] = len(word_to_index)\n", 43 | " \n", 44 | " vec = np.array([float(x) for x in line[1:]])\n", 45 | " word_vectors.append(vec)\n", 46 | " word_vector_size = len(word_vectors[0])\n", 47 | " return word_to_index, word_vectors, word_vector_size" 48 | ] 49 | }, 50 | { 51 | "cell_type": "code", 52 | "execution_count": 4, 53 | "metadata": { 54 | "collapsed": true, 55 | "deletable": true, 56 | "editable": true 57 | }, 58 | "outputs": [], 59 | "source": [ 60 | "class PreTrainedEmbeddings(object):\n", 61 | " def __init__(self):\n", 62 | " self.word_to_index, self.word_vectors, self.word_vector_size = load_word_vectors()\n", 63 | " self.index_to_word = {v: k for k, v in self.word_to_index.items()}\n", 64 | " self.index = AnnoyIndex(self.word_vector_size, metric='euclidean')\n", 65 | " print('Building Index')\n", 66 | " for _, i in tqdm(self.word_to_index.items()):\n", 67 | " self.index.add_item(i, self.word_vectors[i])\n", 68 | " self.index.build(50)\n", 69 | " print('Finished!')\n", 70 | " \n", 71 | " def get_embedding(self, word):\n", 72 | " return self.word_vectors[self.word_to_index[word]]\n", 73 | " \n", 74 | " def closest(self, word, n=1):\n", 75 | " vector = self.get_embedding(word)\n", 76 | " nn_indices = self.index.get_nns_by_vector(vector, n)\n", 77 | " return [self.index_to_word[neighbor] for neighbor in nn_indices]\n", 78 | " \n", 79 | " def closest_v(self, vector, n=1):\n", 80 | " nn_indices = self.index.get_nns_by_vector(vector, n)\n", 81 | " return [self.index_to_word[neighbor] for neighbor in nn_indices]\n", 82 | " \n", 83 | " def sim(self, w1, w2):\n", 84 | " return np.dot(self.get_embedding(w1), self.get_embedding(w2))" 85 | ] 86 | }, 87 | { 88 | "cell_type": "code", 89 | "execution_count": 5, 90 | "metadata": { 91 | "collapsed": false, 92 | "deletable": true, 93 | "editable": true 94 | }, 95 | "outputs": [ 96 | { 97 | "data": { 98 | "application/vnd.jupyter.widget-view+json": { 99 | "model_id": "59d76ce78f56438ba853d7098c7a67d3" 100 | } 101 | }, 102 | "metadata": {}, 103 | "output_type": "display_data" 104 | }, 105 | { 106 | "name": "stdout", 107 | "output_type": "stream", 108 | "text": [ 109 | "\n", 110 | "Building Index\n" 111 | ] 112 | }, 113 | { 114 | "data": { 115 | "application/vnd.jupyter.widget-view+json": { 116 | "model_id": "f7c8ad0bfbb84a21a9ce0583fa670b2f" 117 | } 118 | }, 119 | "metadata": {}, 120 | "output_type": "display_data" 121 | }, 122 | { 123 | "name": "stdout", 124 | "output_type": "stream", 125 | "text": [ 126 | "\n", 127 | "Finished!\n" 128 | ] 129 | } 130 | ], 131 | "source": [ 132 | "glove = PreTrainedEmbeddings()" 133 | ] 134 | }, 135 | { 136 | "cell_type": "code", 137 | "execution_count": 6, 138 | "metadata": { 139 | "collapsed": false, 140 | "deletable": true, 141 | "editable": true, 142 | "scrolled": true 143 | }, 144 | "outputs": [ 145 | { 146 | "data": { 147 | "text/plain": [ 148 | "['apple', 'microsoft', 'dell', 'pc', 'hewlett']" 149 | ] 150 | }, 151 | "execution_count": 6, 152 | "metadata": {}, 153 | "output_type": "execute_result" 154 | } 155 | ], 156 | "source": [ 157 | "glove.closest('apple', n=5)" 158 | ] 159 | }, 160 | { 161 | "cell_type": "code", 162 | "execution_count": 7, 163 | "metadata": { 164 | "collapsed": false, 165 | "deletable": true, 166 | "editable": true, 167 | "scrolled": true 168 | }, 169 | "outputs": [ 170 | { 171 | "data": { 172 | "text/plain": [ 173 | "['plane', 'airplane', 'jet', 'flight', 'crash']" 174 | ] 175 | }, 176 | "execution_count": 7, 177 | "metadata": {}, 178 | "output_type": "execute_result" 179 | } 180 | ], 181 | "source": [ 182 | "glove.closest('plane', n=5)" 183 | ] 184 | }, 185 | { 186 | "cell_type": "code", 187 | "execution_count": 8, 188 | "metadata": { 189 | "collapsed": false, 190 | "deletable": true, 191 | "editable": true 192 | }, 193 | "outputs": [ 194 | { 195 | "data": { 196 | "text/plain": [ 197 | "(26.873448266652002, 16.501491855324002)" 198 | ] 199 | }, 200 | "execution_count": 8, 201 | "metadata": {}, 202 | "output_type": "execute_result" 203 | } 204 | ], 205 | "source": [ 206 | "glove.sim('beer', 'wine'), glove.sim('beer', 'gasoline')" 207 | ] 208 | }, 209 | { 210 | "cell_type": "markdown", 211 | "metadata": {}, 212 | "source": [ 213 | "** Lexical relationships uncovered by word embeddings **" 214 | ] 215 | }, 216 | { 217 | "cell_type": "code", 218 | "execution_count": 10, 219 | "metadata": { 220 | "collapsed": true, 221 | "deletable": true, 222 | "editable": true 223 | }, 224 | "outputs": [], 225 | "source": [ 226 | "def SAT_analogy(w1, w2, w3):\n", 227 | " '''\n", 228 | " Solves problems of the type:\n", 229 | " w1 : w2 :: w3 : __\n", 230 | " '''\n", 231 | " closest_words = []\n", 232 | " try:\n", 233 | " w1v = glove.get_embedding(w1)\n", 234 | " w2v = glove.get_embedding(w2)\n", 235 | " w3v = glove.get_embedding(w3)\n", 236 | " w4v = w3v + (w2v - w1v)\n", 237 | " closest_words = glove.closest_v(w4v, n=5)\n", 238 | " closest_words = [w for w in closest_words if w not in [w1, w2, w3]]\n", 239 | " except:\n", 240 | " pass\n", 241 | " if len(closest_words) == 0:\n", 242 | " print(':-(')\n", 243 | " else:\n", 244 | " print('{} : {} :: {} : {}'.format(w1, w2, w3, closest_words[0]))" 245 | ] 246 | }, 247 | { 248 | "cell_type": "markdown", 249 | "metadata": {}, 250 | "source": [ 251 | "**Pronouns**" 252 | ] 253 | }, 254 | { 255 | "cell_type": "code", 256 | "execution_count": 11, 257 | "metadata": { 258 | "collapsed": false, 259 | "deletable": true, 260 | "editable": true 261 | }, 262 | "outputs": [ 263 | { 264 | "name": "stdout", 265 | "output_type": "stream", 266 | "text": [ 267 | "man : he :: woman : she\n" 268 | ] 269 | } 270 | ], 271 | "source": [ 272 | "SAT_analogy('man', 'he', 'woman')" 273 | ] 274 | }, 275 | { 276 | "cell_type": "markdown", 277 | "metadata": {}, 278 | "source": [ 279 | "** Verb-Noun relationships **" 280 | ] 281 | }, 282 | { 283 | "cell_type": "code", 284 | "execution_count": 12, 285 | "metadata": { 286 | "collapsed": false, 287 | "deletable": true, 288 | "editable": true 289 | }, 290 | "outputs": [ 291 | { 292 | "name": "stdout", 293 | "output_type": "stream", 294 | "text": [ 295 | "fly : plane :: sail : ship\n" 296 | ] 297 | } 298 | ], 299 | "source": [ 300 | "SAT_analogy('fly', 'plane', 'sail')" 301 | ] 302 | }, 303 | { 304 | "cell_type": "markdown", 305 | "metadata": {}, 306 | "source": [ 307 | "**Noun-Noun relationships**" 308 | ] 309 | }, 310 | { 311 | "cell_type": "code", 312 | "execution_count": 20, 313 | "metadata": { 314 | "collapsed": false, 315 | "deletable": true, 316 | "editable": true 317 | }, 318 | "outputs": [ 319 | { 320 | "name": "stdout", 321 | "output_type": "stream", 322 | "text": [ 323 | "cat : kitten :: dog : puppy\n" 324 | ] 325 | } 326 | ], 327 | "source": [ 328 | "SAT_analogy('cat', 'kitten', 'dog')" 329 | ] 330 | }, 331 | { 332 | "cell_type": "markdown", 333 | "metadata": {}, 334 | "source": [ 335 | "**Hypernymy**" 336 | ] 337 | }, 338 | { 339 | "cell_type": "code", 340 | "execution_count": 23, 341 | "metadata": { 342 | "collapsed": false, 343 | "deletable": true, 344 | "editable": true 345 | }, 346 | "outputs": [ 347 | { 348 | "name": "stdout", 349 | "output_type": "stream", 350 | "text": [ 351 | "blue : color :: dog : animal\n" 352 | ] 353 | } 354 | ], 355 | "source": [ 356 | "SAT_analogy('blue', 'color', 'dog')" 357 | ] 358 | }, 359 | { 360 | "cell_type": "markdown", 361 | "metadata": { 362 | "collapsed": true, 363 | "deletable": true, 364 | "editable": true 365 | }, 366 | "source": [ 367 | "**Meronymy**" 368 | ] 369 | }, 370 | { 371 | "cell_type": "code", 372 | "execution_count": 57, 373 | "metadata": { 374 | "collapsed": false, 375 | "deletable": true, 376 | "editable": true 377 | }, 378 | "outputs": [ 379 | { 380 | "name": "stdout", 381 | "output_type": "stream", 382 | "text": [ 383 | "leg : legs :: hand : hands\n" 384 | ] 385 | } 386 | ], 387 | "source": [ 388 | "SAT_analogy('leg', 'legs', 'hand')" 389 | ] 390 | }, 391 | { 392 | "cell_type": "markdown", 393 | "metadata": { 394 | "deletable": true, 395 | "editable": true 396 | }, 397 | "source": [ 398 | "**Troponymy**" 399 | ] 400 | }, 401 | { 402 | "cell_type": "code", 403 | "execution_count": 32, 404 | "metadata": { 405 | "collapsed": false, 406 | "deletable": true, 407 | "editable": true 408 | }, 409 | "outputs": [ 410 | { 411 | "name": "stdout", 412 | "output_type": "stream", 413 | "text": [ 414 | "talk : communicate :: read : interpret\n" 415 | ] 416 | } 417 | ], 418 | "source": [ 419 | "SAT_analogy('talk', 'communicate', 'read')" 420 | ] 421 | }, 422 | { 423 | "cell_type": "markdown", 424 | "metadata": { 425 | "deletable": true, 426 | "editable": true 427 | }, 428 | "source": [ 429 | "**Metonymy**" 430 | ] 431 | }, 432 | { 433 | "cell_type": "code", 434 | "execution_count": 41, 435 | "metadata": { 436 | "collapsed": false, 437 | "deletable": true, 438 | "editable": true 439 | }, 440 | "outputs": [ 441 | { 442 | "name": "stdout", 443 | "output_type": "stream", 444 | "text": [ 445 | "blue : democrat :: red : republican\n" 446 | ] 447 | } 448 | ], 449 | "source": [ 450 | "SAT_analogy('blue', 'democrat', 'red')" 451 | ] 452 | }, 453 | { 454 | "cell_type": "markdown", 455 | "metadata": { 456 | "deletable": true, 457 | "editable": true 458 | }, 459 | "source": [ 460 | "**Misc**" 461 | ] 462 | }, 463 | { 464 | "cell_type": "code", 465 | "execution_count": 13, 466 | "metadata": { 467 | "collapsed": false, 468 | "deletable": true, 469 | "editable": true 470 | }, 471 | "outputs": [ 472 | { 473 | "name": "stdout", 474 | "output_type": "stream", 475 | "text": [ 476 | "man : doctor :: woman : nurse\n" 477 | ] 478 | } 479 | ], 480 | "source": [ 481 | "SAT_analogy('man', 'doctor', 'woman')" 482 | ] 483 | }, 484 | { 485 | "cell_type": "code", 486 | "execution_count": 14, 487 | "metadata": { 488 | "collapsed": false, 489 | "deletable": true, 490 | "editable": true 491 | }, 492 | "outputs": [ 493 | { 494 | "name": "stdout", 495 | "output_type": "stream", 496 | "text": [ 497 | "man : leader :: woman : opposition\n" 498 | ] 499 | } 500 | ], 501 | "source": [ 502 | "SAT_analogy('man', 'leader', 'woman')" 503 | ] 504 | } 505 | ], 506 | "metadata": { 507 | "kernelspec": { 508 | "display_name": "Python 3", 509 | "language": "python", 510 | "name": "python3" 511 | }, 512 | "language_info": { 513 | "codemirror_mode": { 514 | "name": "ipython", 515 | "version": 3 516 | }, 517 | "file_extension": ".py", 518 | "mimetype": "text/x-python", 519 | "name": "python", 520 | "nbconvert_exporter": "python", 521 | "pygments_lexer": "ipython3", 522 | "version": "3.6.0" 523 | } 524 | }, 525 | "nbformat": 4, 526 | "nbformat_minor": 2 527 | } 528 | -------------------------------------------------------------------------------- /docs/_build/html/_static/basic.css: -------------------------------------------------------------------------------- 1 | /* 2 | * basic.css 3 | * ~~~~~~~~~ 4 | * 5 | * Sphinx stylesheet -- basic theme. 6 | * 7 | * :copyright: Copyright 2007-2016 by the Sphinx team, see AUTHORS. 8 | * :license: BSD, see LICENSE for details. 9 | * 10 | */ 11 | 12 | /* -- main layout ----------------------------------------------------------- */ 13 | 14 | div.clearer { 15 | clear: both; 16 | } 17 | 18 | /* -- relbar ---------------------------------------------------------------- */ 19 | 20 | div.related { 21 | width: 100%; 22 | font-size: 90%; 23 | } 24 | 25 | div.related h3 { 26 | display: none; 27 | } 28 | 29 | div.related ul { 30 | margin: 0; 31 | padding: 0 0 0 10px; 32 | list-style: none; 33 | } 34 | 35 | div.related li { 36 | display: inline; 37 | } 38 | 39 | div.related li.right { 40 | float: right; 41 | margin-right: 5px; 42 | } 43 | 44 | /* -- sidebar --------------------------------------------------------------- */ 45 | 46 | div.sphinxsidebarwrapper { 47 | padding: 10px 5px 0 10px; 48 | } 49 | 50 | div.sphinxsidebar { 51 | float: left; 52 | width: 230px; 53 | margin-left: -100%; 54 | font-size: 90%; 55 | word-wrap: break-word; 56 | overflow-wrap : break-word; 57 | } 58 | 59 | div.sphinxsidebar ul { 60 | list-style: none; 61 | } 62 | 63 | div.sphinxsidebar ul ul, 64 | div.sphinxsidebar ul.want-points { 65 | margin-left: 20px; 66 | list-style: square; 67 | } 68 | 69 | div.sphinxsidebar ul ul { 70 | margin-top: 0; 71 | margin-bottom: 0; 72 | } 73 | 74 | div.sphinxsidebar form { 75 | margin-top: 10px; 76 | } 77 | 78 | div.sphinxsidebar input { 79 | border: 1px solid #98dbcc; 80 | font-family: sans-serif; 81 | font-size: 1em; 82 | } 83 | 84 | div.sphinxsidebar #searchbox input[type="text"] { 85 | width: 170px; 86 | } 87 | 88 | img { 89 | border: 0; 90 | max-width: 100%; 91 | } 92 | 93 | /* -- search page ----------------------------------------------------------- */ 94 | 95 | ul.search { 96 | margin: 10px 0 0 20px; 97 | padding: 0; 98 | } 99 | 100 | ul.search li { 101 | padding: 5px 0 5px 20px; 102 | background-image: url(file.png); 103 | background-repeat: no-repeat; 104 | background-position: 0 7px; 105 | } 106 | 107 | ul.search li a { 108 | font-weight: bold; 109 | } 110 | 111 | ul.search li div.context { 112 | color: #888; 113 | margin: 2px 0 0 30px; 114 | text-align: left; 115 | } 116 | 117 | ul.keywordmatches li.goodmatch a { 118 | font-weight: bold; 119 | } 120 | 121 | /* -- index page ------------------------------------------------------------ */ 122 | 123 | table.contentstable { 124 | width: 90%; 125 | margin-left: auto; 126 | margin-right: auto; 127 | } 128 | 129 | table.contentstable p.biglink { 130 | line-height: 150%; 131 | } 132 | 133 | a.biglink { 134 | font-size: 1.3em; 135 | } 136 | 137 | span.linkdescr { 138 | font-style: italic; 139 | padding-top: 5px; 140 | font-size: 90%; 141 | } 142 | 143 | /* -- general index --------------------------------------------------------- */ 144 | 145 | table.indextable { 146 | width: 100%; 147 | } 148 | 149 | table.indextable td { 150 | text-align: left; 151 | vertical-align: top; 152 | } 153 | 154 | table.indextable ul { 155 | margin-top: 0; 156 | margin-bottom: 0; 157 | list-style-type: none; 158 | } 159 | 160 | table.indextable > tbody > tr > td > ul { 161 | padding-left: 0em; 162 | } 163 | 164 | table.indextable tr.pcap { 165 | height: 10px; 166 | } 167 | 168 | table.indextable tr.cap { 169 | margin-top: 10px; 170 | background-color: #f2f2f2; 171 | } 172 | 173 | img.toggler { 174 | margin-right: 3px; 175 | margin-top: 3px; 176 | cursor: pointer; 177 | } 178 | 179 | div.modindex-jumpbox { 180 | border-top: 1px solid #ddd; 181 | border-bottom: 1px solid #ddd; 182 | margin: 1em 0 1em 0; 183 | padding: 0.4em; 184 | } 185 | 186 | div.genindex-jumpbox { 187 | border-top: 1px solid #ddd; 188 | border-bottom: 1px solid #ddd; 189 | margin: 1em 0 1em 0; 190 | padding: 0.4em; 191 | } 192 | 193 | /* -- domain module index --------------------------------------------------- */ 194 | 195 | table.modindextable td { 196 | padding: 2px; 197 | border-collapse: collapse; 198 | } 199 | 200 | /* -- general body styles --------------------------------------------------- */ 201 | 202 | div.body p, div.body dd, div.body li, div.body blockquote { 203 | -moz-hyphens: auto; 204 | -ms-hyphens: auto; 205 | -webkit-hyphens: auto; 206 | hyphens: auto; 207 | } 208 | 209 | a.headerlink { 210 | visibility: hidden; 211 | } 212 | 213 | h1:hover > a.headerlink, 214 | h2:hover > a.headerlink, 215 | h3:hover > a.headerlink, 216 | h4:hover > a.headerlink, 217 | h5:hover > a.headerlink, 218 | h6:hover > a.headerlink, 219 | dt:hover > a.headerlink, 220 | caption:hover > a.headerlink, 221 | p.caption:hover > a.headerlink, 222 | div.code-block-caption:hover > a.headerlink { 223 | visibility: visible; 224 | } 225 | 226 | div.body p.caption { 227 | text-align: inherit; 228 | } 229 | 230 | div.body td { 231 | text-align: left; 232 | } 233 | 234 | .first { 235 | margin-top: 0 !important; 236 | } 237 | 238 | p.rubric { 239 | margin-top: 30px; 240 | font-weight: bold; 241 | } 242 | 243 | img.align-left, .figure.align-left, object.align-left { 244 | clear: left; 245 | float: left; 246 | margin-right: 1em; 247 | } 248 | 249 | img.align-right, .figure.align-right, object.align-right { 250 | clear: right; 251 | float: right; 252 | margin-left: 1em; 253 | } 254 | 255 | img.align-center, .figure.align-center, object.align-center { 256 | display: block; 257 | margin-left: auto; 258 | margin-right: auto; 259 | } 260 | 261 | .align-left { 262 | text-align: left; 263 | } 264 | 265 | .align-center { 266 | text-align: center; 267 | } 268 | 269 | .align-right { 270 | text-align: right; 271 | } 272 | 273 | /* -- sidebars -------------------------------------------------------------- */ 274 | 275 | div.sidebar { 276 | margin: 0 0 0.5em 1em; 277 | border: 1px solid #ddb; 278 | padding: 7px 7px 0 7px; 279 | background-color: #ffe; 280 | width: 40%; 281 | float: right; 282 | } 283 | 284 | p.sidebar-title { 285 | font-weight: bold; 286 | } 287 | 288 | /* -- topics ---------------------------------------------------------------- */ 289 | 290 | div.topic { 291 | border: 1px solid #ccc; 292 | padding: 7px 7px 0 7px; 293 | margin: 10px 0 10px 0; 294 | } 295 | 296 | p.topic-title { 297 | font-size: 1.1em; 298 | font-weight: bold; 299 | margin-top: 10px; 300 | } 301 | 302 | /* -- admonitions ----------------------------------------------------------- */ 303 | 304 | div.admonition { 305 | margin-top: 10px; 306 | margin-bottom: 10px; 307 | padding: 7px; 308 | } 309 | 310 | div.admonition dt { 311 | font-weight: bold; 312 | } 313 | 314 | div.admonition dl { 315 | margin-bottom: 0; 316 | } 317 | 318 | p.admonition-title { 319 | margin: 0px 10px 5px 0px; 320 | font-weight: bold; 321 | } 322 | 323 | div.body p.centered { 324 | text-align: center; 325 | margin-top: 25px; 326 | } 327 | 328 | /* -- tables ---------------------------------------------------------------- */ 329 | 330 | table.docutils { 331 | border: 0; 332 | border-collapse: collapse; 333 | } 334 | 335 | table caption span.caption-number { 336 | font-style: italic; 337 | } 338 | 339 | table caption span.caption-text { 340 | } 341 | 342 | table.docutils td, table.docutils th { 343 | padding: 1px 8px 1px 5px; 344 | border-top: 0; 345 | border-left: 0; 346 | border-right: 0; 347 | border-bottom: 1px solid #aaa; 348 | } 349 | 350 | table.footnote td, table.footnote th { 351 | border: 0 !important; 352 | } 353 | 354 | th { 355 | text-align: left; 356 | padding-right: 5px; 357 | } 358 | 359 | table.citation { 360 | border-left: solid 1px gray; 361 | margin-left: 1px; 362 | } 363 | 364 | table.citation td { 365 | border-bottom: none; 366 | } 367 | 368 | /* -- figures --------------------------------------------------------------- */ 369 | 370 | div.figure { 371 | margin: 0.5em; 372 | padding: 0.5em; 373 | } 374 | 375 | div.figure p.caption { 376 | padding: 0.3em; 377 | } 378 | 379 | div.figure p.caption span.caption-number { 380 | font-style: italic; 381 | } 382 | 383 | div.figure p.caption span.caption-text { 384 | } 385 | 386 | /* -- field list styles ----------------------------------------------------- */ 387 | 388 | table.field-list td, table.field-list th { 389 | border: 0 !important; 390 | } 391 | 392 | .field-list ul { 393 | margin: 0; 394 | padding-left: 1em; 395 | } 396 | 397 | .field-list p { 398 | margin: 0; 399 | } 400 | 401 | /* -- other body styles ----------------------------------------------------- */ 402 | 403 | ol.arabic { 404 | list-style: decimal; 405 | } 406 | 407 | ol.loweralpha { 408 | list-style: lower-alpha; 409 | } 410 | 411 | ol.upperalpha { 412 | list-style: upper-alpha; 413 | } 414 | 415 | ol.lowerroman { 416 | list-style: lower-roman; 417 | } 418 | 419 | ol.upperroman { 420 | list-style: upper-roman; 421 | } 422 | 423 | dl { 424 | margin-bottom: 15px; 425 | } 426 | 427 | dd p { 428 | margin-top: 0px; 429 | } 430 | 431 | dd ul, dd table { 432 | margin-bottom: 10px; 433 | } 434 | 435 | dd { 436 | margin-top: 3px; 437 | margin-bottom: 10px; 438 | margin-left: 30px; 439 | } 440 | 441 | dt:target, .highlighted { 442 | background-color: #fbe54e; 443 | } 444 | 445 | dl.glossary dt { 446 | font-weight: bold; 447 | font-size: 1.1em; 448 | } 449 | 450 | .optional { 451 | font-size: 1.3em; 452 | } 453 | 454 | .sig-paren { 455 | font-size: larger; 456 | } 457 | 458 | .versionmodified { 459 | font-style: italic; 460 | } 461 | 462 | .system-message { 463 | background-color: #fda; 464 | padding: 5px; 465 | border: 3px solid red; 466 | } 467 | 468 | .footnote:target { 469 | background-color: #ffa; 470 | } 471 | 472 | .line-block { 473 | display: block; 474 | margin-top: 1em; 475 | margin-bottom: 1em; 476 | } 477 | 478 | .line-block .line-block { 479 | margin-top: 0; 480 | margin-bottom: 0; 481 | margin-left: 1.5em; 482 | } 483 | 484 | .guilabel, .menuselection { 485 | font-family: sans-serif; 486 | } 487 | 488 | .accelerator { 489 | text-decoration: underline; 490 | } 491 | 492 | .classifier { 493 | font-style: oblique; 494 | } 495 | 496 | abbr, acronym { 497 | border-bottom: dotted 1px; 498 | cursor: help; 499 | } 500 | 501 | /* -- code displays --------------------------------------------------------- */ 502 | 503 | pre { 504 | overflow: auto; 505 | overflow-y: hidden; /* fixes display issues on Chrome browsers */ 506 | } 507 | 508 | span.pre { 509 | -moz-hyphens: none; 510 | -ms-hyphens: none; 511 | -webkit-hyphens: none; 512 | hyphens: none; 513 | } 514 | 515 | td.linenos pre { 516 | padding: 5px 0px; 517 | border: 0; 518 | background-color: transparent; 519 | color: #aaa; 520 | } 521 | 522 | table.highlighttable { 523 | margin-left: 0.5em; 524 | } 525 | 526 | table.highlighttable td { 527 | padding: 0 0.5em 0 0.5em; 528 | } 529 | 530 | div.code-block-caption { 531 | padding: 2px 5px; 532 | font-size: small; 533 | } 534 | 535 | div.code-block-caption code { 536 | background-color: transparent; 537 | } 538 | 539 | div.code-block-caption + div > div.highlight > pre { 540 | margin-top: 0; 541 | } 542 | 543 | div.code-block-caption span.caption-number { 544 | padding: 0.1em 0.3em; 545 | font-style: italic; 546 | } 547 | 548 | div.code-block-caption span.caption-text { 549 | } 550 | 551 | div.literal-block-wrapper { 552 | padding: 1em 1em 0; 553 | } 554 | 555 | div.literal-block-wrapper div.highlight { 556 | margin: 0; 557 | } 558 | 559 | code.descname { 560 | background-color: transparent; 561 | font-weight: bold; 562 | font-size: 1.2em; 563 | } 564 | 565 | code.descclassname { 566 | background-color: transparent; 567 | } 568 | 569 | code.xref, a code { 570 | background-color: transparent; 571 | font-weight: bold; 572 | } 573 | 574 | h1 code, h2 code, h3 code, h4 code, h5 code, h6 code { 575 | background-color: transparent; 576 | } 577 | 578 | .viewcode-link { 579 | float: right; 580 | } 581 | 582 | .viewcode-back { 583 | float: right; 584 | font-family: sans-serif; 585 | } 586 | 587 | div.viewcode-block:target { 588 | margin: -1px -10px; 589 | padding: 0 10px; 590 | } 591 | 592 | /* -- math display ---------------------------------------------------------- */ 593 | 594 | img.math { 595 | vertical-align: middle; 596 | } 597 | 598 | div.body div.math p { 599 | text-align: center; 600 | } 601 | 602 | span.eqno { 603 | float: right; 604 | } 605 | 606 | span.eqno a.headerlink { 607 | position: relative; 608 | left: 0px; 609 | z-index: 1; 610 | } 611 | 612 | div.math:hover a.headerlink { 613 | visibility: visible; 614 | } 615 | 616 | /* -- printout stylesheet --------------------------------------------------- */ 617 | 618 | @media print { 619 | div.document, 620 | div.documentwrapper, 621 | div.bodywrapper { 622 | margin: 0 !important; 623 | width: 100%; 624 | } 625 | 626 | div.sphinxsidebar, 627 | div.related, 628 | div.footer, 629 | #top-link { 630 | display: none; 631 | } 632 | } -------------------------------------------------------------------------------- /day_1/figures/intro_to_pytorch/computational_graph_backward.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | --------------------------------------------------------------------------------