Kernel: Python 3 (ipykernel)
Machine Learning with PyTorch and Scikit-Learn
-- Code Examples
Package version checks
Add folder to path in order to load from the check_packages.py script:
In [3]:
Check recommended package versions:
In [2]:
Out[2]:
[OK] Your Python version is 3.9.7 | packaged by conda-forge | (default, Sep 29 2021, 19:24:02)
[Clang 11.1.0 ]
[OK] torch 1.10.1
Chapter 15: Modeling Sequential Data Using Recurrent Neural Networks (Part 1/3)
Outline
In [4]:
Introducing sequential data
Modeling sequential data—order matters
Representing sequences
In [2]:
Out[2]:
The different categories of sequence modeling
In [3]:
Out[3]:
RNNs for modeling sequences
Understanding the RNN looping mechanism
In [4]:
Out[4]:
In [5]:
Out[5]:
Computing activations in an RNN
In [6]:
Out[6]:
In [5]:
Out[5]:
Hidden-recurrence vs. output-recurrence
In [8]:
Out[8]:
In [11]:
Out[11]:
W_xh shape: torch.Size([2, 5])
W_hh shape: torch.Size([2, 2])
b_xh shape: torch.Size([2])
b_hh shape: torch.Size([2])
In [12]:
Out[12]:
Time step 0 =>
Input : [[1. 1. 1. 1. 1.]]
Hidden : [[-0.4701929 0.5863904]]
Output (manual) : [[-0.3519801 0.52525216]]
RNN output : [[-0.3519801 0.52525216]]
Time step 1 =>
Input : [[2. 2. 2. 2. 2.]]
Hidden : [[-0.88883156 1.2364397 ]]
Output (manual) : [[-0.68424344 0.76074266]]
RNN output : [[-0.68424344 0.76074266]]
Time step 2 =>
Input : [[3. 3. 3. 3. 3.]]
Hidden : [[-1.3074701 1.886489 ]]
Output (manual) : [[-0.8649416 0.90466356]]
RNN output : [[-0.8649416 0.90466356]]
The challenges of learning long-range interactions
In [9]:
Out[9]:
Long Short-Term Memory cells
In [10]:
Out[10]:
Readers may ignore the next cell.
In [15]:
Out[15]:
[NbConvertApp] Converting notebook ch15_part1.ipynb to script
[NbConvertApp] Writing 3919 bytes to ch15_part1.py