MaskLabel
¶
Bases: Module
The label embedding and masking layer from the "Masked Label Prediction: Unified Message Passing Model for Semi-Supervised Classification" paper.
The labels y of a subset of the nodes, given by mask, are embedded
and merged into the node features.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
num_classes
|
int
|
The number of classes. |
required |
out_features_dim
|
int
|
Size of the label embeddings. With |
required |
method
|
Literal['add', 'concat']
|
|
'add'
|
Example:
import mlx.core as mx
from mlx_graphs.nn import MaskLabel
mask_label = MaskLabel(num_classes=3, out_features_dim=16)
x = mx.random.normal((5, 16))
y = mx.array([0, 1, 2, 1, 0])
train_mask = mx.array([True, True, False, True, False])
# hide a random half of the training labels at each epoch
label_mask = MaskLabel.ratio_mask(train_mask, ratio=0.5)
>>> mask_label(x, y, label_mask).shape
(5, 16)
References
[1] Shi et al. Masked Label Prediction: Unified Message Passing Model for Semi-Supervised Classification
Methods:
| Name | Description |
|---|---|
__call__ |
Merges the label embeddings of the masked nodes into |
ratio_mask |
Randomly keeps a ratio of the |
Source code in mlx_graphs/nn/models/mask_label.py
__call__
¶
Merges the label embeddings of the masked nodes into x.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
array
|
Node features, shape |
required |
y
|
array
|
Integer labels of all the nodes, shape |
required |
mask
|
array
|
Boolean mask or index array of the nodes whose label is used |
required |
Returns:
| Type | Description |
|---|---|
array
|
Node features of shape |
array
|
|
Source code in mlx_graphs/nn/models/mask_label.py
ratio_mask
staticmethod
¶
ratio_mask(mask: array, ratio: float) -> array
Randomly keeps a ratio of the True entries of a boolean mask.
Each True entry stays True with probability ratio. Does not
modify mask.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mask
|
array
|
The boolean mask to re-mask |
required |
ratio
|
float
|
The probability of keeping each entry |
required |
Source code in mlx_graphs/nn/models/mask_label.py
from mlx_graphs.nn import MaskLabel · mlx_graphs/nn/models/mask_label.py