Models¶
hyperbench.models
¶
CommonNeighbors
¶
Bases: Module
Source code in hyperbench/models/common_neighbors.py
forward(hyperedge_index, node_to_neighbors=None)
¶
Compute CN scores for all hyperedges in the batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Tensor containing the hyperedge indices. |
required |
node_to_neighbors
|
dict[int, Neighborhood] | None
|
Optional mapping from nodes to their neighborhoods. |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
A 1-D tensor of shape (num_hyperedges,) with CN scores. |
Source code in hyperbench/models/common_neighbors.py
GCN
¶
Bases: Module
A reusable multi-layer GCN stack built from torch_geometric.nn.GCNConv.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
Dimension of the input node embeddings to the GCN layers. |
required |
out_channels
|
int
|
Dimension of the output node embeddings from the GCN layers. |
required |
hidden_channels
|
int | None
|
Dimension of the hidden node embeddings in the GCN layers.
Defaults to |
None
|
num_layers
|
int
|
Number of GCN layers. Must be at least 1. Defaults to |
2
|
drop_rate
|
float
|
Dropout rate applied after each GCN layer except the last one. |
0.0
|
bias
|
bool
|
Whether to include a bias term in the GCN layers. |
True
|
activation_fn
|
ActivationFn | None
|
Activation function to use after each hidden layer. Defaults to |
None
|
activation_fn_kwargs
|
dict | None
|
Keyword arguments for the activation function. Defaults to empty dict. |
None
|
improved
|
bool
|
Whether to use the improved version of |
False
|
add_self_loops
|
bool
|
Whether to add self-loops to the input graph. |
True
|
normalize
|
bool
|
Whether to symmetrically normalize the adjacency matrix in |
True
|
cached
|
bool
|
Whether to cache the normalized adjacency matrix in |
False
|
Source code in hyperbench/models/gcn.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 | |
GCNConfig
¶
Bases: TypedDict
Configuration for the GCN model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
Dimension of the input node embeddings to the GCN layers. |
required | |
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 | |
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 | |
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 |
Source code in hyperbench/models/gcn.py
HGNN
¶
Bases: Module
HGNN performs spectral convolution directly on the hypergraph structure using the
node-hyperedge incidence matrix, without any reduction to a pairwise graph.
Unlike HyperGCN (which approximates each hyperedge by selecting representative pairwise
edges via random projection), HGNN preserves all higher-order relationships by passing
messages through the full incidence structure: nodes -> hyperedges -> nodes.
- Proposed in Hypergraph Neural Networks <https://arxiv.org/pdf/1809.09401>_ paper (AAAI 2019).
- Reference implementation: source <https://deephypergraph.readthedocs.io/en/latest/_modules/dhg/models/hypergraphs/hgnn.html#HGNN>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
The number of input channels. |
required |
hidden_channels
|
int
|
The number of hidden channels. |
required |
num_classes
|
int
|
The number of output channels. |
required |
bias
|
bool
|
If set to |
True
|
use_batch_normalization
|
bool
|
If set to |
False
|
drop_rate
|
float
|
Dropout ratio. Defaults to |
0.5
|
Source code in hyperbench/models/hgnn.py
forward(x, hyperedge_index)
¶
Apply two stacked HGNNConv layers to produce node embeddings.
The first layer applies ReLU + dropout and maps in_channels -> hidden_channels.
The second layer is the output layer (no activation/dropout) and maps
hidden_channels -> num_classes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input node feature matrix. Size |
required |
hyperedge_index
|
Tensor
|
Hyperedge incidence in COO format. Size |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The output node feature matrix. Size |
Source code in hyperbench/models/hgnn.py
HNHN
¶
Bases: Module
HNHN performs incidence-based hypergraph convolution with explicit hyperedge
embeddings between the node -> hyperedge -> node propagation steps.
- Proposed in HNHN: Hypergraph Networks with Hyperedge Neurons <https://arxiv.org/abs/2006.12278>_ paper.
- Reference implementation: source <https://deephypergraph.readthedocs.io/en/latest/_modules/dhg/models/hypergraphs/hnhn.html#HNHN>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
The number of input channels. |
required |
hidden_channels
|
int
|
The number of hidden channels. |
required |
num_classes
|
int
|
The number of output channels. |
required |
bias
|
bool
|
If set to |
True
|
use_batch_normalization
|
bool
|
If set to |
False
|
drop_rate
|
float
|
Dropout ratio. Defaults to |
0.5
|
Source code in hyperbench/models/hnhn.py
forward(x, hyperedge_index)
¶
Apply two stacked HNHNConv layers to produce node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input node feature matrix of size |
required |
hyperedge_index
|
Tensor
|
Hyperedge incidence in COO format of size |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The output node feature matrix of size |
Source code in hyperbench/models/hnhn.py
HGNNP
¶
Bases: Module
HGNN+ performs hypergraph convolution with two-stage mean aggregation using the
incidence structure directly: nodes -> hyperedges -> nodes.
- Proposed in HGNN+: General Hypergraph Neural Networks <https://ieeexplore.ieee.org/document/9795251>_ paper (IEEE T-PAMI 2022).
- Reference implementation: source <https://deephypergraph.readthedocs.io/en/latest/_modules/dhg/models/hypergraphs/hgnnp.html#HGNNP>_.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
The number of input channels. |
required |
hidden_channels
|
int
|
The number of hidden channels. |
required |
num_classes
|
int
|
The number of output channels. |
required |
bias
|
bool
|
If set to |
True
|
use_batch_normalization
|
bool
|
If set to |
False
|
drop_rate
|
float
|
Dropout ratio. Defaults to |
0.5
|
Source code in hyperbench/models/hgnnp.py
forward(x, hyperedge_index)
¶
Apply two stacked HGNNPConv layers to produce node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input node feature matrix. Size |
required |
hyperedge_index
|
Tensor
|
Hyperedge incidence in COO format. Size |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The output node feature matrix. Size |
Source code in hyperbench/models/hgnnp.py
HyperGCN
¶
Bases: Module
HyperGCN approximates each hyperedge of the hypergraph by a set of pairwise edges connecting the vertices of the hyperedge
and treats the learning problem as a graph learning problem on the approximation.
- Proposed in HyperGCN: A New Method of Training Graph Convolutional Networks on Hypergraphs <https://dl.acm.org/doi/10.5555/3454287.3454422>_ paper (NeurIPS 2019).
- Code of the paper: source <https://github.com/malllabiisc/HyperGCN>.
- Reference implementation: source <https://deephypergraph.readthedocs.io/en/latest/_modules/dhg/models/hypergraphs/hypergcn.html#HyperGCN>.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
The number of input channels. |
required |
hidden_channels
|
int
|
The number of hidden channels. |
required |
num_classes
|
int
|
The number of classes of the classification task as HyperGCB is a node classification model. |
required |
bias
|
bool
|
If set to |
True
|
use_batch_normalization
|
bool
|
If set to |
False
|
drop_rate
|
float
|
Dropout ratio. Defaults to |
0.5
|
use_mediator
|
bool
|
Whether to use mediator to transform the hyperedges to edges in the graph. Defaults to |
False
|
fast
|
bool
|
If set to |
True
|
Source code in hyperbench/models/hypergcn.py
forward(x, hyperedge_index)
¶
The forward function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Input node feature matrix. Size |
required |
hyperedge_index
|
Tensor
|
The hyperedge indices of the hypergraph. Size |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
The output node feature matrix. Size |
Source code in hyperbench/models/hypergcn.py
MLP
¶
Bases: Module
A simple multi-layer perceptron (MLP) with configurable number of layers, hidden channels, activation functions, normalization, and dropout.
Examples:
>>> mlp = MLP(in_channels=16, out_channels=1, hidden_channels=32, num_layers=3)
>>> x = torch.randn(10, 16) # 10 samples, 16 features
>>> output = mlp(x)
>>> output.shape
... torch.Size([10, 1])
With custom activation, normalization, and dropout:
>>> mlp = MLP(
... in_channels=16,
... out_channels=1,
... hidden_channels=32,
... num_layers=3,
... activation_fn=nn.Tanh, # nn.ReLU, nn.LeakyReLU, etc.
... activation_fn_kwargs={"inplace": True},
... normalization_fn=nn.BatchNorm1d, # nn.LayerNorm, etc.
... normalization_fn_kwargs={"eps": 1e-5},
... drop_rate=0.5,
... )
>>> x = torch.randn(10, 16)
>>> output = mlp(x)
>>> output.shape
... torch.Size([10, 1])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
Number of input features. |
required |
out_channels
|
int
|
Number of output features. |
required |
hidden_channels
|
int | None
|
Number of hidden units in each hidden layer. Required if num_layers > 1. |
None
|
num_layers
|
int
|
Total number of layers (including output layer). Must be at least 1. Defaults to 1. |
1
|
activation_fn
|
ActivationFn | None
|
Activation function to use after each hidden layer. Defaults to |
None
|
activation_fn_kwargs
|
dict | None
|
Keyword arguments for the activation function. Defaults to empty dict. |
None
|
normalization_fn
|
NormalizationFn | None
|
Normalization function to use after each hidden layer (before activation). If |
None
|
normalization_fn_kwargs
|
dict | None
|
Keyword arguments for the normalization function. Defaults to empty dict. |
None
|
bias
|
bool
|
Whether to include bias terms in the linear layers. Defaults to |
True
|
drop_rate
|
float
|
Dropout rate to apply after each hidden layer (after activation). If 0.0, no dropout is applied. Defaults to 0.0. |
0.0
|
Source code in hyperbench/models/mlp.py
SLP
¶
Bases: MLP
A single-layer perceptron (SLP) which is a special case of MLP with exactly one layer and no hidden units.
Examples:
>>> slp = SLP(in_channels=16, out_channels=1)
>>> x = torch.randn(10, 16) # 10 samples, 16 features
>>> output = slp(x)
>>> output.shape
... torch.Size([10, 1])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
Number of input features. |
required |
out_channels
|
int
|
Number of output features. |
required |
Source code in hyperbench/models/mlp.py
NHP
¶
Bases: Module
Neural Hyperlink Predictor (NHP) for undirected hyperedge link prediction.
- Proposed in NHP: Neural Hypergraph Link Prediction <https://dl.acm.org/doi/10.1145/3340531.3411870>_ paper (CIKM 2020).
- Reference implementation: source <https://github.com/cyixiao/NHP-reproduce/>_.
NHP scores each candidate hyperedge by building candidate-specific node embeddings. A node that appears in multiple candidate hyperedges can receive a different incidence embedding in each one, because its update depends on the other nodes in that candidate hyperedge.
Examples:
>>> x = [
... [1., 0.], # node 0
... [0., 1.], # node 1
... [1., 1.], # node 2
... [1., 0.], # node 3
... ]
>>> hyperedge_index = [
... [0, 1, 1, 2, 3], # node IDs
... [0, 0, 1, 1, 1], # hyperedge IDs
... ]
>>> # hyperedge 0 = {node 0, node 1}
>>> # hyperedge 1 = {node 1, node 2, node 3}
>>> model = NHP(in_channels=2, hidden_channels=8, aggregation="maxmin")
>>> scores = model(x, hyperedge_index)
>>> scores.shape
... torch.Size([2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
in_channels
|
int
|
Number of input features per node. |
required |
hidden_channels
|
int
|
Number of hidden units in the node embeddings. |
required |
activation_fn
|
ActivationFn | None
|
Activation function to use after the linear transformations. Defaults to |
None
|
activation_fn_kwargs
|
dict | None
|
Keyword arguments for the activation function. Defaults to empty dict. |
None
|
aggregation
|
Literal['mean', 'maxmin']
|
Method to aggregate the incidence embeddings into a hyperedge embedding. Must be either "maxmin" or "mean". Defaults to "maxmin". |
'maxmin'
|
bias
|
bool
|
Whether to include bias terms in the linear layers. Defaults to |
True
|
Source code in hyperbench/models/nhp.py
9 10 11 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 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 | |
forward(x, hyperedge_index)
¶
Score each candidate hyperedge.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
Returns:
| Type | Description |
|---|---|
Tensor
|
Scores of shape |
Source code in hyperbench/models/nhp.py
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 | |
Node2Vec
¶
Bases: Module
Node2Vec implementation based on torch_geometric.nn.Node2Vec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
Tensor
|
Edge index representing the graph structure. Size |
required |
embedding_dim
|
int
|
Dimension of the node embeddings to learn. |
required |
walk_length
|
int
|
Length of each random walk. |
20
|
context_size
|
int
|
Window size for the skip-gram model (number of neighbors in the walk considered as context).
For example, if |
10
|
num_walks_per_node
|
int
|
Number of random walks to start at each node. |
10
|
p
|
float
|
Return hyperparameter for Node2Vec. Default is |
1.0
|
q
|
float
|
In-out hyperparameter for Node2Vec. Default is |
1.0
|
num_negative_samples
|
int
|
Number of negative samples to use for training the skip-gram model.
If set to |
1
|
num_nodes
|
int | None
|
Total number of nodes in the graph. If not provided, it will be inferred from the hyperedge_index. This is only needed if the hyperedge_index does not include all nodes (e.g., some isolated nodes are missing). |
None
|
sparse
|
bool
|
Whether Node2Vec embeddings should use sparse gradients. |
True
|
Source code in hyperbench/models/node2vec.py
Node2VecConfig
¶
Bases: TypedDict
Configuration for the Node2Vec model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
edge_index
|
Edge index representing the graph structure. Size |
required | |
embedding_dim
|
Dimension of the node embeddings to learn. |
required | |
walk_length
|
Length of each random walk. |
required | |
context_size
|
Window size for the skip-gram model (number of neighbors in the walk considered as context).
For example, if |
required | |
num_walks_per_node
|
Number of random walks to start at each node. |
required | |
p
|
Return hyperparameter for Node2Vec. Default is |
required | |
q
|
In-out hyperparameter for Node2Vec. Default is |
required | |
num_negative_samples
|
Number of negative samples to use for training the skip-gram model.
If set to |
required | |
num_nodes
|
Total number of nodes in the graph. If not provided, it will be inferred from the hyperedge_index. This is only needed if the hyperedge_index does not include all nodes (e.g., some isolated nodes are missing). |
required | |
sparse
|
Whether Node2Vec embeddings should use sparse gradients. |
required |
Source code in hyperbench/models/node2vec.py
Node2VecGCN
¶
Bases: Module
A joint encoder that first learns Node2Vec embeddings and then refines them with GCN layers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node2vec_config
|
Node2VecConfig
|
Model-side configuration for the internal |
required |
gcn_config
|
GCNConfig
|
Model-side configuration for the GCN stack applied to the Node2Vec embeddings. |
required |
Source code in hyperbench/models/node2vec.py
VilLain
¶
Bases: Module
VilLain learns node-specific virtual-label logits instead of consuming existing node features.
The model is transductive: rows in node_embedding correspond to the fixed global node space used during training.
- Proposed in VilLain: Self-Supervised Learning on Homogeneous Hypergraphs without Features via Virtual Label Propagation <https://dl.acm.org/doi/pdf/10.1145/3589334.3645454>_ paper (WWW 2024).
- Reference implementation: source <https://github.com/geon0325/VilLain/>_.
Each forward pass: 1. Samples differentiable virtual-label assignments with Gumbel-Softmax. 2. Propagates them over the incidence structure. 3. Returns averaged propagated node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_nodes
|
int
|
Total number of trainable nodes. |
required |
embedding_dim
|
int
|
Returned embedding dimension. Defaults to |
128
|
labels_per_subspace
|
int
|
Number of virtual labels per subspace. Defaults to |
2
|
training_steps
|
int
|
Propagation steps used for self-supervised loss. Defaults to |
4
|
generation_steps
|
int
|
Propagation steps averaged for final embeddings. Defaults to |
100
|
tau
|
float
|
Gumbel-Softmax temperature. Defaults to |
1.0
|
eps
|
float
|
Numerical stability constant. Defaults to |
1e-10
|
Source code in hyperbench/models/villain.py
11 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 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 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 | |
forward(hyperedge_index, node_ids=None, num_hyperedges=None)
¶
Compute the self-supervised VilLain objective.
Use hyperedge_embeddings or node_embeddings to generate final embeddings for inference after training.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting. Use this when a batch has rebased local node ids but the learned logits live in the full transductive node table. This is needed as the model keeps an internal embedding table with a row for every node in the global node space. |
None
|
num_hyperedges
|
int | None
|
Optional explicit hyperedge count used during node-to-hyperedge pooling to preserve empty hyperedges.
If not provided, the hyperedge count is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, VilLainLossParts]
|
Node embeddings of shape |
Source code in hyperbench/models/villain.py
loss(hyperedge_index, node_ids=None, num_hyperedges=None)
¶
Compute the self-supervised VilLain objective.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting. Use this when a batch has rebased local node ids but the learned logits live in the full transductive node table. This is needed as the model keeps an internal embedding table with a row for every node in the global node space. |
None
|
num_hyperedges
|
int | None
|
Optional explicit hyperedge count used during node-to-hyperedge pooling to preserve empty hyperedges.
If not provided, the hyperedge count is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
tuple[Tensor, VilLainLossParts]
|
A tuple |
Source code in hyperbench/models/villain.py
hyperedge_embeddings(hyperedge_index, node_ids=None, num_hyperedges=None)
¶
Generate hyperedge embeddings by averaging propagated hyperedge states. Every generation step computes hyperedge states from the current node states, then updates node states for the next step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting. Use this when a batch has rebased local node ids but the learned logits live in the full transductive node table. This is needed as the model keeps an internal embedding table with a row for every node in the global node space. |
None
|
num_hyperedges
|
int | None
|
Optional explicit hyperedge count used during node-to-hyperedge pooling to preserve empty hyperedges.
If not provided, the hyperedge count is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Hyperedge embeddings of shape |
Source code in hyperbench/models/villain.py
node_embeddings(hyperedge_index, node_ids=None, num_hyperedges=None)
¶
Generate node embeddings by averaging propagated node states.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting. Use this when a batch has rebased local node ids but the learned logits live in the full transductive node table. This is needed as the model keeps an internal embedding table with a row for every node in the global node space. |
None
|
num_hyperedges
|
int | None
|
Optional explicit hyperedge count used during node-to-hyperedge pooling to preserve empty hyperedges.
If not provided, the hyperedge count is inferred from |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Node embeddings of shape |
Source code in hyperbench/models/villain.py
reset_parameters()
¶
__embeddings(hyperedge_index, node_ids, num_hyperedges, mode='node')
¶
Generate final node or hyperedge embeddings for inference.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Incidence tensor of shape |
required |
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting. |
required |
num_hyperedges
|
int | None
|
Optional explicit hyperedge count to preserve empty hyperedges during propagation. |
required |
mode
|
Literal['node', 'hyperedge']
|
Selects whether to accumulate propagated node states or hyperedge states. |
'node'
|
Returns:
| Type | Description |
|---|---|
Tensor
|
Averaged embeddings truncated to |
Source code in hyperbench/models/villain.py
__get_initial_virtual_node_features(node_ids=None)
¶
Convert trainable node logits into flattened virtual-label probabilities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node_ids
|
Tensor | None
|
Optional global node ids matching local node ids the embedding table in the transductive setting.
If |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
A tensor of shape |
Source code in hyperbench/models/villain.py
__message_passing(x, hyperedge_index, num_hyperedges)
¶
One round of message passing, where nodes send messages to hyperedges and then hyperedges send messages back to nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Virtual node features of shape (num_nodes, raw_embedding_dim). |
required |
hyperedge_index
|
Tensor
|
Hyperedge index tensor of shape (2, num_edges). |
required |
num_hyperedges
|
int
|
Total number of hyperedges. |
required |
Returns:
| Type | Description |
|---|---|
tuple[Tensor, Tensor]
|
The updated node and hyperedge embeddings after one round of message passing. |
Source code in hyperbench/models/villain.py
__num_hyperedges(hyperedge_index, num_hyperedges)
¶
Return the explicit hyperedge count or infer it from the hyperedge_index, if not provided.
Explicit counts are required when empty hyperedges must remain in the hypergraph.