Notebooks
G
Google
Ogbg Molpcba

Ogbg Molpcba

jaxexamplesogbg_molpcbaflax

Flax ogbg-molpcba Example

Open In Colab

Demonstration notebook for https://github.com/google/flax/tree/main/examples/ogbg_molpcba.

Setup

[1]
     |████████████████████████████████| 77 kB 2.7 MB/s 
     |████████████████████████████████| 88 kB 5.5 MB/s 
     |████████████████████████████████| 4.0 MB 38.2 MB/s 
     |████████████████████████████████| 73 kB 1.3 MB/s 
     |████████████████████████████████| 118 kB 38.3 MB/s 
     |████████████████████████████████| 57 kB 3.6 MB/s 
  Building wheel for flax (setup.py) ... done
[2]
[3]
mount_gdrive
Cloning into 'flaxrepo'...
remote: Enumerating objects: 350, done.
remote: Counting objects: 100% (350/350), done.
remote: Compressing objects: 100% (312/312), done.
remote: Total 350 (delta 65), reused 140 (delta 20), pack-reused 0
Receiving objects: 100% (350/350), 2.10 MiB | 20.10 MiB/s, done.
Resolving deltas: 100% (65/65), done.
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
<IPython.core.display.Javascript object>
[4]
/content/examples/ogbg_molpcba

Imports

[5]
[6]

Dataset

TensorFlow Datasets supports customizable visualization of the ogbg_molpcba dataset.

[7]
[8]
INFO:absl:Load pre-computed DatasetInfo (eg: splits, num examples,...) from GCS: ogbg_molpcba/0.1.2
INFO:absl:Load dataset info from /tmp/tmpmdoxgxq7tfds
INFO:absl:Generating dataset ogbg_molpcba (/root/tensorflow_datasets/ogbg_molpcba/0.1.2)
Downloading and preparing dataset 37.70 MiB (download: 37.70 MiB, generated: 822.53 MiB, total: 860.23 MiB) to /root/tensorflow_datasets/ogbg_molpcba/0.1.2...
Dl Completed...: 0 url [00:00, ? url/s]
Dl Size...: 0 MiB [00:00, ? MiB/s]
Extraction completed...: 0 file [00:00, ? file/s]
INFO:absl:Downloading https://snap.stanford.edu/ogb/data/graphproppred/csv_mol_download/pcba.zip into /root/tensorflow_datasets/downloads/snap.stan.edu_ogb_grap_csv_mol_down_pcbapc4I82Cv1THcU-IggPHK8IHZ8qM-BJ3VDk-q_rtqrf4.zip.tmp.495be609cf3840d3a942e7f9ba5d705e...
Generating splits...:   0%|          | 0/3 [00:00<?, ? splits/s]
Generating train examples...:   0%|          | 0/350343 [00:00<?, ? examples/s]
Shuffling ogbg_molpcba-train.tfrecord...:   0%|          | 0/350343 [00:00<?, ? examples/s]
INFO:absl:Done writing ogbg_molpcba-train.tfrecord. Number of examples: 350343 (shards: [43793, 43793, 43793, 43793, 43792, 43793, 43793, 43793])
Generating validation examples...:   0%|          | 0/43793 [00:00<?, ? examples/s]
Shuffling ogbg_molpcba-validation.tfrecord...:   0%|          | 0/43793 [00:00<?, ? examples/s]
INFO:absl:Done writing ogbg_molpcba-validation.tfrecord. Number of examples: 43793 (shards: [43793])
Generating test examples...:   0%|          | 0/43793 [00:00<?, ? examples/s]
Shuffling ogbg_molpcba-test.tfrecord...:   0%|          | 0/43793 [00:00<?, ? examples/s]
INFO:absl:Done writing ogbg_molpcba-test.tfrecord. Number of examples: 43793 (shards: [43793])
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split train, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
Dataset ogbg_molpcba downloaded and prepared to /root/tensorflow_datasets/ogbg_molpcba/0.1.2. Subsequent calls will reuse this data.
OutputOutput

Training

