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 [1]:
Check recommended package versions:
In [2]:
Out[2]:
[OK] Your Python version is 3.8.8 | packaged by conda-forge | (default, Feb 20 2021, 16:22:27)
[GCC 9.3.0]
[OK] torch 1.10.0
[OK] torch_geometric 2.0.3
[OK] numpy 1.21.5
[OK] matplotlib 3.5.1
Chapter 18 - Graph Neural Networks for Capturing Dependencies in Graph Structured Data (Part 2/2)
In [2]:
Implementing a GNN using the PyTorch Geometric library
In [3]:
In [4]:
Out[4]:
130831
In [5]:
Out[5]:
Data(x=[5, 11], edge_index=[2, 8], edge_attr=[8, 4], y=[1, 19], pos=[5, 3], idx=[1], name='gdb_1', z=[5])
In [6]:
Out[6]:
tensor([6, 1, 1, 1, 1])
In [7]:
Out[7]:
Data(x=[5, 11], edge_index=[2, 8], edge_attr=[8, 4], y=[1, 19], pos=[5, 3], idx=[1], name='gdb_1', z=[5], new_attribute=[3])
In [8]:
Out[8]:
True
In [9]:
In [10]:
In [11]:
In [12]:
Out[12]:
ExampleNet(
(conv1): NNConv(11, 32, aggr=add, nn=Sequential(
(0): Linear(in_features=4, out_features=32, bias=True)
(1): ReLU()
(2): Linear(in_features=32, out_features=352, bias=True)
))
(conv2): NNConv(32, 16, aggr=add, nn=Sequential(
(0): Linear(in_features=4, out_features=32, bias=True)
(1): ReLU()
(2): Linear(in_features=32, out_features=512, bias=True)
))
(fc_1): Linear(in_features=16, out_features=32, bias=True)
(out): Linear(in_features=32, out_features=1, bias=True)
)
In [13]:
Out[13]:
Epochs: 0 | epoch avg. loss: 0.42 | validation avg. loss: 0.15
Epochs: 1 | epoch avg. loss: 0.14 | validation avg. loss: 0.14
Epochs: 2 | epoch avg. loss: 0.11 | validation avg. loss: 0.08
Epochs: 3 | epoch avg. loss: 0.10 | validation avg. loss: 0.19
In [14]:
In [15]:
Out[15]:
Text(0.5, 0, 'Isotropic polarizability')
Other GNN layers and recent developments
Spectral graph convolutions
Pooling
In [16]:
Out[16]:
Normalization
Pointers to advanced graph neural network literature
Summary
Readers may ignore the next cell.
In [1]:
Out[1]:
[NbConvertApp] WARNING | Config option `kernel_spec_manager_class` not recognized by `NbConvertApp`.
[NbConvertApp] Converting notebook ch18_part2.ipynb to script
[NbConvertApp] Writing 5365 bytes to ch18_part2.py