模块更新于 2026-11-20· 浏览 4· 下载 0
EFIGNN 显式特征交互感知图神经网络
显式学任意阶交互:每层做无激活函数的图卷积聚合邻居信息,再哈达玛乘上 1 阶特征之和,交互阶数随层数递增,2 层学 2 阶、4 层学 4 阶
结构图

显式学任意阶交互:每层做无激活函数的图卷积聚合邻居信息,再哈达玛乘上 1 阶特征之和,交互阶数随层数递增,2 层学 2 阶、4 层学 4 阶
论文信息
- 论文:Explicit Feature Interaction-Aware Graph Neural Network
- 出处:IEEE Access 2024
核心痛点
GCN、GAT 这类 GNN 靠激活函数做非线性聚合,只能隐式学到"所有特征搅在一起"的高阶交互,而 1~3 阶低阶特征交互里同样藏着有效模式,却被整体忽略;FM、DeepFM、CrossNet 等显式交互方法只处理平铺特征、没法直接用在图数据上,可解释性也长期被忽视。
模块亮点
- 显式学任意阶交互:每层做无激活函数的图卷积聚合邻居信息,再哈达玛乘上 1 阶特征之和,交互阶数随层数递增,2 层学 2 阶、4 层学 4 阶
- 联合训练一致涨点:与 GCN、GAT、GATv2、ASDGN 联合训练后预测精度全面提升,且等参数量下优于 GCN & GCN 与 EFIGNN & EFIGNN,说明显式 + 隐式交互互补
- 线性天然可解释:模型全线性,可直接算出每个 1、2 阶特征对各类别输出的影响值并画成热图;tSNE 显示无过平滑问题
适用场景
领域为图神经网络的节点分类;原文在 Cora、CiteSeer、PubMed、Amazon Computers、Actor 五个数据集上验证,并在 ogbn-arxiv、ogbn-mag 两个 OGB 基准上验证联合训练;可迁移到推荐系统等特征交互起关键作用的图应用,以及医疗等需要可解释模型的高风险领域。
插入位置建议
- 与 GCN、GAT、GATv2 等骨干并联做联合训练:两路各层表示拼接后接统一输出层
- 把网络中堆叠的 GCNConv 替换为 EFIGNNConv,保留"无激活 + 特征交叉"的结构逐层叠深
- 接在输出层前作为可解释分支,读取 1、2 阶特征影响值画热图,做特征分析
适用任务
- 图神经网络的节点分类
完整代码
efignn.py
import torch
import torch.nn as nn
from torch_geometric.nn import MessagePassing, GCNConv
from torch_geometric.utils import add_self_loops, degree
import pytorch_lightning as pl
import torch.optim as optim
import torch.nn.functional as F
from torch_geometric.data import Data
"""《Explicit Feature Interaction-Aware Graph Neural Network》IEEE Access2024
图神经网络 (GNN) 是处理图结构数据的强大工具。然而,它们的设计通常限制它们只能学习高阶特征交互,而忽略了低阶特征交互。
为了解决这个问题,我们引入了一种新的 GNN 方法,称为显式特征交互感知图神经网络 (explicit feature interaction-aware graph neural network,EFI-GNN)。
与传统 GNN 不同,EFI-GNN 是一个多层线性网络,旨在显式地对图中的任意阶特征交互进行建模。为了验证 EFI-GNN 的有效性,我们使用各种数据集进行了实验。
实验结果表明,EFI-GNN 的性能与现有的 GNN 相比具有竞争力,并且当 GNN 与 EFI-GNN 联合训练时,预测性能会有所改善。此外,由于 EFI-GNN 的线性结构,它的预测是可解释的。
"""
class _BaseLightningModel(pl.LightningModule):
def __init__(
self,
lr: float,
weight_decay: float
) -> None:
super().__init__()
self._lr = lr
self._weight_decay = weight_decay
self._y_hat = []
self._y_true = []
def configure_optimizers(self) -> optim.Optimizer:
optimizer = optim.Adam(self.parameters(), lr=self._lr, weight_decay=self._weight_decay)
# scheduler = optim.lr_scheduler.CosineAnnealingLR(optimizer, T_max=200)
return {
'optimizer': optimizer,
# 'lr_scheduler': scheduler,
'interval': 'epoch',
'monitor': 'val_loss'
}
def training_step(self, batch, batch_index) -> torch.Tensor:
self.train()
y_hat = self(batch.x, batch.edge_index)
loss = F.cross_entropy(y_hat[batch.train_mask], batch.y[batch.train_mask])
self.log('train_loss', loss, prog_bar=True, on_step=False, on_epoch=True)
return loss
def validation_step(self, batch, batch_index) -> torch.Tensor:
self.eval()
y_hat = self(batch.x, batch.edge_index)
loss = F.cross_entropy(y_hat[batch.val_mask], batch.y[batch.val_mask])
self.log('val_loss', loss, prog_bar=True, on_step=False, on_epoch=True)
return loss
def test_step(self, batch, batch_index) -> None:
self.eval()
y_hat = self(batch.x, batch.edge_index)[batch.test_mask].argmax(dim=1)
y_true = batch.y[batch.test_mask]
self._y_hat.append(y_hat)
self._y_true.append(y_true)
def on_test_epoch_end(self) -> None:
y_hat = torch.concat(self._y_hat, dim=0)
y_true = torch.concat(self._y_true, dim=0)
acc = (y_hat == y_true).to(torch.float32).mean()
print(acc.item())
self._y_hat.clear()
self._y_true.clear()
__all__ = ['EFIGNNConv', 'EFIGNN']
class EFIGNNConv(MessagePassing):
def __init__(
self,
channels: int
):
super().__init__(aggr='add')
self._linear = nn.Linear(channels, channels, bias=False)
self._bias = nn.Parameter(torch.empty(channels))
self.reset_parameters()
def reset_parameters(self):
self._linear.reset_parameters()
self._bias.data.zero_()
def forward(
self,
x: torch.Tensor,
x0: torch.Tensor,
edge_index: torch.Tensor
):
edge_index, _ = add_self_loops(edge_index, num_nodes=x.size(0))
x = self._linear(x)
row, col = edge_index
deg = degree(col, x.size(0), dtype=x.dtype)
deg_inv_sqrt = deg.pow(-0.5)
deg_inv_sqrt[deg_inv_sqrt == float('inf')] = 0
norm = deg_inv_sqrt[row] * deg_inv_sqrt[col]
out = self.propagate(edge_index, x=x, norm=norm)
out = out * x0
out = out + self._bias
return out
def message(self, x_j, norm):
return norm.view(-1, 1) * x_j
class EFIGNN(_BaseLightningModel):
def __init__(
self,
architecture: list,
dropout: float = 0,
batchnorm: bool = False,
lr: float = 1e-3,
weight_decay: float = 0,
skip_conn: bool = False,
apply_output_layer: bool = True
) -> None:
super().__init__(lr, weight_decay)
# self.save_hyperparameters()
n_layers = len(architecture) - 2
self._layers = nn.ModuleList()
# self._layers.append(nn.Linear(architecture[0], architecture[1]))
self._layers.append(GCNConv(architecture[0], architecture[1]))
if batchnorm:
self._layers.append(nn.BatchNorm1d(architecture[1]))
self._layers.append(nn.Dropout(p=dropout))
for i in range(n_layers - 1):
self._layers.append(EFIGNNConv(architecture[i + 1]))
if batchnorm:
self._layers.append(nn.BatchNorm1d(architecture[i + 1]))
if dropout > 0:
self._layers.append(nn.Dropout(p=dropout))
self._output_layer = nn.Linear(sum(architecture[1: -1]), architecture[-1])
self._skip_conn = skip_conn
self._apply_output_layer = apply_output_layer
def forward(
self,
x: torch.Tensor,
edge_index: torch.Tensor
):
xs = []
for layer in self._layers:
if isinstance(layer, MessagePassing):
xs.append(x)
if len(xs) == 1:
x = layer(x, edge_index)
else:
if self._skip_conn:
# x = layer(x, xs[0], edge_index) + sum(xs[1:])
x = layer(x, xs[1], edge_index) + sum(xs[1:])
else:
# x = layer(x, xs[0], edge_index)
x = layer(x, xs[1], edge_index)
else:
x = layer(x)
xs.append(x)
xs = torch.concat(xs[1:], dim=1)
if self._apply_output_layer:
y_hat = self._output_layer(xs)
else:
y_hat = xs
return y_hat
if __name__ == '__main__':
# 创建一个简单的图数据
num_nodes = 6 # 节点数量
num_features = 3 # 每个节点的特征数量
num_classes = 3 # 类别数量
# 随机生成节点特征
x = torch.rand((num_nodes, num_features), dtype=torch.float32)
# 定义边连接(无向图)
edge_index = torch.tensor([[0, 1, 1, 2, 2, 3, 3, 4],
[1, 0, 2, 1, 3, 2, 4, 3]], dtype=torch.long)
# 随机生成标签
y = torch.randint(0, num_classes, (num_nodes,), dtype=torch.long)
# 创建图数据对象
data = Data(x=x, edge_index=edge_index, y=y)
# 创建模型实例
block = EFIGNN(architecture=[num_features, 4, 4, num_classes]).to('cuda')
# 将数据移动到 GPU
data = data.to('cuda')
# 进行前向传播
output = block(data.x, data.edge_index)
# 打印输入和输出的尺寸
print("Input size:", data.x.size())
print("Output size:", output.size())环境与依赖
Python 3.9+
继续浏览
下一篇EGA 边缘引导注意力模块免参数提边缘:用拉普拉斯算子从原图提取高频边缘特征,零可学习参数、几乎不增计算量,比 Sobel 等一阶算子得到的边缘更有意义相关资源
模块2026-11-20
ContraNorm 对比归一化层
对抗维度崩溃:把对比学习的均匀性损失搬到表示本身,一步梯度展开得到前向公式:x 减去 scale × softmax(相似度)x 再接 LayerNorm,把挤在一起的表示"撑开",能提升表示的方差与有效秩
Transformer图神经网络ContraNorm
图神经网络MIT
模块2026-11-20
GCKM 图卷积核机器
卷积套核函数:每层先用归一化邻接矩阵做邻居聚合,再用高斯核把特征隐式映射到高维空间,后续逐层只在核矩阵上递归计算
图神经网络GCKM核方法
图神经网络MIT
模块2026-11-20
GEA 图外部注意力
图间共享记忆:用与输入图无关的可学习外部 key-value 单元充当所有图共享的“记忆库”,节点、边各配一套,特征只需与外部单元做注意力,即可隐式建模图间相关性,消融显示去掉任一外部单元都会掉点
图神经网络GEA图表示学习
图神经网络MIT