"Graph Convolutions Enrich the Self-Attention in Transformers!" NeurIPS 2024
27
stars
14
commits
Python
primary language
Mar 19, 2025
updated
The detailed guidance is included in the README.md of each subdirectory:
πΌοΈ Image Classification π ./Image
π Natural Language Understanding π ./NLP
π§ Causal Language Modeling π ./NLP
π Graph Regression π ./Graph
ποΈ Speech Recognition π ./Speech
π» Code Classification π ./Code
GFSA's core implementation is shown in the following pseudocode:
def GFSA(att, K):
"""
Graph Filter-based Self-Attention
Args:
att: original self-attention matrix
K: order of high-order term
Notes:
w_0, w_1 can be set in two ways:
1) As learnable parameters
2) Fixed as hyperparameters (w_0=0, w_1=1)
Returns:
gf_att: GFSA attention matrix
"""
# Initialize weights
w_0 = torch.zeros(h) # identity term weight
w_1 = torch.ones(h) # first-order term weight
w_K = torch.zeros(h) # high-order term weight
I = torch.eyes(n)[None, None, ...]
# Compute high-order term using Taylor approximation
att_K = att + (K-1) * (torch.mm(att,att) - att)
# Combine terms with weights
gf_att = w_0[None, :, None, None] * I + \
w_1[None, :, None, None] * att + \
w_K[None, :, None, None] * att_K
return gf_att
w_0, w_1 can be either learnable parameters or fixed hyperparametersfrom models.attention import GFSA
# Replace original self-attention with GFSA
attention_output = GFSA(
att=attention_scores, # original attention matrix
K=3 # order of high-order term
)
If you use this code for your research, please cite our paper:
@inproceedings{choi2024gfsa,
title={Graph Convolutions Enrich the Self-Attention in Transformers!},
author={Jeongwhan Choi and Hyowon Wi and Jayoung Kim and Yehjin Shin and Kookjin Lee and Nathaniel Trask and Noseong Park},
booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
year={2024},
url={https://openreview.net/forum?id=ffNrpcBpi6}
}
14 commits
Python
99.3%
"Graph Convolutions Enrich the Self-Attention in Transformers!" NeurIPS 2024
27
stars
14
commits
Python
primary language
Mar 19, 2025
updated
The detailed guidance is included in the README.md of each subdirectory:
πΌοΈ Image Classification π ./Image
π Natural Language Understanding π ./NLP
π§ Causal Language Modeling π ./NLP
π Graph Regression π ./Graph
ποΈ Speech Recognition π ./Speech
π» Code Classification π ./Code
GFSA's core implementation is shown in the following pseudocode:
def GFSA(att, K):
"""
Graph Filter-based Self-Attention
Args:
att: original self-attention matrix
K: order of high-order term
Notes:
w_0, w_1 can be set in two ways:
1) As learnable parameters
2) Fixed as hyperparameters (w_0=0, w_1=1)
Returns:
gf_att: GFSA attention matrix
"""
# Initialize weights
w_0 = torch.zeros(h) # identity term weight
w_1 = torch.ones(h) # first-order term weight
w_K = torch.zeros(h) # high-order term weight
I = torch.eyes(n)[None, None, ...]
# Compute high-order term using Taylor approximation
att_K = att + (K-1) * (torch.mm(att,att) - att)
# Combine terms with weights
gf_att = w_0[None, :, None, None] * I + \
w_1[None, :, None, None] * att + \
w_K[None, :, None, None] * att_K
return gf_att
w_0, w_1 can be either learnable parameters or fixed hyperparametersfrom models.attention import GFSA
# Replace original self-attention with GFSA
attention_output = GFSA(
att=attention_scores, # original attention matrix
K=3 # order of high-order term
)
If you use this code for your research, please cite our paper:
@inproceedings{choi2024gfsa,
title={Graph Convolutions Enrich the Self-Attention in Transformers!},
author={Jeongwhan Choi and Hyowon Wi and Jayoung Kim and Yehjin Shin and Kookjin Lee and Nathaniel Trask and Noseong Park},
booktitle={The Thirty-eighth Annual Conference on Neural Information Processing Systems},
year={2024},
url={https://openreview.net/forum?id=ffNrpcBpi6}
}
14 commits
Python
99.3%