Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
PaddlePaddle
PGL
提交
c56c4b11
P
PGL
项目概览
PaddlePaddle
/
PGL
通知
76
Star
4
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
11
列表
看板
标记
里程碑
合并请求
1
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
PGL
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
11
Issue
11
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c56c4b11
编写于
5月 22, 2020
作者:
W
Webbley
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update tutorials
上级
ccf74fa5
变更
2
展开全部
隐藏空白更改
内联
并排
Showing
2 changed file
with
51 addition
and
58 deletion
+51
-58
docs/source/quick_start/md/quick_start.md
docs/source/quick_start/md/quick_start.md
+8
-8
tutorials/1-Introduction.ipynb
tutorials/1-Introduction.ipynb
+43
-50
未找到文件。
docs/source/quick_start/md/quick_start.md
浏览文件 @
c56c4b11
...
...
@@ -19,8 +19,8 @@ def build_graph():
# Each node can be represented by a d-dimensional feature vector, here for simple, the feature vectors are randomly generated.
d
=
16
feature
=
np
.
random
.
randn
(
num_node
,
d
).
astype
(
"float32"
)
# each edge
also can be represented by a feature vector
edge_feature
=
np
.
random
.
randn
(
len
(
edge_list
),
d
).
astype
(
"float32"
)
# each edge
has it own weight
edge_feature
=
np
.
random
.
randn
(
len
(
edge_list
),
1
).
astype
(
"float32"
)
# create a graph
g
=
graph
.
Graph
(
num_nodes
=
num_node
,
...
...
@@ -66,13 +66,13 @@ In this tutorial, we use a simple Graph Convolutional Network(GCN) developed by
In PGL, we can easily implement a GCN layer as follows:
```
python
# define GCN layer function
def
gcn_layer
(
gw
,
feature
,
hidden_size
,
name
,
activation
):
def
gcn_layer
(
gw
,
nfeat
,
efeat
,
hidden_size
,
name
,
activation
):
# gw is a GraphWrapper;feature is the feature vectors of nodes
# define message function
def
send_func
(
src_feat
,
dst_feat
,
edge_feat
):
# In this tutorial, we return the feature vector of the source node as message
return
src_feat
[
'h'
]
return
src_feat
[
'h'
]
*
edge_feat
[
'e'
]
# define reduce function
def
recv_func
(
feat
):
...
...
@@ -80,7 +80,7 @@ def gcn_layer(gw, feature, hidden_size, name, activation):
return
fluid
.
layers
.
sequence_pool
(
feat
,
pool_type
=
'sum'
)
# trigger message to passing
msg
=
gw
.
send
(
send_func
,
nfeat_list
=
[(
'h'
,
feature
)])
msg
=
gw
.
send
(
send_func
,
nfeat_list
=
[(
'h'
,
nfeat
)],
efeat_list
=
[(
'e'
,
efeat
)])
# recv funciton receives message and trigger reduce funcition to handle message
output
=
gw
.
recv
(
msg
,
recv_func
)
output
=
fluid
.
layers
.
fc
(
output
,
...
...
@@ -92,10 +92,10 @@ def gcn_layer(gw, feature, hidden_size, name, activation):
```
After defining the GCN layer, we can construct a deeper GCN model with two GCN layers.
```
python
output
=
gcn_layer
(
gw
,
gw
.
node_feat
[
'feature'
],
output
=
gcn_layer
(
gw
,
gw
.
node_feat
[
'feature'
],
gw
.
edge_feat
[
'edge_feature'
],
hidden_size
=
8
,
name
=
'gcn_layer_1'
,
activation
=
'relu'
)
output
=
gcn_layer
(
gw
,
output
,
hidden_size
=
1
,
name
=
'gcn_layer_2'
,
activation
=
None
)
output
=
gcn_layer
(
gw
,
output
,
gw
.
edge_feat
[
'edge_feature'
]
,
hidden_size
=
1
,
name
=
'gcn_layer_2'
,
activation
=
None
)
```
## Step 3: data preprocessing
...
...
tutorials/1-Introduction.ipynb
浏览文件 @
c56c4b11
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录