Node classification (NC)¶
hypertorch.node_classification
¶
NCClassifier
¶
Bases: LightningModule
A LightningModule base class for multiclass node-classification models.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module. Defaults to |
classifier |
Module
|
Module that maps node features to class logits. |
loss_fn |
Module
|
Multiclass loss function. |
metrics_log_kwargs |
dict[str, Any]
|
Keyword arguments passed to metric log calls. |
train_metrics |
MetricCollection | None
|
Optional training metrics. |
val_metrics |
MetricCollection | None
|
Optional validation metrics. |
test_metrics |
MetricCollection | None
|
Optional test metrics. |
Source code in hypertorch/node_classification/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 169 170 171 172 173 174 175 176 177 178 179 | |
__init__(classifier, loss_fn, encoder=None, metrics=None, metrics_log_kwargs=None)
¶
Initialize the NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier
|
Module
|
Module producing one class-logit row per node. |
required |
loss_fn
|
Module
|
Loss function used on supervised target nodes. |
required |
encoder
|
Module | None
|
Optional encoder module. Defaults to |
None
|
metrics
|
MetricCollection | None
|
Optional metric collection cloned independently per stage. |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls. |
None
|
Source code in hypertorch/node_classification/common.py
CommonNeighborsClassifier
¶
Bases: NCClassifier
A LightningModule for the CommonNeighbors-based NC classifier.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
Identity placeholder inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
node_to_neighbors |
dict[int, Neighborhood]
|
Precomputed training-world node neighborhoods. |
automatic_optimization |
bool
|
Disabled because this module has no trainable optimization. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
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 | |
__init__(train_hdata, num_classes, aggregation='sum', exclude_self_reference=True, classifier=None, loss_fn=None, metrics=None, metrics_log_kwargs=None)
¶
Initialize the CommonNeighbors-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data used to precompute neighborhoods and labeled reference nodes. |
required |
num_classes
|
int
|
Number of node classes. |
required |
aggregation
|
Literal['mean', 'min', 'sum']
|
Method used to aggregate reference-node scores per class.
Defaults to |
'sum'
|
exclude_self_reference
|
bool
|
Whether a node should ignore itself when it also
appears among labeled reference nodes. Defaults to |
True
|
classifier
|
Module | None
|
Optional classifier module. |
None
|
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Defaults to |
None
|
Source code in hypertorch/node_classification/common_neighbors_nc.py
forward(global_node_ids)
¶
Compute common-neighbor class scores for the given nodes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
global_node_ids
|
Tensor
|
Stable node IDs matching the training-world node IDs. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class scores of shape |
Source code in hypertorch/node_classification/common_neighbors_nc.py
on_fit_start()
¶
Warn users if they are running unnecessary training epochs.
Source code in hypertorch/node_classification/common_neighbors_nc.py
training_step(batch, batch_idx)
¶
Return a zero loss for the non-trainable heuristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch, unused. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Zero scalar tensor on the module device. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
validation_step(batch, batch_idx)
¶
Return a zero validation loss for the non-trainable heuristic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch, unused. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Zero scalar tensor on the module device. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
test_step(batch, batch_idx)
¶
Evaluate a test batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
predict_step(batch, batch_idx)
¶
Predict common-neighbor class scores for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class scores. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
configure_optimizers()
¶
Return no optimizer for the non-trainable heuristic.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
None
|
No optimizer is configured, so always returns |
__step(batch, stage)
¶
Shared evaluation logic for all stages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
|
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
__class_to_node_ids(train_hdata, num_classes)
¶
Group labeled training nodes by class.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data containing node labels and train node mask. |
required |
num_classes
|
int
|
Number of node classes. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
class_to_node_ids |
dict[int, list[int]]
|
Dictionary mapping class IDs to lists of node IDs. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
__default_classifier(train_hdata, num_classes, aggregation, exclude_self_reference=True)
¶
Create a default CommonNeighbors classifier with a CommonNeighborsNodeScorer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
train_hdata
|
HData
|
Training data containing node labels and train node mask. |
required |
num_classes
|
int
|
Number of node classes. |
required |
aggregation
|
Literal['mean', 'min', 'sum']
|
Method used to aggregate reference-node scores per class. |
required |
exclude_self_reference
|
bool
|
Whether a node should ignore itself when it also appears among labeled reference nodes. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
classifier |
CommonNeighbors
|
A CommonNeighbors classifier with a CommonNeighborsNodeScorer. |
Source code in hypertorch/node_classification/common_neighbors_nc.py
GCNClassifierConfig
¶
Bases: TypedDict
Configuration for the GCN classifier in GCNClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
out_channels |
int
|
Number of node classes. |
hidden_channels |
NotRequired[int]
|
Number of hidden units in intermediate GCN layers. |
num_layers |
NotRequired[int]
|
Number of GCN layers. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate applied after each hidden GCN layer. Defaults to |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
improved |
NotRequired[bool]
|
Whether to use the improved GCN normalization. Defaults to |
add_self_loops |
NotRequired[bool]
|
Whether to add self-loops before convolution. Defaults to |
normalize |
NotRequired[bool]
|
Whether to normalize the adjacency matrix in |
cached |
NotRequired[bool]
|
Whether to cache the normalized graph in |
graph_reduction_strategy |
NotRequired[GraphReductionStrategy]
|
Strategy for reducing the hypergraph to a graph.
Defaults to |
num_nodes |
NotRequired[int]
|
Optional total number of nodes to use during graph reduction. |
activation_fn |
NotRequired[ActivationFn]
|
Activation function to use after each hidden layer.
Defaults to |
activation_fn_kwargs |
NotRequired[dict]
|
Keyword arguments for the activation function. Defaults to empty dict. |
Source code in hypertorch/node_classification/gcn_nc.py
GCNClassifier
¶
Bases: NCClassifier
A LightningModule for GCN-based NC classifier.
Reduces the hypergraph to a graph, then applies GCN layers to produce per-node class logits.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
GCN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/node_classification/gcn_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the GCN-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
GCNClassifierConfig
|
Configuration for the GCN classifier. |
required |
loss_fn
|
Module | None
|
Optional 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. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/gcn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/gcn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/gcn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/gcn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/gcn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/gcn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/gcn_nc.py
HGNNClassifierConfig
¶
Bases: TypedDict
Configuration for the HGNN classifier in HGNNClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HGNN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/node_classification/hgnn_nc.py
HGNNClassifier
¶
Bases: NCClassifier
A LightningModule for HGNN-based NC classifier.
Uses HGNN to transform node features and hypergraph incidence structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HGNN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/node_classification/hgnn_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HGNN-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HGNNClassifierConfig
|
Configuration for the HGNN classifier. |
required |
loss_fn
|
Module | None
|
Optional 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. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/hgnn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/hgnn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/hgnn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/hgnn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/hgnn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/hgnn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/hgnn_nc.py
HNHNClassifierConfig
¶
Bases: TypedDict
Configuration for the HNHN classifier in HNHNClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HNHN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/node_classification/hnhn_nc.py
HNHNClassifier
¶
Bases: NCClassifier
A LightningModule for HNHN-based NC classifier.
Uses HNHN to transform node features and hypergraph incidence structure into
per-node class logits through explicit hyperedge neurons. During training,
validation, and testing, loss and metrics are computed on supervised target
nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HNHN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/node_classification/hnhn_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HNHN-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HNHNClassifierConfig
|
Configuration for the HNHN classifier. |
required |
loss_fn
|
Module | None
|
Optional 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. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/hnhn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/hnhn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/hnhn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/hnhn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/hnhn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/hnhn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/hnhn_nc.py
HGNNPClassifierConfig
¶
Bases: TypedDict
Configuration for the HGNN+ classifier in HGNNPClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HGNN+ layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
Source code in hypertorch/node_classification/hgnnp_nc.py
HGNNPClassifier
¶
Bases: NCClassifier
A LightningModule for HGNN+-based NC classifier.
Uses HGNN+ to transform node features and hypergraph incidence structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HGNN+ classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/node_classification/hgnnp_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HGNN+-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HGNNPClassifierConfig
|
Configuration for the HGNN+ classifier. |
required |
loss_fn
|
Module | None
|
Optional 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. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/hgnnp_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/hgnnp_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/hgnnp_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/hgnnp_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/hgnnp_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/hgnnp_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/hgnnp_nc.py
HyperGCNClassifierConfig
¶
Bases: TypedDict
Configuration for the HyperGCN classifier in HyperGCNClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
hidden_channels |
int
|
Number of hidden units in the intermediate HyperGCN layer. |
out_channels |
int
|
Number of node classes. |
bias |
NotRequired[bool]
|
Whether to include bias terms. Defaults to |
use_batch_normalization |
NotRequired[bool]
|
Whether to use batch normalization. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate. Defaults to |
use_mediator |
NotRequired[bool]
|
Whether to use mediator nodes for hyperedge-to-edge conversion.
Defaults to |
fast |
NotRequired[bool]
|
Whether to cache the graph structure after first computation.
Defaults to |
seed |
NotRequired[int]
|
Optional random seed for the random reduction of hyperedges to edges.
Defaults to |
Source code in hypertorch/node_classification/hypergcn_nc.py
HyperGCNClassifier
¶
Bases: NCClassifier
A LightningModule for HyperGCN-based NC classifier.
Uses HyperGCN to transform node features and hypergraph structure directly into
per-node class logits. During training, validation, and testing, loss and metrics
are computed on supervised target nodes selected by HData.target_node_mask.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
HyperGCN classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
Source code in hypertorch/node_classification/hypergcn_nc.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 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 | |
__init__(classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0005, metrics=None, metrics_log_kwargs=None)
¶
Initialize the HyperGCN-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
HyperGCNClassifierConfig
|
Configuration for the HyperGCN classifier. |
required |
loss_fn
|
Module | None
|
Optional 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. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/hypergcn_nc.py
forward(x, hyperedge_index)
¶
Predict node-class logits from node features and hypergraph structure.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> x.shape ... torch.Size([4, 3]) >>> hyperedge_index.shape ... torch.Size([2, 6])
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x, hyperedge_index) >>> logits.shape ... torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
hyperedge_index
|
Tensor
|
Hyperedge connectivity of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/hypergcn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/hypergcn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/hypergcn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/hypergcn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/hypergcn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/hypergcn_nc.py
MLPClassifier
¶
Bases: NCClassifier
A LightningModule for MLP-based NC classifier.
Uses an MLP classifier to map node features directly to per-node class logits.
During training, validation, and testing, loss and metrics are computed on the
supervised target nodes selected by HData.target_node_mask when present.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional encoder module inherited from |
classifier |
Module
|
MLP classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
lr |
float
|
Learning rate for the optimizer. Defaults to |
Source code in hypertorch/node_classification/mlp_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.001, metrics=None, metrics_log_kwargs=None)
¶
Initialize the MLP-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
MLPClassifierConfig
|
Configuration for the MLP classifier. |
required |
loss_fn
|
Module | None
|
Optional loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/mlp_nc.py
forward(x)
¶
Predict node-class logits from node features.
Examples:
Given 4 nodes with 3 features each and 2 output classes: >>> 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
The forward pass maps each node to one row of class logits: >>> logits = model.forward(x) >>> logits.shape torch.Size([4, 2])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature matrix of shape |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/mlp_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/mlp_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/mlp_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/mlp_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/mlp_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/mlp_nc.py
MLPClassifierConfig
¶
Bases: TypedDict
Configuration for the MLP classifier in MLPClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
in_channels |
int
|
Number of input features per node. |
out_channels |
int
|
Number of node classes. |
num_layers |
NotRequired[int]
|
Number of layers in the MLP classifier. |
hidden_channels |
NotRequired[int | None]
|
Optional number of hidden units per layer. If |
activation_fn |
NotRequired[ActivationFn | None]
|
Optional activation function class to use in the MLP classifier.
If |
activation_fn_kwargs |
NotRequired[dict | None]
|
Optional dictionary of keyword arguments to pass to the activation function constructor. |
normalization_fn |
NotRequired[NormalizationFn | None]
|
Optional normalization function class to use in the MLP classifier.
If |
normalization_fn_kwargs |
NotRequired[dict | None]
|
Optional dictionary of keyword arguments to pass to the normalization function constructor. |
bias |
NotRequired[bool]
|
Whether to include bias terms in the MLP layers. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate to apply after each MLP layer except the last one.
Defaults to |
Source code in hypertorch/node_classification/mlp_nc.py
Node2VecGCNClassifierConfig
¶
Bases: TypedDict
Configuration for the Node2VecGCN classifier in Node2VecGCNClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
NotRequired[Node2VecMode]
|
Whether to use precomputed node embeddings from |
num_features |
int
|
Dimension of the Node2Vec embeddings, which is also used by the GCN. |
node2vec_config |
Node2VecEncoderConfig
|
Shared Node2Vec configuration used in joint mode. It is ignored
in precomputed mode. So, it can be provided as an empty dictionary: |
gcn_config |
Node2VecGCNEncoderConfig
|
Configuration for the GCN classifier. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
Node2VecGCNClassifier
¶
Bases: NCClassifier
A LightningModule for Node2VecGCN-based NC classifier.
Supports two modes
precomputed: use node embeddings already stored inbatch.x.joint: train a Node2Vec encoder jointly with the GCN classifier.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional Node2Vec-GCN encoder inherited from |
classifier |
Module
|
GCN classifier inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
mode |
Node2VecMode
|
Whether to use precomputed or joint Node2Vec embeddings. |
embedding_dim |
int
|
Node embedding dimension consumed by GCN. |
node2vec_config |
Node2VecEncoderConfig
|
Node2Vec configuration. |
gcn_config |
Node2VecGCNEncoderConfig
|
GCN configuration. |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
Weight decay for the optimizer. Defaults to |
random_walk_batch_size |
int
|
Batch size used for Node2Vec walk loss in joint mode.
Defaults to |
node2vec_loss_weight |
float
|
Weight applied to Node2Vec walk loss in joint mode.
Defaults to |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
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 | |
__init__(classifier_config, loss_fn=None, lr=0.001, weight_decay=0.0, metrics=None, metrics_log_kwargs=None)
¶
Initialize the Node2VecGCN-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
classifier_config
|
Node2VecGCNClassifierConfig
|
Configuration for Node2Vec embeddings and GCN layers. |
required |
loss_fn
|
Module | None
|
Optional NC loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
Weight decay for the optimizer. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior of |
None
|
Source code in hypertorch/node_classification/node2vecgcn_nc.py
forward(x, hyperedge_index, global_node_ids=None)
¶
Predict node-class logits from Node2Vec embeddings refined by GCN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature or precomputed embedding matrix. |
required |
hyperedge_index
|
Tensor
|
Hyperedge incidence tensor. |
required |
global_node_ids
|
Tensor | None
|
Optional global node IDs for joint Node2Vec lookup.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the configured mode cannot supply node embeddings. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
In joint mode this combines NC loss with one stochastic Node2Vec walk loss batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/node2vecgcn_nc.py
Node2VecClassifierConfig
¶
Bases: TypedDict
Configuration for the Node2Vec classifier in Node2VecClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
out_channels |
int
|
Number of node classes. |
Source code in hypertorch/node_classification/node2vec_nc.py
Node2VecEncoderConfig
¶
Bases: TypedDict
Configuration for the Node2Vec encoder in Node2VecClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
mode |
NotRequired[Node2VecMode]
|
Whether to use precomputed node embeddings from |
num_features |
int
|
Dimension of the Node2Vec embeddings, which is also the input dimension of the classifier. |
node2vec_config |
Node2VecEncoderConfig
|
Shared Node2Vec configuration used in joint mode, or metadata for validating precomputed embeddings. |
Source code in hypertorch/node_classification/node2vec_nc.py
Node2VecClassifier
¶
Bases: NCClassifier
A LightningModule for Node2Vec-based NC classifier.
Supports two modes
precomputed: use node embeddings already stored inbatch.x.joint: train a Node2Vec encoder jointly with the node classifier.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
Optional Node2Vec encoder inherited from |
classifier |
Module
|
Classifier inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
mode |
Node2VecMode
|
Whether to use precomputed or joint Node2Vec embeddings. |
embedding_dim |
int
|
Node embedding dimension consumed by the classifier. |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
Weight decay for the optimizer. Defaults to |
random_walk_batch_size |
int
|
Batch size used for Node2Vec walk loss in joint mode.
Defaults to |
node2vec_loss_weight |
float
|
Weight applied to Node2Vec walk loss in joint mode.
Defaults to |
Source code in hypertorch/node_classification/node2vec_nc.py
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 | |
__init__(encoder_config, classifier_config, loss_fn=None, lr=0.001, weight_decay=0.0, metrics=None, metrics_log_kwargs=None)
¶
Initialize the Node2Vec-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
Node2VecEncoderConfig
|
Configuration for the Node2Vec encoder. |
required |
classifier_config
|
Node2VecClassifierConfig
|
Configuration for the classifier. |
required |
loss_fn
|
Module | None
|
Optional NC loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.001
|
weight_decay
|
float
|
Weight decay for the optimizer. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior of |
None
|
Source code in hypertorch/node_classification/node2vec_nc.py
forward(x, global_node_ids=None)
¶
Predict node-class logits from precomputed or jointly trained Node2Vec embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
Tensor
|
Node feature or precomputed embedding matrix. |
required |
global_node_ids
|
Tensor | None
|
Optional global node IDs for joint Node2Vec lookup.
Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the configured mode cannot supply node embeddings. |
Source code in hypertorch/node_classification/node2vec_nc.py
training_step(batch, batch_idx)
¶
Run a training step.
In joint mode this combines NC loss with one stochastic Node2Vec walk loss batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Training loss. |
Source code in hypertorch/node_classification/node2vec_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/node2vec_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/node2vec_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/node2vec_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/node2vec_nc.py
VilLainClassifierConfig
¶
Bases: TypedDict
Configuration for the classifier in VilLainClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
out_channels |
int
|
Number of node classes. |
Source code in hypertorch/node_classification/villain_nc.py
VilLainEncoderConfig
¶
Bases: TypedDict
Configuration for the VilLain encoder in VilLainClassifier.
Attributes:
| Name | Type | Description |
|---|---|---|
num_nodes |
int
|
Total number of trainable nodes. |
embedding_dim |
NotRequired[int]
|
Returned node embedding dimension. Defaults to |
labels_per_subspace |
NotRequired[int]
|
Number of virtual labels per subspace. Defaults to |
training_steps |
NotRequired[int]
|
Propagation steps used for VilLain loss. Defaults to |
generation_steps |
NotRequired[int]
|
Propagation steps averaged by |
tau |
NotRequired[float]
|
Gumbel-Softmax temperature. Defaults to |
eps |
NotRequired[float]
|
Numerical stability constant. Defaults to |
villain_loss_weight |
NotRequired[float]
|
Weight applied to VilLain self-supervision. Defaults to |
Source code in hypertorch/node_classification/villain_nc.py
VilLainClassifier
¶
Bases: NCClassifier
Feature-free VilLain-based NC classifier.
The module learns transductive node embeddings from the hypergraph structure with
VilLain and classifies the generated embeddings with an MLP.
Attributes:
| Name | Type | Description |
|---|---|---|
encoder |
Module | None
|
VilLain encoder module inherited from |
classifier |
Module
|
Classifier module inherited from |
loss_fn |
Module
|
Loss function inherited from |
metrics_log_kwargs |
dict[str, Any]
|
Metric logging keyword arguments inherited from |
train_metrics |
MetricCollection | None
|
Optional training metrics inherited from |
val_metrics |
MetricCollection | None
|
Optional validation metrics inherited from |
test_metrics |
MetricCollection | None
|
Optional test metrics inherited from |
embedding_dim |
int
|
VilLain node embedding dimension. |
lr |
float
|
Learning rate for the optimizer. Defaults to |
weight_decay |
float
|
L2 regularization. Defaults to |
villain_loss_weight |
float
|
Weight applied to VilLain self-supervision. Defaults to |
Source code in hypertorch/node_classification/villain_nc.py
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 | |
__init__(encoder_config, classifier_config, loss_fn=None, lr=0.01, weight_decay=0.0, metrics=None, metrics_log_kwargs=None)
¶
Initialize the VilLain-based NC classifier.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoder_config
|
VilLainEncoderConfig
|
Configuration for the VilLain encoder. |
required |
classifier_config
|
VilLainClassifierConfig
|
Configuration for the classifier. |
required |
loss_fn
|
Module | None
|
Optional NC loss function. Defaults to |
None
|
lr
|
float
|
Learning rate for the optimizer. Defaults to |
0.01
|
weight_decay
|
float
|
L2 regularization. Defaults to |
0.0
|
metrics
|
MetricCollection | None
|
Optional metric collection for evaluation. Defaults to |
None
|
metrics_log_kwargs
|
dict[str, Any] | None
|
Additional keyword arguments passed to metric log calls.
Useful for configuring distributed synchronization behavior
of |
None
|
Source code in hypertorch/node_classification/villain_nc.py
forward(hyperedge_index, global_node_ids=None, num_hyperedges=None)
¶
Predict node-class logits from VilLain-generated node embeddings.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
hyperedge_index
|
Tensor
|
Hyperedge incidence tensor. |
required |
global_node_ids
|
Tensor | None
|
Optional global node IDs for transductive embedding lookup.
Defaults to |
None
|
num_hyperedges
|
int | None
|
Optional explicit number of hyperedges. Defaults to |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Node-class logits of shape |
Source code in hypertorch/node_classification/villain_nc.py
training_step(batch, batch_idx)
¶
Run a training step with NC and VilLain self-supervised losses.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Training batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Combined training loss. |
Source code in hypertorch/node_classification/villain_nc.py
validation_step(batch, batch_idx)
¶
Run a validation step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Validation batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Validation loss. |
Source code in hypertorch/node_classification/villain_nc.py
test_step(batch, batch_idx)
¶
Run a test step.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Test batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Test loss. |
Source code in hypertorch/node_classification/villain_nc.py
predict_step(batch, batch_idx)
¶
Predict node-class logits for a batch.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Prediction batch. |
required |
batch_idx
|
int
|
Batch index, unused. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
logits |
Tensor
|
Predicted node-class logits. |
Source code in hypertorch/node_classification/villain_nc.py
configure_optimizers()
¶
Configure the optimizer.
Returns:
| Name | Type | Description |
|---|---|---|
optimizer |
Adam
|
Adam optimizer. |
__eval_step(batch, stage)
¶
Run shared evaluation logic for a stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
batch
|
HData
|
Input batch. |
required |
stage
|
Stage
|
Current evaluation stage. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
loss |
Tensor
|
Computed loss. |
Source code in hypertorch/node_classification/villain_nc.py
__to_villain_encoder()
¶
Return the configured VilLain encoder.
Returns:
| Name | Type | Description |
|---|---|---|
encoder |
VilLain
|
VilLain encoder instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the configured encoder is missing or has the wrong type. |
Source code in hypertorch/node_classification/villain_nc.py
Node2VecGCNNCConfig
¶
Bases: TypedDict
Configuration for the GCN model.
Attributes:
| Name | Type | Description |
|---|---|---|
out_channels |
int
|
Dimension of the output node embeddings from the GCN layers. |
hidden_channels |
NotRequired[int]
|
Dimension of the hidden node embeddings in the GCN layers. |
num_layers |
NotRequired[int]
|
Number of GCN layers. Must be at least 1. Defaults to |
drop_rate |
NotRequired[float]
|
Dropout rate applied after each GCN layer (except the last one).
Defaults to |
bias |
NotRequired[bool]
|
Whether to include a bias term in the GCN layers. Defaults to |
improved |
NotRequired[bool]
|
Whether to use the improved version of GCNConv. Defaults to |
add_self_loops |
NotRequired[bool]
|
Whether to add self-loops to the input graph. Defaults to |
normalize |
NotRequired[bool]
|
Whether to symmetrically normalize the adjacency matrix in GCNConv.
Defaults to |
cached |
NotRequired[bool]
|
Whether to cache the normalized adjacency matrix in GCNConv.
Only applicable if the graph structure does not change between epochs.
Defaults to |
graph_reduction_strategy |
NotRequired[GraphReductionStrategy]
|
Strategy for reducing the hyperedge graph.
Defaults to |
num_nodes |
NotRequired[int]
|
Total number of nodes in the hypergraph. This is useful when setting is transductive but train dataset may not contain all hyperedges where some nodes appear, to ensure consistent encoding across splits. |
activation_fn |
NotRequired[ActivationFn]
|
Activation function to use after each hidden layer.
Defaults to |
activation_fn_kwargs |
NotRequired[dict]
|
Keyword arguments for the activation function. Defaults to empty dict. |
Source code in hypertorch/models/node2vec_common.py
Node2VecNCConfig
¶
Bases: TypedDict
Configuration for the Node2Vec encoder.
Attributes:
| Name | Type | Description |
|---|---|---|
context_size |
NotRequired[int]
|
Skip-gram context size for Node2Vec.
For example, if |
walk_length |
NotRequired[int]
|
Length of each random walk. |
num_walks_per_node |
NotRequired[int]
|
Number of walks sampled per node. |
p |
NotRequired[float]
|
Node2Vec return parameter. Controls the probability of stepping back to the node visited
in the previous step. Lower values of |
q |
NotRequired[float]
|
Node2Vec in-out parameter. Controls whether walks stay near the source node or explore
further outward. Lower values of |
num_negative_samples |
NotRequired[int]
|
Number of negative samples per positive walk context.
If set to |
num_nodes |
NotRequired[int]
|
Number of nodes in the stable node space. Defaults to the number of nodes
in the |
train_hyperedge_index |
NotRequired[Tensor]
|
Training hypereddge index used to build the Node2Vec walk graph.
Required in |
graph_reduction_strategy |
NotRequired[GraphReductionStrategy]
|
Strategy for reducing the hyperedge graph.
Defaults to |
random_walk_batch_size |
NotRequired[int]
|
Batch size used by the walk sampler in joint mode. |
node2vec_loss_weight |
NotRequired[float]
|
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 task loss.
Defaults to |
sparse |
NotRequired[bool]
|
Whether to use sparse gradients in the Node2Vec encoder. Defaults to |