CS224W - Colab 2
CS224W - Colab 2
In Colab 2, we will work to construct our own graph neural network using PyTorch Geometric (PyG) and then apply that model on two Open Graph Benchmark (OGB) datasets. These two datasets will be used to benchmark your model’s performance on two different graph-based tasks: 1) node property prediction, predicting properties of single nodes and 2) graph property prediction, predicting properties of entire graphs or subgraphs.
First, we will learn how PyTorch Geometric stores graphs ...
GCN 图卷积神经网络
GCN 图卷积神经网络
参考资料:
https://pyg.org/
https://networkx.org/
https://www.dgl.ai/
https://distill.pub/2021/gnn-intro/
https://distill.pub/2021/understanding-gnns/
参考视频:
https://www.bilibili.com/video/BV1Hs4y157Ls/
https://www.bilibili.com/video/BV1z14y1A7JX/
一、引入
假定我们有一个图 GGG :
VVV 是节点集合vertex set
AAA 是邻接矩阵Adjacency matrix 二进制
X∈R∣V∣×mX \in \mathbb{R}^{|V| \times m}X∈R∣V∣×m 是节点特征矩阵
1. 原始想法
最初,我们当然是希望说,是否可以直接把整个 AAA 和 XXX 拼接起来,直接整个作为输入。
但是,实际上会有很多问题:
参数量过大
输入无法适应各种大小的图
对节点顺序敏感
我们知道,在 CNN 中,是用滑动窗 ...
PageRank:《哈利·波特》人物节点重要度
PageRank:《哈利·波特》人物节点重要度
数据来源:http://data.openkg.cn/dataset/a-harry-potter-kg
0. 理论知识
G 矩阵
其中:
每个节点A的重要度由指向A 的节点B、C、D重要度决定(B/C/D 本身可能指向了多个,则均摊出去)
为了防止陷入问题,添加 Teleport 传送概率
示例
可用于推荐系统
总结
很巧妙的是,实际上后续的两个变种,就是把传送矩阵的均等传送的概率改成非均等、有偏好的传送,就形成了推荐系统的效果。下面是总结:
1. 环境准备
1!pip install networkx numpy matplotlib pandas
12345678910import numpy as npimport pandas as pdimport networkx as nximport matplotlib.pyplot as pltimport matplotlib as mpl%matplotlib inline# 使用macOS系统自带的中文字体plt.rcParams[' ...
CS224W - Colab 1
CS224W - Colab 1
In this Colab, we will write a full pipeline for learning node embeddings.
We will go through the following 3 steps.
To start, we will load a classic graph in network science, the Karate Club Network. We will explore multiple graph statistics for that graph.
We will then work together to transform the graph structure into a PyTorch tensor, so that we can perform machine learning over the graph.
Finally, we will finish the first learning algorithm on graphs: a node embedding mode ...
CS224W - Colab 0
CS224W - Colab 0
Colab 0 will not be graded, so you don’t need to hand in this notebook. That said, we highly recommend you to run this notebook, so you can get familiar with the basic concepts of graph mining and Graph Neural Networks.
In this Colab, we will introduce two packages, NetworkX and PyTorch Geometric.
For the PyTorch Geometric section, you don’t need to understand all the details already. Concepts and implementations of graph neural network will be covered in future lectures and Col ...
Node2Vec 官方代码解读
Node2Vec 官方代码解读
参考资料
Node2Vec 官方作者 Aditya Grover 代码:https://github.com/aditya-grover/node2vec
1. 环境准备
工具包
1234567891011import warningswarnings.filterwarnings('ignore')import argparseimport numpy as npimport networkx as nx from gensim.models import Word2Vecimport randomimport matplotlib.pyplot as plt %matplotlib inline
读入命令行参数
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950def parse_args(): ''' Parses the node2vec argume ...
Node2Vec 图嵌入:《悲惨世界》人物关系
Node2Vec 图嵌入: 《悲惨世界》人物关系
参考资料:
Elior Cohen 代码:https://github.com/eliorc/node2vec
Elior Cohen 博客:https://maelfabien.github.io/machinelearning/graph_5/
1. 环境准备
安装工具包
1!pip install node2vec networkx numpy matplotlib
导入工具包
123456789101112# 图数据挖掘import networkx as nx# 数据分析import numpy as np# 随机数import random# 数据可视化import matplotlib.pyplot as plt
2. 数据
初始化
12345# 空手道俱乐部# G = nx.karate_club_graph()# 悲惨世界 人物G = nx.les_miserables_graph()
1G.nodes
NodeView(('Napoleon', 'Myriel', 'MlleBaptistine', 'MmeMa ...
DeepWalk 图嵌入:维基百科词条
DeepWalk 图嵌入:维基百科词条
1. 环境参考
参考资料
https://github.com/prateekjoshi565/DeepWalk
安装工具包
1!pip install networkx gensim pandas numpy tqdm scikit-learn matplotlib
导入工具包
123456789101112131415# 图数据挖掘import networkx as nx# 数据分析import pandas as pdimport numpy as np# 随机数与进度条import randomfrom tqdm import tqdm# 数据可视化import matplotlib.pyplot as plt%matplotlib inline
2. 数据
获取数据
爬虫网站:https://densitydesign.github.io/strumentalia-seealsology/
设置 distance
输入链接:
https://en.wikipedia.org/wiki/Computer_vision
htt ...
ML2021 - HW 5
Homework 5 - Sequence-to-sequence
If you have any questions, feel free to email us at: ntu-ml-2021spring-ta@googlegroups.com
(4/21 Updates)
Link to reference training curves.
(4/14 Updates)
Link to tutorial video part 1 part 2.
Now defaults to load "avg_last_5_checkpoint.pt" to generate prediction.
Expected run time on Colab with Tesla T4
Baseline
Details
Total Time
Simple
2m 15s $\times$30 epochs
1hr 8m
Medium
4m $\times$30 epochs
2hr
Strong
8m $\times$30 epochs (backwa ...
ML2021 - HW 4
HW4: Speaker Prediction
goal: learn to use transformer
赛事:https://www.kaggle.com/competitions/ml2021spring-hw4/overview
Baselines:
Easy: Run sample code and know how to use transformer.
Medium: Know how to adjust parameters of transformer.
Hard: Construct conformer which is a variety of transformer.
Other links
Kaggle: link
Slide: link
Data: link
Video (Chinese): link
Video (English): link
Solution for downloading dataset fail.: link
1. Data
Dataset
12345678910111213141516171819202 ...