Views
No views yet
1from transformers import AutoModel, AutoConfig
2
3model = AutoModel.from_pretrained("viguera10/esa-graph-encoder", trust_remote_code=True)
4
5# Inputs are plain PyTorch tensors
6import torch
7
8# Two molecules batched together:
9# mol0: 4 nodes, edges 0->1, 1->2, 2->3 (and reverse)
10# mol1: 3 nodes, edges 0->1, 1->2 (and reverse)
11
12node_features = torch.randn(7, 84) # total 7 nodes, 84 node features (ChemProp one-hot)
13edge_index = torch.tensor([ # global node indices
14 [0,1,1,2,2,3, 4,5,5,6],
15 [1,0,2,1,3,2, 5,4,6,5],
16])
17edge_attr = torch.randn(10, 14) # 10 edges, 14 edge features (ChemProp one-hot)
18batch_mapping = torch.tensor([0,0,0,0, 1,1,1]) # node -> graph id
19
20output = model(
21 node_features=node_features,
22 edge_index=edge_index,
23 batch_mapping=batch_mapping,
24 edge_attr=edge_attr,
25)
26# output.last_hidden_state: Tensor[2, 256] — one embedding per graphconfig.json:| Parameter | Description |
|---|---|
apply_attention_on | "edge" (ESA) or "node" (NSA) |
hidden_dims | Feature dimension at each layer |
num_heads | Attention heads at each layer |
layer_types | Sequence of "S" (SAB), "M" (masked SAB), "P" (PMA pooling) |
dim_output | Dimension of the output graph embedding |
xformers_or_torch_attn | "torch" (default) or "xformers" |
1@Article{Buterez2025,
2 author={Buterez, David
3 and Janet, Jon Paul
4 and Oglic, Dino
5 and Li{\`o}, Pietro},
6 title={An end-to-end attention-based approach for learning on graphs},
7 journal={Nature Communications},
8 year={2025},
9 month={Jun},
10 day={05},
11 volume={16},
12 number={1},
13 pages={5244},
14 issn={2041-1723},
15 doi={10.1038/s41467-025-60252-z},
16 url={https://doi.org/10.1038/s41467-025-60252-z}
17}