Pytorch实现一个简单图网络(Graph Net)
source link: https://mathpretty.com/12604.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
最近开始看图网络, 首先对其有一个大概的印象.
参考资料: Program a simple Graph Net in PyTorch (本文就是翻译的这一篇文章, 并稍作修改)
一些参考资料
- GNN综述——从入门到入门, 这里也是别人整理的一个GNN的入门系列.
- 番外篇:GNN模型及实现细节, 详细解释论文"The Graph Neural Network Model"的具体实现过程.
- 番外篇:PyG框架及Cora数据集简介, PyG框架的介绍, 里面有说明如何进行相应的矩阵运算.
- 【GNN】万字长文带你入门 GCN, 包括详细的GCN的原理的解释.
- Cluster-GCN, 这一篇也就写的一般, 可以做一下参考.
- PyTorch Geometric CUDA installation issues on Google Colab, 如何安装指定的Pytorch Geometric在Google Colab上面.
Graph Data的介绍
在介绍图网络之前, 我们首先来说一下什么是图(graph). 一个图的是由下面两个主要因素构成的:
- 节点(Nodes): entities that usually have a certain set of properties
- 边(Edges): connecting two nodes. An edge can be uni- or bidirectional (可以是单项或是双向的)
于是, 下面是graph data的两个基本的特征:
- Just like in other machine learning applications every node has a set of features. For example, when we look at a social network every node can be a person with a certain age, gender, interests, political views, etc. (每一个节点拥有一些特征)
- Information is also encoded in the structure of the graph. By looking at friends of a person it is often possible to get some insight into this person. (数据之间会以节点的形式进行保存)
例如, 我们在评价一个人的时候, 我们可以首先看这个人的属性, 接着我们就会看这个人的朋友. 所以, graph net的最基本的想法就是, we aggregate information of neighbors, and neighbors of neighbors, etc. of one node.
Graph Data的例子
下面我们来看一个Graph data的例子. 例如下图是一个friend group, 两个node之间有边表示这两个人是好朋友.
接着我们聚焦在person A上面. 现在看depth 0, 也就是A本身. 可以获得以下的一些性质.
接着, 我们查看depth 1, 也就是和A是直接认识的人, 是B, C, E.
接着, 我们查看depth 2, 也就是A的朋友的朋友, 这个时候可以得到如下的图.
关于Cora数据集介绍
- 该数据集共2708个样本点, 每个样本点都是一篇科学论文;
- 每个节点有1433维的词向量表示. 每个维度对应一个词, 只有0和1两个取值, 表示这个词是否出现在这篇论文中;
- 所有样本点被分为8个类别, 类别分别是1.基于案例; 2. 遗传算法; 3. 神经网络; 4. 概率方法; 5. 强化学习; 6. 规则学习; 7. 理论;
- 每篇论文至少引用了一篇其他论文, 若论文之间存在引用的关系, 则这两个节点是相连的, 该数据集一共有5429条边; (在Pytorch中, 因为是无向边, 每条边被存储了两次, 所以最后大约是10556, 至于为什么不是5429*2=10585, 是因为原始数据中有重复边, 这个可以参考链接, About Cora Dataset #852)
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK