Transformers were originally proposed as a sequence-to-sequence model for text but have become vital for a wide range of modalities, including images, audio, video, and undirected graphs. However, transformers for directed graphs are a surprisingly underexplored topic, despite their applicability to ubiquitous domains, including source code and logic circuits. In this work, we propose two direction- and structure-aware positional encodings for directed graphs: (1) the eigenvectors of the Magnetic Laplacian - a direction-aware generalization of the combinatorial Laplacian; (2) directional random walk encodings. Empirically, we show that the extra directionality information is useful in various downstream tasks, including correctness testing of sorting networks and source code understanding. Together with a data-flow-centric graph construction, our model outperforms the prior state of the art on the Open Graph Benchmark Code2 relatively by 14.7%.
翻译:Transformer最初作为文本序列到序列模型被提出,但现已广泛应用于包括图像、音频、视频和无向图在内的多种模态。然而,针对有向图的Transformer却是一个出人意料的未充分探索课题,尽管其适用于源代码和逻辑电路等普遍领域。在这项工作中,我们提出两种面向有向图的方向感知与结构感知位置编码:(1) 磁拉普拉斯算子的特征向量——组合拉普拉斯算子的方向感知泛化;(2) 方向随机游走编码。实验表明,额外方向性信息在多种下游任务中具有实用价值,包括排序网络的正确性测试和源代码理解。结合数据流为中心的图构建方法,我们的模型在开放图基准测试Code2上相对先前最优结果提升了14.7%。