graph_subgraph_embedding v1
Browse files- README.md +77 -0
- manifest.json +29 -0
- metrics.json +86 -0
- model.onnx +3 -0
- model.pt +3 -0
- train.log +15 -0
- train_config.json +6 -0
README.md
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
library_name: khaos
|
| 4 |
+
tags:
|
| 5 |
+
- khaos
|
| 6 |
+
- graph
|
| 7 |
+
- subgraph-embedding
|
| 8 |
+
- graph-transformer
|
| 9 |
+
pipeline_tag: feature-extraction
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# Khaos Subgraph Embedding
|
| 13 |
+
|
| 14 |
+
A graph transformer that maps a whole subgraph to one 128-dimensional vector, trained contrastively on augmented views of subgraphs (dropped edges and masked features), with a small network-type objective.
|
| 15 |
+
|
| 16 |
+
`graph_subgraph_embedding` **v1**, from Khaos (a local-first library of pre-trained models for domain-specific tasks). This is the first release of the artifact.
|
| 17 |
+
|
| 18 |
+
## Model
|
| 19 |
+
|
| 20 |
+
- Architecture: GraphTransformerEncoder: 4 transformer blocks (dim 128, 4 heads) with a learned attention bias on edges and mean pooling
|
| 21 |
+
- Parameters: 801,665
|
| 22 |
+
- Format: ONNX (`model.onnx`) plus PyTorch weights (`model.pt`) and `manifest.json`
|
| 23 |
+
- Training data: [fletxcher/khaos-graph_subgraph_embedding](https://huggingface.co/datasets/fletxcher/khaos-graph_subgraph_embedding)
|
| 24 |
+
|
| 25 |
+
## Results
|
| 26 |
+
|
| 27 |
+
Measured on the held-out test split of the training dataset.
|
| 28 |
+
|
| 29 |
+
| Metric | Value |
|
| 30 |
+
| --- | ---: |
|
| 31 |
+
| test_domain_accuracy | 0.9950 |
|
| 32 |
+
| test_baseline_structure_accuracy | 0.8375 |
|
| 33 |
+
| test_unseen_graph_domain_accuracy | 0.7833 |
|
| 34 |
+
| test_unseen_graph_baseline_structure_accuracy | 0.6867 |
|
| 35 |
+
| chance_accuracy | 0.3333 |
|
| 36 |
+
|
| 37 |
+
### Domain classification from the embedding
|
| 38 |
+
|
| 39 |
+
A logistic regression on the 128-dimensional subgraph embedding, versus a baseline on simple statistics (size, mean degree, density, feature mean and spread).
|
| 40 |
+
|
| 41 |
+
| Split | Subgraphs | Embedding | Baseline |
|
| 42 |
+
| --- | ---: | ---: | ---: |
|
| 43 |
+
| test | 400 | 0.995 | 0.838 |
|
| 44 |
+
| test_unseen_graph | 300 | 0.783 | 0.687 |
|
| 45 |
+
|
| 46 |
+
## Training
|
| 47 |
+
|
| 48 |
+
```json
|
| 49 |
+
{
|
| 50 |
+
"epochs": 30,
|
| 51 |
+
"batch": 16,
|
| 52 |
+
"lr": 0.0005,
|
| 53 |
+
"architecture": "GraphTransformerEncoder"
|
| 54 |
+
}
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Best epoch 4, trained in 349.5 minutes on a single consumer GPU (RTX 3050 8 GB).
|
| 58 |
+
|
| 59 |
+
## Intended use
|
| 60 |
+
|
| 61 |
+
Comparing and retrieving subgraphs and communities. Input is a subgraph of at most about 64 nodes.
|
| 62 |
+
|
| 63 |
+
## Limitations
|
| 64 |
+
|
| 65 |
+
- Trained with a coarse pretext task (network type), so it captures global structure more than fine semantics.
|
| 66 |
+
- Attention is all-pairs: cost grows quadratically with subgraph size.
|
| 67 |
+
|
| 68 |
+
## Usage
|
| 69 |
+
|
| 70 |
+
```bash
|
| 71 |
+
pip install khaos
|
| 72 |
+
khaos serve ./graph_subgraph_embedding
|
| 73 |
+
```
|
| 74 |
+
|
| 75 |
+
## License
|
| 76 |
+
|
| 77 |
+
This model was trained on graph data with research-only, share-alike or mixed terms (see the training dataset card for each source). Treat it as research use and check the upstream data licenses before any commercial use.
|
manifest.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "graph_subgraph_embedding",
|
| 3 |
+
"vertical": "graph",
|
| 4 |
+
"version": "v1",
|
| 5 |
+
"framework": "onnx",
|
| 6 |
+
"files": {
|
| 7 |
+
"model": "model.onnx"
|
| 8 |
+
},
|
| 9 |
+
"meta": {
|
| 10 |
+
"architecture": "GraphTransformerEncoder",
|
| 11 |
+
"inputs": [
|
| 12 |
+
"x",
|
| 13 |
+
"adj"
|
| 14 |
+
],
|
| 15 |
+
"outputs": [
|
| 16 |
+
"vector",
|
| 17 |
+
"embeddings"
|
| 18 |
+
],
|
| 19 |
+
"in_dim": 64,
|
| 20 |
+
"dataset": "khaos-ml/khaos-graph_subgraph_embedding",
|
| 21 |
+
"test_metrics": {
|
| 22 |
+
"test_domain_accuracy": 0.995,
|
| 23 |
+
"test_baseline_structure_accuracy": 0.8375,
|
| 24 |
+
"test_unseen_graph_domain_accuracy": 0.7833333333333333,
|
| 25 |
+
"test_unseen_graph_baseline_structure_accuracy": 0.6866666666666666,
|
| 26 |
+
"chance_accuracy": 0.3333333333333333
|
| 27 |
+
}
|
| 28 |
+
}
|
| 29 |
+
}
|
metrics.json
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"test": {
|
| 3 |
+
"test_domain_accuracy": 0.995,
|
| 4 |
+
"test_baseline_structure_accuracy": 0.8375,
|
| 5 |
+
"test_unseen_graph_domain_accuracy": 0.7833333333333333,
|
| 6 |
+
"test_unseen_graph_baseline_structure_accuracy": 0.6866666666666666,
|
| 7 |
+
"chance_accuracy": 0.3333333333333333
|
| 8 |
+
},
|
| 9 |
+
"best_epoch": 4,
|
| 10 |
+
"best_val": 0.0024999999999999467,
|
| 11 |
+
"train_seconds": 20970.0,
|
| 12 |
+
"history": [
|
| 13 |
+
{
|
| 14 |
+
"epoch": 1,
|
| 15 |
+
"train_loss": 0.7550397944450379,
|
| 16 |
+
"val_loss": 0.08999999999999997,
|
| 17 |
+
"val_domain_acc": 0.91
|
| 18 |
+
},
|
| 19 |
+
{
|
| 20 |
+
"epoch": 2,
|
| 21 |
+
"train_loss": 0.5199777933955193,
|
| 22 |
+
"val_loss": 0.020000000000000018,
|
| 23 |
+
"val_domain_acc": 0.98
|
| 24 |
+
},
|
| 25 |
+
{
|
| 26 |
+
"epoch": 3,
|
| 27 |
+
"train_loss": 0.4170550738275051,
|
| 28 |
+
"val_loss": 0.007499999999999951,
|
| 29 |
+
"val_domain_acc": 0.9925
|
| 30 |
+
},
|
| 31 |
+
{
|
| 32 |
+
"epoch": 4,
|
| 33 |
+
"train_loss": 0.3787872822582722,
|
| 34 |
+
"val_loss": 0.0024999999999999467,
|
| 35 |
+
"val_domain_acc": 0.9975
|
| 36 |
+
},
|
| 37 |
+
{
|
| 38 |
+
"epoch": 5,
|
| 39 |
+
"train_loss": 0.34004313036799433,
|
| 40 |
+
"val_loss": 0.0024999999999999467,
|
| 41 |
+
"val_domain_acc": 0.9975
|
| 42 |
+
},
|
| 43 |
+
{
|
| 44 |
+
"epoch": 6,
|
| 45 |
+
"train_loss": 0.3247001314908266,
|
| 46 |
+
"val_loss": 0.0050000000000000044,
|
| 47 |
+
"val_domain_acc": 0.995
|
| 48 |
+
},
|
| 49 |
+
{
|
| 50 |
+
"epoch": 7,
|
| 51 |
+
"train_loss": 0.30104018703103064,
|
| 52 |
+
"val_loss": 0.007499999999999951,
|
| 53 |
+
"val_domain_acc": 0.9925
|
| 54 |
+
},
|
| 55 |
+
{
|
| 56 |
+
"epoch": 8,
|
| 57 |
+
"train_loss": 0.28323888778686523,
|
| 58 |
+
"val_loss": 0.0024999999999999467,
|
| 59 |
+
"val_domain_acc": 0.9975
|
| 60 |
+
},
|
| 61 |
+
{
|
| 62 |
+
"epoch": 9,
|
| 63 |
+
"train_loss": 0.2644550459086895,
|
| 64 |
+
"val_loss": 0.0050000000000000044,
|
| 65 |
+
"val_domain_acc": 0.995
|
| 66 |
+
},
|
| 67 |
+
{
|
| 68 |
+
"epoch": 10,
|
| 69 |
+
"train_loss": 0.259011353328824,
|
| 70 |
+
"val_loss": 0.0024999999999999467,
|
| 71 |
+
"val_domain_acc": 0.9975
|
| 72 |
+
},
|
| 73 |
+
{
|
| 74 |
+
"epoch": 11,
|
| 75 |
+
"train_loss": 0.24648742914199828,
|
| 76 |
+
"val_loss": 0.0024999999999999467,
|
| 77 |
+
"val_domain_acc": 0.9975
|
| 78 |
+
},
|
| 79 |
+
{
|
| 80 |
+
"epoch": 12,
|
| 81 |
+
"train_loss": 0.23379882737994195,
|
| 82 |
+
"val_loss": 0.0024999999999999467,
|
| 83 |
+
"val_domain_acc": 0.9975
|
| 84 |
+
}
|
| 85 |
+
]
|
| 86 |
+
}
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a692ddba31d667b3cf56b698cee0e1c7f7b394cb458c8f60cfdc335d82f3b1ad
|
| 3 |
+
size 3241328
|
model.pt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3da2d1d81dce24c6234093fd6b222f4f0fb57e9b977a43ac1124ac41ddc6bf76
|
| 3 |
+
size 3221198
|
train.log
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
[ 0s] training graph_subgraph_embedding v1 on cuda
|
| 2 |
+
[ 73s] epoch=1 train_loss=0.7550 val_loss=0.0900 val_domain_acc=0.9100
|
| 3 |
+
[ 143s] epoch=2 train_loss=0.5200 val_loss=0.0200 val_domain_acc=0.9800
|
| 4 |
+
[ 212s] epoch=3 train_loss=0.4171 val_loss=0.0075 val_domain_acc=0.9925
|
| 5 |
+
[ 20412s] epoch=4 train_loss=0.3788 val_loss=0.0025 val_domain_acc=0.9975
|
| 6 |
+
[ 20488s] epoch=5 train_loss=0.3400 val_loss=0.0025 val_domain_acc=0.9975
|
| 7 |
+
[ 20558s] epoch=6 train_loss=0.3247 val_loss=0.0050 val_domain_acc=0.9950
|
| 8 |
+
[ 20627s] epoch=7 train_loss=0.3010 val_loss=0.0075 val_domain_acc=0.9925
|
| 9 |
+
[ 20696s] epoch=8 train_loss=0.2832 val_loss=0.0025 val_domain_acc=0.9975
|
| 10 |
+
[ 20766s] epoch=9 train_loss=0.2645 val_loss=0.0050 val_domain_acc=0.9950
|
| 11 |
+
[ 20834s] epoch=10 train_loss=0.2590 val_loss=0.0025 val_domain_acc=0.9975
|
| 12 |
+
[ 20903s] epoch=11 train_loss=0.2465 val_loss=0.0025 val_domain_acc=0.9975
|
| 13 |
+
[ 20972s] epoch=12 train_loss=0.2338 val_loss=0.0025 val_domain_acc=0.9975
|
| 14 |
+
[ 20972s] early stop at epoch 12
|
| 15 |
+
[ 20981s] saved /home/fgxcs/development/khaos/models/graph_subgraph_embedding/v1
|
train_config.json
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"epochs": 30,
|
| 3 |
+
"batch": 16,
|
| 4 |
+
"lr": 0.0005,
|
| 5 |
+
"architecture": "GraphTransformerEncoder"
|
| 6 |
+
}
|