HLP¶
hyperbench.hlp
¶
CommonNeighborsHlpModule
¶
Bases: HlpModule
A LightningModule for the CommonNeighbors model with optional negative sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aggregation
|
Literal['mean', 'min', 'sum']
|
The aggregation method for common neighbors ("mean", "min", or "sum"). |
'mean'
|
decoder
|
Module | None
|
An optional decoder module. Defaults to :class: |
None
|
loss_fn
|
Module | None
|
An optional loss function. Defaults to |
None
|
metrics
|
MetricCollection | None
|
An optional dictionary of metric functions. |
None
|
Source code in hyperbench/hlp/common_neighbors_hlp.py
forward(hyperedge_index)
¶
Compute common neighbor scores for the given hyperedges.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Tensor containing incidence information for the hyperedges to score. |
required |
Source code in hyperbench/hlp/common_neighbors_hlp.py
on_fit_start()
¶
Warn users if they are running unnecessary training epochs.
Source code in hyperbench/hlp/common_neighbors_hlp.py
__step(batch, stage)
¶
Shared evaluation logic for all stages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
:class: |
required |
stage
|
Stage
|
The current stage of evaluation (e.g., |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The computed loss. |
Source code in hyperbench/hlp/common_neighbors_hlp.py
GCNEncoderConfig
¶
Bases: TypedDict
Configuration for the GCN encoder in GCNHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
hidden_channels
|
Number of hidden units in the intermediate GCN layers. |
required | |
num_layers
|
Number of GCN layers. Defaults to |
required | |
drop_rate
|
Dropout rate applied after each hidden GCN layer. Defaults to |
required | |
bias
|
Whether to include bias terms. Defaults to |
required | |
improved
|
Whether to use the improved GCN normalization. Defaults to |
required | |
add_self_loops
|
Whether to add self-loops before convolution. Defaults to |
required | |
normalize
|
Whether to normalize the adjacency matrix in |
required | |
cached
|
Whether to cache the normalized graph in |
required | |
graph_reduction_strategy
|
Strategy for reducing the hypergraph to a graph. Defaults to |
required | |
activation_fn
|
Activation function to use after each hidden layer. Defaults to |
required | |
activation_fn_kwargs
|
Keyword arguments for the activation function. Defaults to empty dict. |
required |
Source code in hyperbench/hlp/gcn_hlp.py
GCNHlpModule
¶
Bases: HlpModule
A LightningModule for GCN-based HLP.
Uses a graph reduction of the input hypergraph to run GCN over nodes, aggregates node embeddings per hyperedge, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
GCNEncoderConfig
|
Configuration for the GCN encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. Defaults to |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/gcn_hlp.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 | |
forward(x, hyperedge_index)
¶
Reduce the hypergraph to a graph, encode nodes with GCN, aggregate per hyperedge, and score.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Logit scores of shape |
Source code in hyperbench/hlp/gcn_hlp.py
HGNNHlpModule
¶
Bases: HlpModule
A LightningModule for HGNN-based Hyperedge Link Prediction.
Uses HGNN as an encoder to produce structure-aware node embeddings via spectral hypergraph convolution, aggregates them per hyperedge, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
HGNNEncoderConfig
|
Configuration for the HGNN encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. Defaults to |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/hgnn_hlp.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
forward(x, hyperedge_index)
¶
Run the full HGNN-based hyperedge link prediction pipeline.
The pipeline has three stages:
1. Encode: HGNN applies two rounds of D_n^{-1/2} H D_e^{-1} H^T D_n^{-1/2}
smoothing to propagate information through the hypergraph topology (nodes ->
hyperedges -> nodes). The output is a structure-aware node embedding matrix of
shape (num_nodes, out_channels).
2. Aggregate: For each hyperedge being scored, pool the embeddings of its member
nodes using the configured strategy (mean/max/min/sum). This produces a hyperedge
embedding that summarizes the collective representation of the hyperedge's nodes.
Shape: (num_hyperedges, out_channels).
3. Decode: A single linear layer (SLP) projects each hyperedge embedding to a
scalar score representing the likelihood that the hyperedge is a real (positive)
hyperedge. Shape: (num_hyperedges,).
Examples:
Given 5 nodes with 8 features and 2 hyperedges::
>>> x.shape # (5, 8) - all nodes in the hypergraph
>>> hyperedge_index = [[0, 1, 2, 3, 4], # node IDs
... [0, 0, 0, 1, 1]] # hyperedge IDs
The forward pass:
1. HGNN encodes all 5 nodes using the hypergraph Laplacian.
node_embeddings.shape = (5, out_channels)
2. Aggregate per hyperedge:
- hyperedge 0: pool(emb[0], emb[1], emb[2])
- hyperedge 1: pool(emb[3], emb[4])
hyperedge_embeddings.shape = (2, out_channels)
3. Decode: one scalar per hyperedge -> scores.shape = (2,)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Logit scores of shape |
Tensor
|
probabilities, or use directly with |
Source code in hyperbench/hlp/hgnn_hlp.py
HGNNEncoderConfig
¶
Bases: TypedDict
Configuration for the HGNN encoder in HGNNHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
hidden_channels
|
Number of hidden units in the intermediate HGNN layer. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
bias
|
Whether to include bias terms. Defaults to |
required | |
use_batch_normalization
|
Whether to use batch normalization. Defaults to |
required | |
drop_rate
|
Dropout rate. Defaults to |
required |
Source code in hyperbench/hlp/hgnn_hlp.py
HNHNEncoderConfig
¶
Bases: TypedDict
Configuration for the HNHN encoder in HNHNHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
hidden_channels
|
Number of hidden units in the intermediate HNHN layer. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
bias
|
Whether to include bias terms. Defaults to |
required | |
use_batch_normalization
|
Whether to use batch normalization. Defaults to |
required | |
drop_rate
|
Dropout rate. Defaults to |
required |
Source code in hyperbench/hlp/hnhn_hlp.py
HNHNHlpModule
¶
Bases: HlpModule
A LightningModule for HNHN-based Hyperedge Link Prediction.
Uses HNHN as an encoder to produce node embeddings through explicit hyperedge neurons, aggregates them per hyperedge, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
HNHNEncoderConfig
|
Configuration for the HNHN encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. Defaults to |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
scheduler_step_size
|
int
|
Step size for learning rate scheduler. Defaults to |
100
|
scheduler_gamma
|
float
|
Multiplicative factor for learning rate decay. Defaults to |
0.51
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/hnhn_hlp.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 | |
forward(x, hyperedge_index)
¶
Run the full HNHN-based hyperedge link prediction pipeline.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Logit scores of shape |
Source code in hyperbench/hlp/hnhn_hlp.py
HGNNPEncoderConfig
¶
Bases: TypedDict
Configuration for the HGNN+ encoder in HGNNPHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
hidden_channels
|
Number of hidden units in the intermediate HGNN+ layer. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
bias
|
Whether to include bias terms. Defaults to |
required | |
use_batch_normalization
|
Whether to use batch normalization. Defaults to |
required | |
drop_rate
|
Dropout rate. Defaults to |
required |
Source code in hyperbench/hlp/hgnnp_hlp.py
HGNNPHlpModule
¶
Bases: HlpModule
A LightningModule for HGNN+-based Hyperedge Link Prediction.
Uses HGNN+ as an encoder to produce structure-aware node embeddings via row-stochastic hypergraph convolution, aggregates them per hyperedge, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
HGNNPEncoderConfig
|
Configuration for the HGNN+ encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. Defaults to |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/hgnnp_hlp.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 | |
forward(x, hyperedge_index)
¶
Run the full HGNN+-based hyperedge link prediction pipeline.
The pipeline has three stages:
1. Encode: HGNN+ applies two rounds of D_v^{-1} H D_e^{-1} H^T
smoothing to propagate information through the hypergraph topology with
two-stage mean aggregation. The output is a structure-aware node
embedding matrix of shape (num_nodes, out_channels).
2. Aggregate: For each hyperedge being scored, pool the embeddings of its member
nodes using the configured strategy (mean/max/min/sum). This produces a hyperedge
embedding of shape (num_hyperedges, out_channels).
3. Decode: A single linear layer projects each hyperedge embedding to a
scalar score. Shape: (num_hyperedges,).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Logit scores of shape |
Source code in hyperbench/hlp/hgnnp_hlp.py
HlpModule
¶
Bases: LightningModule
A LightningModule for HLP models with optional negative sampling.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder
|
Module | None
|
Optional encoder module. Defaults to |
None
|
decoder
|
Module
|
Decoder module to use to predict whether hyperedges are positive or negative. |
required |
loss_fn
|
Module
|
Loss function. |
required |
metrics
|
MetricCollection | None
|
Optional |
None
|
negative_sampler
|
NegativeSampler | None
|
Optional negative sampler. If |
None
|
negative_sampling_schedule
|
NegativeSamplingSchedule
|
When to perform negative sampling during training. Defaults to |
EVERY_EPOCH
|
negative_sampling_every_n
|
int
|
If using |
1
|
Source code in hyperbench/hlp/common.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
HyperGCNHlpModule
¶
Bases: HlpModule
A LightningModule for HyperGCN-based Hyperedge Link Prediction.
Uses HyperGCN as an encoder to produce structure-aware node embeddings via graph convolution on the full hypergraph, aggregates them per hyperedge, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
HyperGCNEncoderConfig
|
Configuration for the HyperGCN encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. Defaults to |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/hypergcn_hlp.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 | |
forward(x, hyperedge_index)
¶
Encode node features via HyperGCN, aggregate per hyperedge, and score.
Steps
- Encode: HyperGCN builds a GCN Laplacian from
hyperedge_indexand applies message passing to produce structure-aware node embeddings. - Aggregate: For each hyperedge, aggregate its member nodes' embeddings using the configured pooling method (mean/max/min/sum).
- Decode: A linear layer scores each hyperedge embedding.
Examples:
Given 5 nodes with 3 features and 2 hyperedges::
>>> x.shape # (5, 3) — all nodes in the hypergraph
>>> hyperedge_index = [[0, 1, 2, 3, 4], # node IDs (global)
... [0, 0, 0, 1, 1]] # hyperedge IDs
The forward pass:
1. HyperGCN encodes all 5 nodes using the full graph Laplacian.
node_embeddings.shape = (5, out_channels)
2. Aggregate per hyperedge:
- hyperedge 0: pool(emb[0], emb[1], emb[2])
- hyperedge 1: pool(emb[3], emb[4])
3. Decode: one scalar score per hyperedge → scores.shape = (2,)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scores of shape |
Source code in hyperbench/hlp/hypergcn_hlp.py
HyperGCNEncoderConfig
¶
Bases: TypedDict
Configuration for the HyperGCN encoder in HyperGCNHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
hidden_channels
|
Number of hidden units in the intermediate HyperGCN layer. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
bias
|
Whether to include bias terms. Defaults to |
required | |
use_batch_normalization
|
Whether to use batch normalization. Defaults to |
required | |
drop_rate
|
Dropout rate. Defaults to |
required | |
use_mediator
|
Whether to use mediator nodes for hyperedge-to-edge conversion. Defaults to |
required | |
fast
|
Whether to cache the graph structure after first computation. Defaults to |
required |
Source code in hyperbench/hlp/hypergcn_hlp.py
MLPHlpModule
¶
Bases: HlpModule
A LightningModule for MLP-based Hyperedge Link Prediction.
Uses an MLP encoder to produce node embeddings, aggregates them per hyperedge via mean pooling, and scores each hyperedge with a linear decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
MlpEncoderConfig
|
Configuration for the MLP encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
metrics
|
MetricCollection | None
|
Optional dictionary of metric functions. |
None
|
Source code in hyperbench/hlp/mlp_hlp.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
forward(x, hyperedge_index)
¶
Encode node features, aggregate per hyperedge via mean pooling, and score.
Examples:
Given 4 nodes with 3 features each and 2 hyperedges: >>> x = [[0.1, 0.2, 0.3], # node 0 ... [0.4, 0.5, 0.6], # node 1 ... [0.7, 0.8, 0.9], # node 2 ... [1.0, 1.1, 1.2]] # node 3
>>> # hyperedge 0 = {node 0, node 1, node 2}
>>> # hyperedge 1 = {node 2, node 3}
>>> hyperedge_index = [[0, 1, 2, 2, 3], # node ids
... [0, 0, 0, 1, 1]] # hyperedge ids
The forward pass: 1. Encoder maps each node to an embedding vector. 2. Aggregate embeddings by summing them per hyperedge: - hyperedge 0: emb[0] + emb[1] + emb[2] - hyperedge 1: emb[2] + emb[3] 3. Sums are divided by the number of nodes per hyperedge (mean pooling): - hyperedge 0: (emb[0] + emb[1] + emb[2]) / 3 - hyperedge 1: (emb[2] + emb[3]) / 2 4. Decoder scores each hyperedge embedding, producing one scalar per hyperedge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scores of shape |
Source code in hyperbench/hlp/mlp_hlp.py
MlpEncoderConfig
¶
Bases: TypedDict
Configuration for the MLP encoder in MLPHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
out_channels
|
Number of output features (embedding size) per node. |
required | |
num_layers
|
Number of layers in the MLP encoder. |
required | |
hidden_channels
|
Optional number of hidden units per layer. If |
required | |
activation_fn
|
Optional activation function class to use in the MLP encoder. If |
required | |
activation_fn_kwargs
|
Optional dictionary of keyword arguments to pass to the activation function constructor. |
required | |
normalization_fn
|
Optional normalization function class to use in the MLP encoder. If |
required | |
normalization_fn_kwargs
|
Optional dictionary of keyword arguments to pass to the normalization function constructor. |
required | |
bias
|
Whether to include bias terms in the MLP layers. Defaults to |
required | |
drop_rate
|
Dropout rate to apply after each MLP layer (except the last one). Defaults to |
required |
Source code in hyperbench/hlp/mlp_hlp.py
NHPEncoderConfig
¶
Bases: TypedDict
Configuration for the NHP encoder/scorer to be used for hyperedge link prediction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Number of input features per node. |
required | |
hidden_channels
|
Number of hidden channels for incidence embeddings. Defaults to |
required | |
aggregation
|
Hyperedge scoring aggregation. |
required | |
bias
|
Whether to include bias terms. Defaults to |
required |
Source code in hyperbench/hlp/nhp_hlp.py
NHPHlpModule
¶
Bases: HlpModule
A LightningModule for undirected NHP hyperedge link prediction.
NHP encodes and scores candidate hyperedges in a single pass. Unlike encoder wrappers that produce reusable global node embeddings, NHP builds candidate-specific incidence embeddings before pooling and scoring each hyperedge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
NHPEncoderConfig
|
Configuration for the NHP encoder/scorer. |
required |
loss_fn
|
Module | None
|
Loss function. Defaults to :class: |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0005
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. |
None
|
Source code in hyperbench/hlp/nhp_hlp.py
forward(x, hyperedge_index)
¶
Encode and score each candidate hyperedge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scores of shape |
Source code in hyperbench/hlp/nhp_hlp.py
NHPRankingLoss
¶
Bases: Module
Ranking loss that pushes positive hyperedges above sampled negatives.
Examples:
>>> logits = [2.0, 1.0, -1.0]
>>> labels = [1.0, 1.0, 0.0]
>>> loss = NHPRankingLoss()
>>> loss(logits, labels)
>>> loss.ndim
... 0
Source code in hyperbench/nn/loss.py
forward(logits, labels)
¶
Compute the ranking loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
logits
|
Tensor
|
Logit scores for each candidate hyperedge, of shape |
required |
labels
|
Tensor
|
Binary labels indicating positive (1) and negative (0) hyperedges, of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scalar loss value. |
Source code in hyperbench/nn/loss.py
Node2VecGCNHlpConfig
¶
Bases: TypedDict
Configuration for the GCN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
out_channels
|
Dimension of the output node embeddings from the GCN layers. |
required | |
hidden_channels
|
Dimension of the hidden node embeddings in the GCN layers. |
required | |
num_layers
|
Number of GCN layers. Must be at least 1. Defaults to |
required | |
drop_rate
|
Dropout rate applied after each GCN layer (except the last one). Defaults to |
required | |
bias
|
Whether to include a bias term in the GCN layers. Defaults to |
required | |
improved
|
Whether to use the improved version of GCNConv. Defaults to |
required | |
add_self_loops
|
Whether to add self-loops to the input graph. Defaults to |
required | |
normalize
|
Whether to symmetrically normalize the adjacency matrix in GCNConv. Defaults to |
required | |
cached
|
Whether to cache the normalized adjacency matrix in GCNConv.
Only applicable if the graph structure does not change between epochs. Defaults to |
required | |
graph_reduction_strategy
|
Strategy for reducing the hyperedge graph. Defaults to |
required | |
activation_fn
|
Activation function to use after each hidden layer. Defaults to |
required | |
activation_fn_kwargs
|
Keyword arguments for the activation function. Defaults to empty dict. |
required |
Source code in hyperbench/hlp/node2vec_common.py
Node2VecHlpConfig
¶
Bases: TypedDict
Configuration for the Node2Vec encoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context_size
|
Skip-gram context size for Node2Vec.
For example, if |
required | |
walk_length
|
Length of each random walk. |
required | |
num_walks_per_node
|
Number of walks sampled per node. |
required | |
p
|
Node2Vec return parameter. Controls the probability of stepping back to the node visited
in the previous step. Lower values of |
required | |
q
|
Node2Vec in-out parameter. Controls whether walks stay near the source node or explore
further outward. Lower values of |
required | |
num_negative_samples
|
Number of negative samples per positive walk context.
If set to |
required | |
num_nodes
|
Number of nodes in the stable node space. Defaults to the number of nodes in the |
required | |
train_hyperedge_index
|
Training hypereddge index used to build the Node2Vec walk graph. Required in |
required | |
graph_reduction_strategy
|
Strategy for reducing the hyperedge graph. Defaults to |
required | |
random_walk_batch_size
|
Batch size used by the walk sampler in joint mode. |
required | |
node2vec_loss_weight
|
Weight applied to the Node2Vec walk loss in joint mode.
This is to decide how much the loss of Node2Vec contributes to the overall loss in joint training, relative to the HLP loss.
Defaults to |
required | |
sparse
|
Whether to use sparse gradients in the Node2Vec encoder. Defaults to |
required |
Source code in hyperbench/hlp/node2vec_common.py
Node2VecGCNEncoderConfig
¶
Bases: TypedDict
Configuration for the Node2Vec encoder in Node2VecGCNHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Whether to use precomputed node embeddings from |
required | |
num_features
|
Dimension of the node embeddings consumed by the decoder. |
required | |
node2vec_config
|
Shared Node2Vec configuration used in joint mode, or metadata for validating precomputed embeddings. |
required | |
gcn_config
|
Configuration for the GCN layers. |
required |
Source code in hyperbench/hlp/node2vecgcn_hlp.py
Node2VecGCNHlpModule
¶
Bases: HlpModule
A LightningModule for Node2Vec-based Hyperedge Link Prediction with GCN encoder.
Supports two modes:
- precomputed: use node embeddings already stored in batch.x.
- joint: train a Node2Vec encoder jointly with the GCN layers and hyperedge decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
Node2VecGCNEncoderConfig
|
Configuration for the Node2Vec encoder and GCN layers. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
Weight decay (L2 regularization) for the optimizer. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional dictionary of metric functions. |
None
|
Source code in hyperbench/hlp/node2vecgcn_hlp.py
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
Node2VecSLPEncoderConfig
¶
Bases: TypedDict
Configuration for the Node2Vec encoder in Node2VecSLPHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Whether to use precomputed node embeddings from |
required | |
num_features
|
Dimension of the node embeddings consumed by the decoder. |
required | |
node2vec_config
|
Shared Node2Vec configuration used in joint mode, or metadata for validating precomputed embeddings. |
required |
Source code in hyperbench/hlp/node2vecslp_hlp.py
Node2VecSLPHlpModule
¶
Bases: HlpModule
A LightningModule for Node2Vec-based Hyperedge Link Prediction.
Supports two modes:
- precomputed: use node embeddings already stored in batch.x.
- joint: train a Node2Vec encoder jointly with the hyperedge decoder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
Node2VecSLPEncoderConfig
|
Configuration for the Node2Vec encoder. |
required |
aggregation
|
Literal['mean', 'max', 'min', 'sum']
|
Method to aggregate node embeddings per hyperedge. |
'mean'
|
loss_fn
|
Module | None
|
Loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
Weight decay (L2 regularization) for the optimizer. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional dictionary of metric functions. |
None
|
Source code in hyperbench/hlp/node2vecslp_hlp.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
VilLainEncoderConfig
¶
Bases: TypedDict
Configuration for VilLainHlpModule.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
Total number of trainable nodes. |
required | |
embedding_dim
|
Returned node and hyperedge embedding dimension. Defaults to |
required | |
labels_per_subspace
|
Number of virtual labels per subspace. Defaults to |
required | |
training_steps
|
Propagation steps used for VilLain loss. Defaults to |
required | |
generation_steps
|
Propagation steps averaged by |
required | |
tau
|
Gumbel-Softmax temperature. Defaults to |
required | |
eps
|
Numerical stability constant. Defaults to |
required | |
villain_loss_weight
|
Weight applied to VilLain self-supervision. Defaults to |
required |
Source code in hyperbench/hlp/villain_hlp.py
VilLainHlpModule
¶
Bases: HlpModule
Feature-free VilLain Hyperedge Link Prediction module.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
VilLainEncoderConfig
|
Configuration for the VilLain encoder. |
required |
embedding_mode
|
Literal['node', 'hyperedge']
|
Whether to return node or hyperedge embeddings from the VilLain encoder. |
'node'
|
aggregation
|
Literal['mean', 'max', 'min', 'maxmin', 'sum']
|
Aggregation method to pool node embeddings into hyperedge embeddings when |
'maxmin'
|
loss_fn
|
Module | None
|
Loss function for the HLP task. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
Weight decay for the optimizer. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Metrics to compute during training and evaluation. Defaults to |
None
|
Source code in hyperbench/hlp/villain_hlp.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 | |