utkarsh1797 commited on
Commit
38a4de1
·
verified ·
1 Parent(s): 4530c79

Upload Anonymous_Walk_Embeddings.ipynb

Browse files
Files changed (1) hide show
  1. Anonymous_Walk_Embeddings.ipynb +591 -0
Anonymous_Walk_Embeddings.ipynb ADDED
@@ -0,0 +1,591 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "markdown",
5
+ "metadata": {
6
+ "id": "2eq2Z1JGYLy7"
7
+ },
8
+ "source": [
9
+ "Assignment 2 : Create ML model based on Anonymous Walk Embeddings for node level prediction"
10
+ ]
11
+ },
12
+ {
13
+ "cell_type": "markdown",
14
+ "source": [
15
+ "- Pramod Manohar Dalavi - 2023aa05398@wilp.bits-pilani.ac.in\n",
16
+ "- Utkarsh Kumar Verma - 2023ab05014@wilp.bits-pilani.ac.in\n",
17
+ "- Ankita Laxmikant Bahirat - 2023aa05952@wilp.bits-pilani.ac.in\n",
18
+ "- Charu Mathur - 2023aa05055@wilp.bits-pilani.ac.in\n",
19
+ "- K Mamatha - 2023ab05018@wilp.bits-pilani.ac.in"
20
+ ],
21
+ "metadata": {
22
+ "id": "UZPVjT1hwxOF"
23
+ }
24
+ },
25
+ {
26
+ "cell_type": "markdown",
27
+ "metadata": {
28
+ "id": "QKRg53KHYUGc"
29
+ },
30
+ "source": [
31
+ "Generate Graph Embeddings"
32
+ ]
33
+ },
34
+ {
35
+ "cell_type": "code",
36
+ "execution_count": null,
37
+ "metadata": {
38
+ "colab": {
39
+ "base_uri": "https://localhost:8080/"
40
+ },
41
+ "id": "S0YbS1rMYKQg",
42
+ "outputId": "57474ad6-f275-424a-e3ca-01cb32fea82e"
43
+ },
44
+ "outputs": [
45
+ {
46
+ "output_type": "stream",
47
+ "name": "stdout",
48
+ "text": [
49
+ "[[0, 1, 2, 0, 3], [0, 1, 2, 3, 2], [0, 1, 2, 3, 2], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 2, 1, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 1], [0, 1, 2, 3, 2], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 2], [0, 1, 2, 0, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 0], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 1], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 0], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 0, 1, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 0, 2], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 2], [0, 1, 2, 3, 2], [0, 1, 0, 2, 0], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 1], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 0, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 0], [0, 1, 2, 3, 2], [0, 1, 0, 2, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 0, 2], [0, 1, 0, 1, 2], [0, 1, 2, 3, 1], [0, 1, 0, 1, 2], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 1, 3], [0, 1, 2, 1, 3], [0, 1, 2, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 2], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 2], [0, 1, 2, 1, 3], [0, 1, 2, 1, 2], [0, 1, 0, 1, 0], [0, 1, 2, 1, 0], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 1], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 0, 2], [0, 1, 2, 3, 4], [0, 1, 2, 0, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 1], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 0, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 0, 1, 2], [0, 1, 2, 1, 3], [0, 1, 2, 3, 0], [0, 1, 0, 2, 3], [0, 1, 2, 3, 0], [0, 1, 0, 1, 0], [0, 1, 2, 0, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 0], [0, 1, 2, 0, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 0, 1, 0], [0, 1, 2, 1, 0], [0, 1, 2, 1, 0], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 2, 1, 2], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 1, 3], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 0], [0, 1, 2, 3, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 1, 0], [0, 1, 2, 3, 4], [0, 1, 2, 1, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 1, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 1], [0, 1, 2, 1, 3], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 0, 2, 0], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 2, 1, 0], [0, 1, 0, 2, 3], [0, 1, 2, 3, 1], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 0, 2, 0], [0, 1, 2, 3, 2], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 0, 1, 0], [0, 1, 2, 1, 3], [0, 1, 0, 2, 3], [0, 1, 0, 1, 2], [0, 1, 2, 3, 1], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 1], [0, 1, 0, 2, 0], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 0, 2, 1], [0, 1, 0, 2, 0], [0, 1, 0, 2, 3], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 0], [0, 1, 2, 3, 4], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 0, 1], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 1], [0, 1, 2, 3, 2], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 1, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2], [0, 1, 0, 2, 3], [0, 1, 2, 1, 2], [0, 1, 0, 2, 3], [0, 1, 2, 3, 4], [0, 1, 2, 3, 2]]\n"
50
+ ]
51
+ }
52
+ ],
53
+ "source": [
54
+ "import networkx as nx\n",
55
+ "import numpy as np\n",
56
+ "\n",
57
+ "def generate_anonymous_walks(graph, walk_length, num_walks):\n",
58
+ " walks = []\n",
59
+ " for _ in range(num_walks):\n",
60
+ " for node in graph.nodes():\n",
61
+ " walk = [node]\n",
62
+ " for _ in range(walk_length - 1):\n",
63
+ " neighbors = list(graph.neighbors(walk[-1]))\n",
64
+ " if neighbors:\n",
65
+ " walk.append(np.random.choice(neighbors))\n",
66
+ " else:\n",
67
+ " break\n",
68
+ " walks.append(walk)\n",
69
+ " return walks\n",
70
+ "\n",
71
+ "def anonymous_walk_embedding(graph, walk_length=5, num_walks=10):\n",
72
+ " walks = generate_anonymous_walks(graph, walk_length, num_walks)\n",
73
+ " # Convert walks to anonymous walks\n",
74
+ " anon_walks = []\n",
75
+ " for walk in walks:\n",
76
+ " anon_walk = []\n",
77
+ " mapping = {}\n",
78
+ " next_id = 0\n",
79
+ " for node in walk:\n",
80
+ " if node not in mapping:\n",
81
+ " mapping[node] = next_id\n",
82
+ " next_id += 1\n",
83
+ " anon_walk.append(mapping[node])\n",
84
+ " anon_walks.append(anon_walk)\n",
85
+ " return anon_walks\n",
86
+ "\n",
87
+ "# Example usage\n",
88
+ "G = nx.karate_club_graph()\n",
89
+ "embeddings = anonymous_walk_embedding(G)\n",
90
+ "print(embeddings)"
91
+ ]
92
+ },
93
+ {
94
+ "cell_type": "markdown",
95
+ "metadata": {
96
+ "id": "fgMkAPGpYX7A"
97
+ },
98
+ "source": [
99
+ "Dataset Preparation"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": null,
105
+ "metadata": {
106
+ "colab": {
107
+ "base_uri": "https://localhost:8080/"
108
+ },
109
+ "id": "4eiZ0-p0Y_HY",
110
+ "outputId": "573d7c65-b94d-4168-90c8-48429fa837e6"
111
+ },
112
+ "outputs": [
113
+ {
114
+ "output_type": "stream",
115
+ "name": "stdout",
116
+ "text": [
117
+ "Collecting ogb\n",
118
+ " Downloading ogb-1.3.6-py3-none-any.whl.metadata (6.2 kB)\n",
119
+ "Requirement already satisfied: torch>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.5.1+cu124)\n",
120
+ "Requirement already satisfied: numpy>=1.16.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.26.4)\n",
121
+ "Requirement already satisfied: tqdm>=4.29.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (4.67.1)\n",
122
+ "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.6.1)\n",
123
+ "Requirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.2.2)\n",
124
+ "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.17.0)\n",
125
+ "Requirement already satisfied: urllib3>=1.24.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.3.0)\n",
126
+ "Collecting outdated>=0.2.0 (from ogb)\n",
127
+ " Downloading outdated-0.2.2-py2.py3-none-any.whl.metadata (4.7 kB)\n",
128
+ "Requirement already satisfied: setuptools>=44 in /usr/local/lib/python3.11/dist-packages (from outdated>=0.2.0->ogb) (75.1.0)\n",
129
+ "Collecting littleutils (from outdated>=0.2.0->ogb)\n",
130
+ " Downloading littleutils-0.2.4-py3-none-any.whl.metadata (679 bytes)\n",
131
+ "Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from outdated>=0.2.0->ogb) (2.32.3)\n",
132
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2.8.2)\n",
133
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2025.1)\n",
134
+ "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2025.1)\n",
135
+ "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (1.14.1)\n",
136
+ "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (1.4.2)\n",
137
+ "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (3.5.0)\n",
138
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.17.0)\n",
139
+ "Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (4.12.2)\n",
140
+ "Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.4.2)\n",
141
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.1.6)\n",
142
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (2024.10.0)\n",
143
+ "Collecting nvidia-cuda-nvrtc-cu12==12.4.127 (from torch>=1.6.0->ogb)\n",
144
+ " Downloading nvidia_cuda_nvrtc_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
145
+ "Collecting nvidia-cuda-runtime-cu12==12.4.127 (from torch>=1.6.0->ogb)\n",
146
+ " Downloading nvidia_cuda_runtime_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
147
+ "Collecting nvidia-cuda-cupti-cu12==12.4.127 (from torch>=1.6.0->ogb)\n",
148
+ " Downloading nvidia_cuda_cupti_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\n",
149
+ "Collecting nvidia-cudnn-cu12==9.1.0.70 (from torch>=1.6.0->ogb)\n",
150
+ " Downloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\n",
151
+ "Collecting nvidia-cublas-cu12==12.4.5.8 (from torch>=1.6.0->ogb)\n",
152
+ " Downloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
153
+ "Collecting nvidia-cufft-cu12==11.2.1.3 (from torch>=1.6.0->ogb)\n",
154
+ " Downloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
155
+ "Collecting nvidia-curand-cu12==10.3.5.147 (from torch>=1.6.0->ogb)\n",
156
+ " Downloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
157
+ "Collecting nvidia-cusolver-cu12==11.6.1.9 (from torch>=1.6.0->ogb)\n",
158
+ " Downloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\n",
159
+ "Collecting nvidia-cusparse-cu12==12.3.1.170 (from torch>=1.6.0->ogb)\n",
160
+ " Downloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl.metadata (1.6 kB)\n",
161
+ "Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (2.21.5)\n",
162
+ "Requirement already satisfied: nvidia-nvtx-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
163
+ "Collecting nvidia-nvjitlink-cu12==12.4.127 (from torch>=1.6.0->ogb)\n",
164
+ " Downloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl.metadata (1.5 kB)\n",
165
+ "Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.1.0)\n",
166
+ "Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (1.13.1)\n",
167
+ "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch>=1.6.0->ogb) (1.3.0)\n",
168
+ "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch>=1.6.0->ogb) (3.0.2)\n",
169
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->outdated>=0.2.0->ogb) (3.4.1)\n",
170
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->outdated>=0.2.0->ogb) (3.10)\n",
171
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->outdated>=0.2.0->ogb) (2025.1.31)\n",
172
+ "Downloading ogb-1.3.6-py3-none-any.whl (78 kB)\n",
173
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m78.8/78.8 kB\u001b[0m \u001b[31m2.1 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
174
+ "\u001b[?25hDownloading outdated-0.2.2-py2.py3-none-any.whl (7.5 kB)\n",
175
+ "Downloading nvidia_cublas_cu12-12.4.5.8-py3-none-manylinux2014_x86_64.whl (363.4 MB)\n",
176
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m363.4/363.4 MB\u001b[0m \u001b[31m4.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
177
+ "\u001b[?25hDownloading nvidia_cuda_cupti_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (13.8 MB)\n",
178
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m13.8/13.8 MB\u001b[0m \u001b[31m62.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
179
+ "\u001b[?25hDownloading nvidia_cuda_nvrtc_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (24.6 MB)\n",
180
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m24.6/24.6 MB\u001b[0m \u001b[31m48.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
181
+ "\u001b[?25hDownloading nvidia_cuda_runtime_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (883 kB)\n",
182
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m883.7/883.7 kB\u001b[0m \u001b[31m35.6 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
183
+ "\u001b[?25hDownloading nvidia_cudnn_cu12-9.1.0.70-py3-none-manylinux2014_x86_64.whl (664.8 MB)\n",
184
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m664.8/664.8 MB\u001b[0m \u001b[31m2.7 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
185
+ "\u001b[?25hDownloading nvidia_cufft_cu12-11.2.1.3-py3-none-manylinux2014_x86_64.whl (211.5 MB)\n",
186
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m211.5/211.5 MB\u001b[0m \u001b[31m6.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
187
+ "\u001b[?25hDownloading nvidia_curand_cu12-10.3.5.147-py3-none-manylinux2014_x86_64.whl (56.3 MB)\n",
188
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m56.3/56.3 MB\u001b[0m \u001b[31m13.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
189
+ "\u001b[?25hDownloading nvidia_cusolver_cu12-11.6.1.9-py3-none-manylinux2014_x86_64.whl (127.9 MB)\n",
190
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m127.9/127.9 MB\u001b[0m \u001b[31m7.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
191
+ "\u001b[?25hDownloading nvidia_cusparse_cu12-12.3.1.170-py3-none-manylinux2014_x86_64.whl (207.5 MB)\n",
192
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m207.5/207.5 MB\u001b[0m \u001b[31m6.3 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
193
+ "\u001b[?25hDownloading nvidia_nvjitlink_cu12-12.4.127-py3-none-manylinux2014_x86_64.whl (21.1 MB)\n",
194
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m21.1/21.1 MB\u001b[0m \u001b[31m83.4 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
195
+ "\u001b[?25hDownloading littleutils-0.2.4-py3-none-any.whl (8.1 kB)\n",
196
+ "Installing collected packages: nvidia-nvjitlink-cu12, nvidia-curand-cu12, nvidia-cufft-cu12, nvidia-cuda-runtime-cu12, nvidia-cuda-nvrtc-cu12, nvidia-cuda-cupti-cu12, nvidia-cublas-cu12, littleutils, outdated, nvidia-cusparse-cu12, nvidia-cudnn-cu12, nvidia-cusolver-cu12, ogb\n",
197
+ " Attempting uninstall: nvidia-nvjitlink-cu12\n",
198
+ " Found existing installation: nvidia-nvjitlink-cu12 12.5.82\n",
199
+ " Uninstalling nvidia-nvjitlink-cu12-12.5.82:\n",
200
+ " Successfully uninstalled nvidia-nvjitlink-cu12-12.5.82\n",
201
+ " Attempting uninstall: nvidia-curand-cu12\n",
202
+ " Found existing installation: nvidia-curand-cu12 10.3.6.82\n",
203
+ " Uninstalling nvidia-curand-cu12-10.3.6.82:\n",
204
+ " Successfully uninstalled nvidia-curand-cu12-10.3.6.82\n",
205
+ " Attempting uninstall: nvidia-cufft-cu12\n",
206
+ " Found existing installation: nvidia-cufft-cu12 11.2.3.61\n",
207
+ " Uninstalling nvidia-cufft-cu12-11.2.3.61:\n",
208
+ " Successfully uninstalled nvidia-cufft-cu12-11.2.3.61\n",
209
+ " Attempting uninstall: nvidia-cuda-runtime-cu12\n",
210
+ " Found existing installation: nvidia-cuda-runtime-cu12 12.5.82\n",
211
+ " Uninstalling nvidia-cuda-runtime-cu12-12.5.82:\n",
212
+ " Successfully uninstalled nvidia-cuda-runtime-cu12-12.5.82\n",
213
+ " Attempting uninstall: nvidia-cuda-nvrtc-cu12\n",
214
+ " Found existing installation: nvidia-cuda-nvrtc-cu12 12.5.82\n",
215
+ " Uninstalling nvidia-cuda-nvrtc-cu12-12.5.82:\n",
216
+ " Successfully uninstalled nvidia-cuda-nvrtc-cu12-12.5.82\n",
217
+ " Attempting uninstall: nvidia-cuda-cupti-cu12\n",
218
+ " Found existing installation: nvidia-cuda-cupti-cu12 12.5.82\n",
219
+ " Uninstalling nvidia-cuda-cupti-cu12-12.5.82:\n",
220
+ " Successfully uninstalled nvidia-cuda-cupti-cu12-12.5.82\n",
221
+ " Attempting uninstall: nvidia-cublas-cu12\n",
222
+ " Found existing installation: nvidia-cublas-cu12 12.5.3.2\n",
223
+ " Uninstalling nvidia-cublas-cu12-12.5.3.2:\n",
224
+ " Successfully uninstalled nvidia-cublas-cu12-12.5.3.2\n",
225
+ " Attempting uninstall: nvidia-cusparse-cu12\n",
226
+ " Found existing installation: nvidia-cusparse-cu12 12.5.1.3\n",
227
+ " Uninstalling nvidia-cusparse-cu12-12.5.1.3:\n",
228
+ " Successfully uninstalled nvidia-cusparse-cu12-12.5.1.3\n",
229
+ " Attempting uninstall: nvidia-cudnn-cu12\n",
230
+ " Found existing installation: nvidia-cudnn-cu12 9.3.0.75\n",
231
+ " Uninstalling nvidia-cudnn-cu12-9.3.0.75:\n",
232
+ " Successfully uninstalled nvidia-cudnn-cu12-9.3.0.75\n",
233
+ " Attempting uninstall: nvidia-cusolver-cu12\n",
234
+ " Found existing installation: nvidia-cusolver-cu12 11.6.3.83\n",
235
+ " Uninstalling nvidia-cusolver-cu12-11.6.3.83:\n",
236
+ " Successfully uninstalled nvidia-cusolver-cu12-11.6.3.83\n",
237
+ "Successfully installed littleutils-0.2.4 nvidia-cublas-cu12-12.4.5.8 nvidia-cuda-cupti-cu12-12.4.127 nvidia-cuda-nvrtc-cu12-12.4.127 nvidia-cuda-runtime-cu12-12.4.127 nvidia-cudnn-cu12-9.1.0.70 nvidia-cufft-cu12-11.2.1.3 nvidia-curand-cu12-10.3.5.147 nvidia-cusolver-cu12-11.6.1.9 nvidia-cusparse-cu12-12.3.1.170 nvidia-nvjitlink-cu12-12.4.127 ogb-1.3.6 outdated-0.2.2\n",
238
+ "Requirement already satisfied: ogb in /usr/local/lib/python3.11/dist-packages (1.3.6)\n",
239
+ "Collecting torch-geometric\n",
240
+ " Downloading torch_geometric-2.6.1-py3-none-any.whl.metadata (63 kB)\n",
241
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m63.1/63.1 kB\u001b[0m \u001b[31m2.0 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
242
+ "\u001b[?25hRequirement already satisfied: torch>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.5.1+cu124)\n",
243
+ "Requirement already satisfied: numpy>=1.16.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.26.4)\n",
244
+ "Requirement already satisfied: tqdm>=4.29.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (4.67.1)\n",
245
+ "Requirement already satisfied: scikit-learn>=0.20.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.6.1)\n",
246
+ "Requirement already satisfied: pandas>=0.24.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.2.2)\n",
247
+ "Requirement already satisfied: six>=1.12.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (1.17.0)\n",
248
+ "Requirement already satisfied: urllib3>=1.24.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (2.3.0)\n",
249
+ "Requirement already satisfied: outdated>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from ogb) (0.2.2)\n",
250
+ "Requirement already satisfied: aiohttp in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (3.11.13)\n",
251
+ "Requirement already satisfied: fsspec in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (2024.10.0)\n",
252
+ "Requirement already satisfied: jinja2 in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (3.1.6)\n",
253
+ "Requirement already satisfied: psutil>=5.8.0 in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (5.9.5)\n",
254
+ "Requirement already satisfied: pyparsing in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (3.2.1)\n",
255
+ "Requirement already satisfied: requests in /usr/local/lib/python3.11/dist-packages (from torch-geometric) (2.32.3)\n",
256
+ "Requirement already satisfied: setuptools>=44 in /usr/local/lib/python3.11/dist-packages (from outdated>=0.2.0->ogb) (75.1.0)\n",
257
+ "Requirement already satisfied: littleutils in /usr/local/lib/python3.11/dist-packages (from outdated>=0.2.0->ogb) (0.2.4)\n",
258
+ "Requirement already satisfied: python-dateutil>=2.8.2 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2.8.2)\n",
259
+ "Requirement already satisfied: pytz>=2020.1 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2025.1)\n",
260
+ "Requirement already satisfied: tzdata>=2022.7 in /usr/local/lib/python3.11/dist-packages (from pandas>=0.24.0->ogb) (2025.1)\n",
261
+ "Requirement already satisfied: scipy>=1.6.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (1.14.1)\n",
262
+ "Requirement already satisfied: joblib>=1.2.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (1.4.2)\n",
263
+ "Requirement already satisfied: threadpoolctl>=3.1.0 in /usr/local/lib/python3.11/dist-packages (from scikit-learn>=0.20.0->ogb) (3.5.0)\n",
264
+ "Requirement already satisfied: filelock in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.17.0)\n",
265
+ "Requirement already satisfied: typing-extensions>=4.8.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (4.12.2)\n",
266
+ "Requirement already satisfied: networkx in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.4.2)\n",
267
+ "Requirement already satisfied: nvidia-cuda-nvrtc-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
268
+ "Requirement already satisfied: nvidia-cuda-runtime-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
269
+ "Requirement already satisfied: nvidia-cuda-cupti-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
270
+ "Requirement already satisfied: nvidia-cudnn-cu12==9.1.0.70 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (9.1.0.70)\n",
271
+ "Requirement already satisfied: nvidia-cublas-cu12==12.4.5.8 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.5.8)\n",
272
+ "Requirement already satisfied: nvidia-cufft-cu12==11.2.1.3 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (11.2.1.3)\n",
273
+ "Requirement already satisfied: nvidia-curand-cu12==10.3.5.147 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (10.3.5.147)\n",
274
+ "Requirement already satisfied: nvidia-cusolver-cu12==11.6.1.9 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (11.6.1.9)\n",
275
+ "Requirement already satisfied: nvidia-cusparse-cu12==12.3.1.170 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.3.1.170)\n",
276
+ "Requirement already satisfied: nvidia-nccl-cu12==2.21.5 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (2.21.5)\n",
277
+ "Requirement already satisfied: nvidia-nvtx-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
278
+ "Requirement already satisfied: nvidia-nvjitlink-cu12==12.4.127 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (12.4.127)\n",
279
+ "Requirement already satisfied: triton==3.1.0 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (3.1.0)\n",
280
+ "Requirement already satisfied: sympy==1.13.1 in /usr/local/lib/python3.11/dist-packages (from torch>=1.6.0->ogb) (1.13.1)\n",
281
+ "Requirement already satisfied: mpmath<1.4,>=1.1.0 in /usr/local/lib/python3.11/dist-packages (from sympy==1.13.1->torch>=1.6.0->ogb) (1.3.0)\n",
282
+ "Requirement already satisfied: aiohappyeyeballs>=2.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (2.5.0)\n",
283
+ "Requirement already satisfied: aiosignal>=1.1.2 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (1.3.2)\n",
284
+ "Requirement already satisfied: attrs>=17.3.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (25.1.0)\n",
285
+ "Requirement already satisfied: frozenlist>=1.1.1 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (1.5.0)\n",
286
+ "Requirement already satisfied: multidict<7.0,>=4.5 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (6.1.0)\n",
287
+ "Requirement already satisfied: propcache>=0.2.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (0.3.0)\n",
288
+ "Requirement already satisfied: yarl<2.0,>=1.17.0 in /usr/local/lib/python3.11/dist-packages (from aiohttp->torch-geometric) (1.18.3)\n",
289
+ "Requirement already satisfied: MarkupSafe>=2.0 in /usr/local/lib/python3.11/dist-packages (from jinja2->torch-geometric) (3.0.2)\n",
290
+ "Requirement already satisfied: charset-normalizer<4,>=2 in /usr/local/lib/python3.11/dist-packages (from requests->torch-geometric) (3.4.1)\n",
291
+ "Requirement already satisfied: idna<4,>=2.5 in /usr/local/lib/python3.11/dist-packages (from requests->torch-geometric) (3.10)\n",
292
+ "Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.11/dist-packages (from requests->torch-geometric) (2025.1.31)\n",
293
+ "Downloading torch_geometric-2.6.1-py3-none-any.whl (1.1 MB)\n",
294
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m1.1/1.1 MB\u001b[0m \u001b[31m22.5 MB/s\u001b[0m eta \u001b[36m0:00:00\u001b[0m\n",
295
+ "\u001b[?25hInstalling collected packages: torch-geometric\n",
296
+ "Successfully installed torch-geometric-2.6.1\n",
297
+ "1.3.6\n",
298
+ "2.6.1\n"
299
+ ]
300
+ }
301
+ ],
302
+ "source": [
303
+ "!pip install ogb\n",
304
+ "!pip install ogb torch-geometric\n",
305
+ "import ogb\n",
306
+ "import torch_geometric\n",
307
+ "\n",
308
+ "print(ogb.__version__)\n",
309
+ "print(torch_geometric.__version__)"
310
+ ]
311
+ },
312
+ {
313
+ "cell_type": "code",
314
+ "execution_count": null,
315
+ "metadata": {
316
+ "colab": {
317
+ "base_uri": "https://localhost:8080/"
318
+ },
319
+ "id": "4B8MF6xVZ6qa",
320
+ "outputId": "30a2c8a5-15f6-4304-a8ec-2bacddefb7a2"
321
+ },
322
+ "outputs": [
323
+ {
324
+ "output_type": "stream",
325
+ "name": "stdout",
326
+ "text": [
327
+ "1.3.6\n",
328
+ "2.6.1\n"
329
+ ]
330
+ }
331
+ ],
332
+ "source": [
333
+ "import ogb\n",
334
+ "import torch_geometric\n",
335
+ "\n",
336
+ "print(ogb.__version__)\n",
337
+ "print(torch_geometric.__version__)"
338
+ ]
339
+ },
340
+ {
341
+ "cell_type": "code",
342
+ "execution_count": null,
343
+ "metadata": {
344
+ "colab": {
345
+ "base_uri": "https://localhost:8080/"
346
+ },
347
+ "id": "mAQtd8gjaBb0",
348
+ "outputId": "e948110b-f189-4696-bf8a-437ec7ddab3e"
349
+ },
350
+ "outputs": [
351
+ {
352
+ "metadata": {
353
+ "tags": null
354
+ },
355
+ "name": "stdout",
356
+ "output_type": "stream",
357
+ "text": [
358
+ "Found existing installation: ogb 1.3.6\n",
359
+ "Uninstalling ogb-1.3.6:\n",
360
+ " Would remove:\n",
361
+ " /usr/local/lib/python3.11/dist-packages/ogb-1.3.6.dist-info/*\n",
362
+ " /usr/local/lib/python3.11/dist-packages/ogb/*\n",
363
+ "Proceed (Y/n)? "
364
+ ]
365
+ }
366
+ ],
367
+ "source": [
368
+ "#!pip uninstall ogb torch-geometric\n",
369
+ "#!pip install ogb torch-geometric"
370
+ ]
371
+ },
372
+ {
373
+ "cell_type": "code",
374
+ "execution_count": null,
375
+ "metadata": {
376
+ "id": "ZKT-dMUbYZj1"
377
+ },
378
+ "outputs": [],
379
+ "source": [
380
+ "import torch\n",
381
+ "from ogb.graphproppred import PygGraphPropPredDataset\n",
382
+ "from torch_geometric.data import DataLoader\n",
383
+ "\n",
384
+ "# Load dataset\n",
385
+ "dataset = PygGraphPropPredDataset(name=\"ogbg-molhiv\")\n",
386
+ "split_idx = dataset.get_idx_split()\n",
387
+ "train_loader = DataLoader(dataset[split_idx[\"train\"]], batch_size=32, shuffle=True)\n",
388
+ "valid_loader = DataLoader(dataset[split_idx[\"valid\"]], batch_size=32, shuffle=False)\n",
389
+ "test_loader = DataLoader(dataset[split_idx[\"test\"]], batch_size=32, shuffle=False)"
390
+ ]
391
+ },
392
+ {
393
+ "cell_type": "markdown",
394
+ "metadata": {
395
+ "id": "pdNjBmBJYcOP"
396
+ },
397
+ "source": [
398
+ "Neural Network Model"
399
+ ]
400
+ },
401
+ {
402
+ "cell_type": "code",
403
+ "execution_count": null,
404
+ "metadata": {
405
+ "id": "5tTY5vQ3Yd3y"
406
+ },
407
+ "outputs": [],
408
+ "source": [
409
+ "import torch\n",
410
+ "from torch_geometric.nn import GCNConv, global_mean_pool\n",
411
+ "\n",
412
+ "class GNN(torch.nn.Module):\n",
413
+ " def __init__(self, hidden_channels):\n",
414
+ " super(GNN, self).__init__() # Call the parent class's __init__ method\n",
415
+ " self.conv1 = GCNConv(dataset.num_node_features, hidden_channels)\n",
416
+ " self.conv2 = GCNConv(hidden_channels, hidden_channels)\n",
417
+ " self.lin = torch.nn.Linear(hidden_channels, dataset.num_tasks)\n",
418
+ "\n",
419
+ " def forward(self, x, edge_index, batch):\n",
420
+ " x = self.conv1(x, edge_index).relu()\n",
421
+ " x = self.conv2(x, edge_index).relu()\n",
422
+ " x = global_mean_pool(x, batch) # Global pooling\n",
423
+ " x = self.lin(x)\n",
424
+ " return x\n",
425
+ "\n",
426
+ "model = GNN(hidden_channels=64)"
427
+ ]
428
+ },
429
+ {
430
+ "cell_type": "markdown",
431
+ "metadata": {
432
+ "id": "Ot4ypsx1YgBq"
433
+ },
434
+ "source": [
435
+ "Model Optimization"
436
+ ]
437
+ },
438
+ {
439
+ "cell_type": "code",
440
+ "execution_count": null,
441
+ "metadata": {
442
+ "id": "ldHLgvdJYh86"
443
+ },
444
+ "outputs": [],
445
+ "source": [
446
+ "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n",
447
+ "criterion = torch.nn.BCEWithLogitsLoss()\n",
448
+ "\n",
449
+ "def train():\n",
450
+ " model.train()\n",
451
+ " for data in train_loader:\n",
452
+ " optimizer.zero_grad()\n",
453
+ " out = model(data.x, data.edge_index, data.batch)\n",
454
+ " loss = criterion(out, data.y.float())\n",
455
+ " loss.backward()\n",
456
+ " optimizer.step()"
457
+ ]
458
+ },
459
+ {
460
+ "cell_type": "markdown",
461
+ "metadata": {
462
+ "id": "9MWIVvcRYlpB"
463
+ },
464
+ "source": [
465
+ "Evaluation"
466
+ ]
467
+ },
468
+ {
469
+ "cell_type": "code",
470
+ "execution_count": null,
471
+ "metadata": {
472
+ "id": "Ui9ln9PlbzZD"
473
+ },
474
+ "outputs": [],
475
+ "source": [
476
+ "# Inspect the first element of the dataset\n",
477
+ "sample_data = dataset[0]\n",
478
+ "print(sample_data)"
479
+ ]
480
+ },
481
+ {
482
+ "cell_type": "code",
483
+ "execution_count": null,
484
+ "metadata": {
485
+ "colab": {
486
+ "background_save": true
487
+ },
488
+ "id": "J-gzaiejcpvx"
489
+ },
490
+ "outputs": [],
491
+ "source": [
492
+ "import torch\n",
493
+ "from ogb.graphproppred import GraphPropPredDataset, Evaluator\n",
494
+ "from torch_geometric.data import DataLoader, Data\n",
495
+ "from torch_geometric.nn import GCNConv, global_mean_pool\n",
496
+ "\n",
497
+ "# Load dataset\n",
498
+ "dataset = GraphPropPredDataset(name=\"ogbg-molhiv\")\n",
499
+ "split_idx = dataset.get_idx_split()\n",
500
+ "\n",
501
+ "# Convert split indices to lists of integers\n",
502
+ "train_idx = split_idx[\"train\"].tolist()\n",
503
+ "valid_idx = split_idx[\"valid\"].tolist()\n",
504
+ "test_idx = split_idx[\"test\"].tolist()\n",
505
+ "\n",
506
+ "# Convert dataset to PyTorch Geometric Data objects\n",
507
+ "def convert_to_pyg_data(data_dict, label):\n",
508
+ " return Data(\n",
509
+ " x=torch.tensor(data_dict['node_feat'], dtype=torch.float),\n",
510
+ " edge_index=torch.tensor(data_dict['edge_index'], dtype=torch.long),\n",
511
+ " edge_attr=torch.tensor(data_dict['edge_feat'], dtype=torch.float),\n",
512
+ " y=torch.tensor(label, dtype=torch.float).view(-1, 1) # Reshape the label\n",
513
+ " )\n",
514
+ "\n",
515
+ "train_data = [convert_to_pyg_data(dataset[i][0], dataset[i][1]) for i in train_idx]\n",
516
+ "valid_data = [convert_to_pyg_data(dataset[i][0], dataset[i][1]) for i in valid_idx]\n",
517
+ "test_data = [convert_to_pyg_data(dataset[i][0], dataset[i][1]) for i in test_idx]\n",
518
+ "\n",
519
+ "train_loader = DataLoader(train_data, batch_size=32, shuffle=True)\n",
520
+ "valid_loader = DataLoader(valid_data, batch_size=32, shuffle=False)\n",
521
+ "test_loader = DataLoader(test_data, batch_size=32, shuffle=False)\n",
522
+ "\n",
523
+ "# Determine the number of node features\n",
524
+ "num_node_features = train_data[0].x.shape[1]\n",
525
+ "num_tasks = dataset.num_tasks\n",
526
+ "\n",
527
+ "class GNN(torch.nn.Module):\n",
528
+ " def __init__(self, hidden_channels):\n",
529
+ " super(GNN, self).__init__()\n",
530
+ " self.conv1 = GCNConv(num_node_features, hidden_channels)\n",
531
+ " self.conv2 = GCNConv(hidden_channels, hidden_channels)\n",
532
+ " self.lin = torch.nn.Linear(hidden_channels, num_tasks)\n",
533
+ "\n",
534
+ " def forward(self, x, edge_index, batch):\n",
535
+ " x = self.conv1(x, edge_index).relu()\n",
536
+ " x = self.conv2(x, edge_index).relu()\n",
537
+ " x = global_mean_pool(x, batch) # Global pooling\n",
538
+ " x = self.lin(x)\n",
539
+ " return x\n",
540
+ "\n",
541
+ "model = GNN(hidden_channels=64)\n",
542
+ "optimizer = torch.optim.Adam(model.parameters(), lr=0.01)\n",
543
+ "criterion = torch.nn.BCEWithLogitsLoss()\n",
544
+ "\n",
545
+ "# Training loop\n",
546
+ "def train():\n",
547
+ " model.train()\n",
548
+ " for data in train_loader:\n",
549
+ " optimizer.zero_grad()\n",
550
+ " out = model(data.x, data.edge_index, data.batch)\n",
551
+ " loss = criterion(out, data.y)\n",
552
+ " loss.backward()\n",
553
+ " optimizer.step()\n",
554
+ "\n",
555
+ "# Evaluation\n",
556
+ "def evaluate(loader):\n",
557
+ " model.eval()\n",
558
+ " y_true = []\n",
559
+ " y_pred = []\n",
560
+ " for data in loader:\n",
561
+ " with torch.no_grad():\n",
562
+ " out = model(data.x, data.edge_index, data.batch)\n",
563
+ " y_true.append(data.y.view(-1, 1).cpu())\n",
564
+ " y_pred.append(out.view(-1, 1).cpu())\n",
565
+ " y_true = torch.cat(y_true, dim=0).numpy()\n",
566
+ " y_pred = torch.cat(y_pred, dim=0).numpy()\n",
567
+ " return evaluator.eval({\"y_true\": y_true, \"y_pred\": y_pred})[\"rocauc\"]\n",
568
+ "\n",
569
+ "evaluator = Evaluator(name=\"ogbg-molhiv\")\n",
570
+ "for epoch in range(1, 101):\n",
571
+ " train()\n",
572
+ " valid_rocauc = evaluate(valid_loader)\n",
573
+ " print(f'Epoch: {epoch:03d}, Validation ROC-AUC: {valid_rocauc:.4f}')"
574
+ ]
575
+ }
576
+ ],
577
+ "metadata": {
578
+ "colab": {
579
+ "provenance": []
580
+ },
581
+ "kernelspec": {
582
+ "display_name": "Python 3",
583
+ "name": "python3"
584
+ },
585
+ "language_info": {
586
+ "name": "python"
587
+ }
588
+ },
589
+ "nbformat": 4,
590
+ "nbformat_minor": 0
591
+ }