en-transformer
Implementation of E(n)-Transformer, which incorporates attention mechanisms into Welling's E(n)-Equivariant Graph Neural Network
Science Score: 67.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
✓CITATION.cff file
Found CITATION.cff file -
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
✓DOI references
Found 2 DOI reference(s) in README -
✓Academic publication links
Links to: arxiv.org, biorxiv.org -
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (6.7%) to scientific vocabulary
Keywords
Repository
Implementation of E(n)-Transformer, which incorporates attention mechanisms into Welling's E(n)-Equivariant Graph Neural Network
Basic Info
Statistics
- Stars: 225
- Watchers: 4
- Forks: 30
- Open Issues: 8
- Releases: 80
Topics
Metadata Files
README.md
E(n)-Equivariant Transformer
Implementation of E(n)-Equivariant Transformer, which extends the ideas from Welling's E(n)-Equivariant Graph Neural Network with attention mechanisms and ideas from transformer architecture.
Update: Used for designing of CDR loops in antibodies!
Install
bash
$ pip install En-transformer
Usage
```python import torch from en_transformer import EnTransformer
model = EnTransformer( dim = 512, depth = 4, # depth dimhead = 64, # dimension per head heads = 8, # number of heads edgedim = 4, # dimension of edge feature neighbors = 64, # only do attention between coordinates N nearest neighbors - set to 0 to turn off talkingheads = True, # use Shazeer's talking heads https://arxiv.org/abs/2003.02436 checkpoint = True, # use checkpointing so one can increase depth at little memory cost (and increase neighbors attended to) usecrossproduct = True, # use cross product vectors (idea by @MattMcPartlon) numgloballinearattn_heads = 4 # if your number of neighbors above is low, you can assign a certain number of attention heads to weakly attend globally to all other nodes through linear attention (https://arxiv.org/abs/1812.01243) )
feats = torch.randn(1, 1024, 512) coors = torch.randn(1, 1024, 3) edges = torch.randn(1, 1024, 1024, 4)
mask = torch.ones(1, 1024).bool()
feats, coors = model(feats, coors, edges, mask = mask) # (1, 1024, 512), (1, 1024, 3) ```
Letting the network take care of both atomic and bond type embeddings
```python import torch from en_transformer import EnTransformer
model = EnTransformer( numtokens = 10, # number of unique nodes, say atoms relposemb = True, # set this to true if your sequence is not an unordered set. it will accelerate convergence numedgetokens = 5, # number of unique edges, say bond types dim = 128, edgedim = 16, depth = 3, heads = 4, dim_head = 32, neighbors = 8 )
atoms = torch.randint(0, 10, (1, 16)) # 10 different types of atoms bonds = torch.randint(0, 5, (1, 16, 16)) # 5 different types of bonds (n x n) coors = torch.randn(1, 16, 3) # atomic spatial coordinates
featsout, coorsout = model(atoms, coors, edges = bonds) # (1, 16, 512), (1, 16, 3) ```
If you would like to only attend to sparse neighbors, as defined by an adjacency matrix (say for atoms), you have to set one more flag and then pass in the N x N adjacency matrix.
```python import torch from en_transformer import EnTransformer
model = EnTransformer( numtokens = 10, dim = 512, depth = 1, heads = 4, dimhead = 32, neighbors = 0, onlysparseneighbors = True, # must be set to true numadjdegrees = 2, # the number of degrees to derive from 1st degree neighbors passed in adj_dim = 8 # whether to pass the adjacency degree information as an edge embedding )
atoms = torch.randint(0, 10, (1, 16)) coors = torch.randn(1, 16, 3)
naively assume a single chain of atoms
i = torch.arange(atoms.shape[1]) adj_mat = (i[:, None] <= (i[None, :] + 1)) & (i[:, None] >= (i[None, :] - 1))
adjacency matrix must be passed in
featsout, coorsout = model(atoms, coors, adjmat = adjmat) # (1, 16, 512), (1, 16, 3) ```
Edges
If you need to pass in continuous edges
```python import torch from entransformer import EnTransformer from entransformer.utils import rot
model = EnTransformer( dim = 512, depth = 1, heads = 4, dimhead = 32, edgedim = 4, numnearestneighbors = 0, onlysparseneighbors = True )
feats = torch.randn(1, 16, 512) coors = torch.randn(1, 16, 3) edges = torch.randn(1, 16, 16, 4)
i = torch.arange(feats.shape[1]) adj_mat = (i[:, None] <= (i[None, :] + 1)) & (i[:, None] >= (i[None, :] - 1))
feats1, coors1 = model(feats, coors, adjmat = adjmat, edges = edges) ```
Example
To run a protein backbone coordinate denoising toy task, first install sidechainnet
bash
$ pip install sidechainnet
Then
bash
$ python denoise.py
Todo
- [ ] add https://arxiv.org/abs/2112.05682 for researchers to stretch to even bigger molecules
Citations
bibtex
@misc{satorras2021en,
title = {E(n) Equivariant Graph Neural Networks},
author = {Victor Garcia Satorras and Emiel Hoogeboom and Max Welling},
year = {2021},
eprint = {2102.09844},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
bibtex
@misc{shazeer2020talkingheads,
title = {Talking-Heads Attention},
author = {Noam Shazeer and Zhenzhong Lan and Youlong Cheng and Nan Ding and Le Hou},
year = {2020},
eprint = {2003.02436},
archivePrefix = {arXiv},
primaryClass = {cs.LG}
}
bibtex
@misc{liu2021swin,
title = {Swin Transformer V2: Scaling Up Capacity and Resolution},
author = {Ze Liu and Han Hu and Yutong Lin and Zhuliang Yao and Zhenda Xie and Yixuan Wei and Jia Ning and Yue Cao and Zheng Zhang and Li Dong and Furu Wei and Baining Guo},
year = {2021},
eprint = {2111.09883},
archivePrefix = {arXiv},
primaryClass = {cs.CV}
}
bibtex
@inproceedings{Kim2020TheLC,
title = {The Lipschitz Constant of Self-Attention},
author = {Hyunjik Kim and George Papamakarios and Andriy Mnih},
booktitle = {International Conference on Machine Learning},
year = {2020},
url = {https://api.semanticscholar.org/CorpusID:219530837}
}
bibtex
@article {Mahajan2023.07.15.549154,
author = {Sai Pooja Mahajan and Jeffrey A. Ruffolo and Jeffrey J. Gray},
title = {Contextual protein and antibody encodings from equivariant graph transformers},
elocation-id = {2023.07.15.549154},
year = {2023},
doi = {10.1101/2023.07.15.549154},
publisher = {Cold Spring Harbor Laboratory},
URL = {https://www.biorxiv.org/content/early/2023/07/29/2023.07.15.549154},
eprint = {https://www.biorxiv.org/content/early/2023/07/29/2023.07.15.549154.full.pdf},
journal = {bioRxiv}
}
bibtex
@article{Bondarenko2023QuantizableTR,
title = {Quantizable Transformers: Removing Outliers by Helping Attention Heads Do Nothing},
author = {Yelysei Bondarenko and Markus Nagel and Tijmen Blankevoort},
journal = {ArXiv},
year = {2023},
volume = {abs/2306.12929},
url = {https://api.semanticscholar.org/CorpusID:259224568}
}
bibtex
@inproceedings{Arora2023ZoologyMA,
title = {Zoology: Measuring and Improving Recall in Efficient Language Models},
author = {Simran Arora and Sabri Eyuboglu and Aman Timalsina and Isys Johnson and Michael Poli and James Zou and Atri Rudra and Christopher R'e},
year = {2023},
url = {https://api.semanticscholar.org/CorpusID:266149332}
}
Owner
- Name: Phil Wang
- Login: lucidrains
- Kind: user
- Location: San Francisco
- Website: lucidrains.github.io
- Repositories: 283
- Profile: https://github.com/lucidrains
Working with Attention. It's all we need
Citation (CITATION.cff)
# This CITATION.cff file was generated with cffinit.
# Visit https://bit.ly/cffinit to generate yours today!
cff-version: 1.2.0
title: En-transformer
message: >-
If you use this software, please cite it using the
metadata from this file.
type: software
authors:
- given-names: Phil Wang
email: lucidrains@gmail.com
name-particle: Phillip
family-names: Wang
repository-code: 'https://github.com/lucidrains/En-transformer'
abstract: Extending EGNN to a transformer
license: MIT
GitHub Events
Total
- Watch event: 12
- Fork event: 4
Last Year
- Watch event: 12
- Fork event: 4
Issues and Pull Requests
Last synced: 7 months ago
All Time
- Total issues: 13
- Total pull requests: 2
- Average time to close issues: 3 months
- Average time to close pull requests: 8 months
- Total issue authors: 11
- Total pull request authors: 2
- Average comments per issue: 1.23
- Average comments per pull request: 1.5
- Merged pull requests: 1
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 1
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 1
- Pull request authors: 0
- Average comments per issue: 1.0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- aced125 (2)
- heiidii (2)
- leffff (1)
- lucidrains (1)
- llllly26 (1)
- charlotte0104 (1)
- chaitjo (1)
- MohaiminDev (1)
- Byun-jinyoung (1)
- amrhamedp (1)
- mireklzicar (1)
Pull Request Authors
- lucidrains (2)
- hypnopump (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 455 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 76
- Total maintainers: 1
pypi.org: en-transformer
E(n)-Equivariant Transformer
- Homepage: https://github.com/lucidrains/En-transformer
- Documentation: https://en-transformer.readthedocs.io/
- License: MIT
-
Latest release: 1.6.6
published over 1 year ago
Rankings
Maintainers (1)
Dependencies
- einops >=0.3
- torch >=1.7
- actions/checkout v2 composite
- actions/setup-python v2 composite
- actions/checkout v2 composite
- actions/setup-python v2 composite