dig.fairgraph.method¶
Graphair¶
A fair graph representation method for graph datasets under dig.fairgraph.dataset.fairgraph_dataset
implemented from the paper
LEARNING FAIR GRAPH REPRESENTATIONS VIA AUTOMATED DATA AUGMENTATIONS.
This class implements the Graphair model |
- class graphair(aug_model, f_encoder, sens_model, classifier_model, lr=0.0001, weight_decay=1e-05, alpha=20, beta=0.9, gamma=0.7, lam=1, dataset='POKEC', num_hidden=64, num_proj_hidden=64)[source]¶
This class implements the Graphair model
- Parameters
aug_model (
torch.nn.Module
) – The augmentation model g described in the paper used for automated graph augmentationsf_encoder (
torch.nn.Module
) –The represnetation encoder f described in the paper used for contrastive learning
sens_model (
torch.nn.Module
) –The adversary model k described in the paper used for adversarial learning
classifier_model (
torch.nn.Module
) – The classifier used to predict the sensitive label of nodes on the augmented graph data.lr (float,optional) – Learning rate for aug_model, f_encoder and sens_model. Defaults to 1e-4
weight_decay (float,optional) – Weight decay for regularization. Defaults to 1e-5
alpha (float,optional) –
The hyperparameter alpha used in the paper to scale adversarial loss component. Defaults to 20.0
beta (float,optional) –
The hyperparameter beta used in the paper to scale contrastive loss component. Defaults to 0.9
gamma (float,optional) –
The hyperparameter gamma used in the paper to scale reconstruction loss component. Defaults to 0.7
lam (float,optional) –
The hyperparameter lambda used in the paper to compute reconstruction loss component. Defaults to 1.0
dataset (str,optional) – The name of the dataset being used. Used only for the model’s output path. Defaults to ‘POKEC’
num_hidden (int,optional) – The input dimension for the MLP networks used in the model. Defaults to 64
num_proj_hidden (int,optional) – The output dimension for the MLP networks used in the model. Defaults to 64
Runner¶
This class instantiates Graphair model and implements method to train and evaluate. |
- class run[source]¶
This class instantiates Graphair model and implements method to train and evaluate.
- run(device, dataset, model='Graphair', epochs=10000, test_epochs=1000, lr=0.0001, weight_decay=1e-05)[source]¶
This method runs training and evaluation for a fairgraph model on the given dataset. Check
examples.fairgraph.Graphair.run_graphair_nba.py
for examples on how to run the Graphair model.- Parameters
device (
torch.device
) – Device for computation.model (str, optional) – Defaults to Graphair. (Note that at this moment, only Graphair is supported)
dataset (
object
) – The dataset to train on. Should be one ofdig.fairgraph.dataset.fairgraph_dataset.POKEC
ordig.fairgraph.dataset.fairgraph_dataset.NBA
.epochs (int, optional) – Number of epochs to train on. Defaults to 10_000.
test_epochs (int,optional) – Number of epochs to train the classifier while running evaluation. Defaults to 1_000.
lr (float,optional) – Learning rate. Defaults to 1e-4.
weight_decay (float, optional) – Weight decay factor for regularization. Defaults to 1e-5.
- Raise
Exception
when model is not Graphair. At this moment, only Graphair is supported.