[ ]
[10]
INFO:absl:Unable to initialize backend 'tpu_driver': NOT_FOUND: Unable to find driver in registry given worker: 
INFO:absl:Unable to initialize backend 'tpu': INVALID_ARGUMENT: TpuPlatform is not available.
INFO:absl:Hyperparameters: {'add_self_loops': True, 'add_undirected_edges': True, 'add_virtual_node': False, 'batch_size': 256, 'checkpoint_every_steps': 10000, 'dropout_rate': 0.1, 'eval_every_steps': 500, 'latent_size': 256, 'layer_norm': True, 'learning_rate': 0.001, 'log_every_steps': 500, 'message_passing_steps': 5, 'model': 'GraphConvNet', 'num_classes': 128, 'num_mlp_layers': 2, 'num_train_steps': 1000, 'optimizer': 'adam', 'skip_connections': True}
INFO:absl:Obtaining datasets.
INFO:absl:Load dataset info from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Reusing dataset ogbg_molpcba (/root/tensorflow_datasets/ogbg_molpcba/0.1.2)
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split train, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split validation, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split test, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Initializing network.
INFO:absl:
+-----------------------------+------------+--------+-----------+--------+
| Name                        | Shape      | Size   | Mean      | Std    |
+-----------------------------+------------+--------+-----------+--------+
| params/Dense_0/bias         | (256,)     | 256    | 0.0       | 0.0    |
| params/Dense_0/kernel       | (9, 256)   | 2,304  | -0.000941 | 0.335  |
| params/Dense_1/bias         | (128,)     | 128    | 0.0       | 0.0    |
| params/Dense_1/kernel       | (256, 128) | 32,768 | -0.000737 | 0.0623 |
| params/LayerNorm_0/bias     | (256,)     | 256    | 0.0       | 0.0    |
| params/LayerNorm_0/scale    | (256,)     | 256    | 1.0       | 0.0    |
| params/LayerNorm_1/bias     | (256,)     | 256    | 0.0       | 0.0    |
| params/LayerNorm_1/scale    | (256,)     | 256    | 1.0       | 0.0    |
| params/LayerNorm_2/bias     | (256,)     | 256    | 0.0       | 0.0    |
| params/LayerNorm_2/scale    | (256,)     | 256    | 1.0       | 0.0    |
| params/LayerNorm_3/bias     | (256,)     | 256    | 0.0       | 0.0    |
| params/LayerNorm_3/scale    | (256,)     | 256    | 1.0       | 0.0    |
| params/LayerNorm_4/bias     | (256,)     | 256    | 0.0       | 0.0    |
| params/LayerNorm_4/scale    | (256,)     | 256    | 1.0       | 0.0    |
| params/MLP_0/Dense_0/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_0/Dense_0/kernel | (256, 256) | 65,536 | -0.000616 | 0.0625 |
| params/MLP_0/Dense_1/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_0/Dense_1/kernel | (256, 256) | 65,536 | -0.000287 | 0.0626 |
| params/MLP_1/Dense_0/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_1/Dense_0/kernel | (256, 256) | 65,536 | 0.000217  | 0.0628 |
| params/MLP_1/Dense_1/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_1/Dense_1/kernel | (256, 256) | 65,536 | -0.00055  | 0.0625 |
| params/MLP_2/Dense_0/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_2/Dense_0/kernel | (256, 256) | 65,536 | 0.000274  | 0.0625 |
| params/MLP_2/Dense_1/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_2/Dense_1/kernel | (256, 256) | 65,536 | -0.000227 | 0.0626 |
| params/MLP_3/Dense_0/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_3/Dense_0/kernel | (256, 256) | 65,536 | -0.000224 | 0.0625 |
| params/MLP_3/Dense_1/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_3/Dense_1/kernel | (256, 256) | 65,536 | 1.42e-05  | 0.0627 |
| params/MLP_4/Dense_0/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_4/Dense_0/kernel | (256, 256) | 65,536 | 0.000319  | 0.0623 |
| params/MLP_4/Dense_1/bias   | (256,)     | 256    | 0.0       | 0.0    |
| params/MLP_4/Dense_1/kernel | (256, 256) | 65,536 | -0.000191 | 0.0624 |
+-----------------------------+------------+--------+-----------+--------+
Total: 695,936
INFO:absl:Checkpoint.restore_or_initialize() ...
INFO:absl:No checkpoint specified. Restore the latest checkpoint.
INFO:absl:Checkpoint None does not exist.
INFO:absl:Checkpoint.save() ...
INFO:absl:Checkpoint.save() finished after 0.09s.
INFO:absl:Checkpoint.restore_or_initialize() finished after 0.10s.
INFO:absl:Starting training.
INFO:absl:Finished training step 1.
INFO:absl:Finished training step 2.
INFO:absl:Finished training step 3.
INFO:absl:Finished training step 4.
INFO:absl:Finished training step 5.
INFO:absl:Finished training step 6.
INFO:absl:Finished training step 7.
INFO:absl:Finished training step 8.
INFO:absl:Finished training step 9.
INFO:absl:Finished training step 10.
INFO:absl:Created artifact [10] Profile of type ArtifactType.URL and value None.
INFO:absl:Setting work unit notes: 2.0 steps/s, 12.4% (124/1000), ETA: 7m
INFO:absl:[124] steps_per_sec=2.048078
INFO:absl:Setting work unit notes: 2.1 steps/s, 25.2% (252/1000), ETA: 5m
INFO:absl:[252] steps_per_sec=2.127820
INFO:absl:Setting work unit notes: 2.1 steps/s, 38.0% (380/1000), ETA: 4m
INFO:absl:[380] steps_per_sec=2.116415
INFO:absl:[500] train_accuracy=0.9849439859390259, train_loss=0.06188433617353439
INFO:absl:[500] validation_accuracy=0.9839196801185608, validation_loss=0.06475622951984406, validation_mean_average_precision=0.036894
INFO:absl:[500] test_accuracy=0.9832062125205994, test_loss=0.06711383163928986, test_mean_average_precision=0.037820
INFO:absl:Setting work unit notes: 0.4 steps/s, 50.1% (501/1000), ETA: 23m (8m : 31.9% eval)
INFO:absl:[501] steps_per_sec=0.351547
INFO:absl:Setting work unit notes: 2.1 steps/s, 62.8% (628/1000), ETA: 2m (9m : 28.7% eval)
INFO:absl:[628] steps_per_sec=2.109877
INFO:absl:Setting work unit notes: 2.1 steps/s, 75.6% (756/1000), ETA: 1m (10m : 26.1% eval)
INFO:absl:[756] steps_per_sec=2.128443
INFO:absl:Setting work unit notes: 2.1 steps/s, 88.4% (884/1000), ETA: 0m (11m : 23.9% eval)
INFO:absl:[884] steps_per_sec=2.122990
INFO:absl:[999] train_accuracy=0.9868282079696655, train_loss=0.052991833537817
INFO:absl:[999] validation_accuracy=0.984052836894989, validation_loss=0.06297025829553604, validation_mean_average_precision=0.049514
INFO:absl:Checkpoint.save() ...
INFO:absl:[999] test_accuracy=0.9833315014839172, test_loss=0.06533924490213394, test_mean_average_precision=0.050113
INFO:absl:Checkpoint.save() finished after 0.06s.
INFO:absl:Setting work unit notes: 1.7 steps/s, 100.0% (1000/1000), ETA: 0m (13m : 0.0% checkpoint, 22.5% eval)
INFO:absl:[1000] steps_per_sec=1.697496
INFO:absl:[1000] train_accuracy=0.9897193908691406, train_loss=0.04319273680448532
INFO:absl:[1000] validation_accuracy=0.9840479493141174, validation_loss=0.0629250779747963, validation_mean_average_precision=0.049538
INFO:absl:[1000] test_accuracy=0.9833057522773743, test_loss=0.06529100239276886, test_mean_average_precision=0.050135
[11]
upload_data

Inference

[12]
[13]
INFO:absl:Load dataset info from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Reusing dataset ogbg_molpcba (/root/tensorflow_datasets/ogbg_molpcba/0.1.2)
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split train, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split validation, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split test, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
[14]
validation
- accuracy: 0.984
- loss: 0.063
- mean_average_precision: 0.050
test
- accuracy: 0.983
- loss: 0.065
- mean_average_precision: 0.050
[15]

We can choose one of the 128 different tasks and see how the model predictions match up with the true labels.

You can change this visualization to use any of the 128 tasks in this dataset, by changing the task variable below. See the appendix here to understand what these tasks mean.

The default is task PCBA-686978 (indexed at 93).

[16]
[17]
INFO:absl:Load dataset info from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
INFO:absl:Reusing dataset ogbg_molpcba (/root/tensorflow_datasets/ogbg_molpcba/0.1.2)
INFO:absl:Constructing tf.data.Dataset ogbg_molpcba for split test, from /root/tensorflow_datasets/ogbg_molpcba/0.1.2
Output