Download annotations/annotation_15/GraphMETRO/graphmetro/train/augment.py from mcy98/RECODE-H: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_15/GraphMETRO/graphmetro/train/augment.py
- Command line
-
hf download hf://datasets/mcy98/RECODE-H/annotations/annotation_15/GraphMETRO/graphmetro/train/augment.py
-
curl -L -o augment.py https://huggingface.co/datasets/mcy98/RECODE-H/resolve/main/annotations/annotation_15/GraphMETRO/graphmetro/train/augment.py
1.03 kB
| import torch | |
| import torch.nn.functional as F | |
| from torch_geometric.utils import dropout_adj | |
| def augment(data, augment_type, p): | |
| if augment_type == 'none': | |
| return data.x_dict, data.edge_index_dict | |
| if augment_type == "dropedge": | |
| edge_index_dict = {} | |
| for edge_type, edge_index in data.edge_index_dict.items(): | |
| edge_index_dict[edge_type], _ = dropout_adj(edge_index, p=p) | |
| x_dict = data.x_dict | |
| else: | |
| x_dict = {} | |
| if augment_type == 'shuffle': | |
| for node_type, x in data.x_dict.items(): | |
| x_dict[node_type] = x[torch.randperm(x.size(0)), :] | |
| if augment_type == "dropfeat": | |
| for node_type, x in data.x_dict.items(): | |
| x_dict[node_type] = F.dropout(x, p=p) | |
| if augment_type == 'noisyfeat': | |
| for node_type, x in data.x_dict.items(): | |
| x_dict[node_type] = x + torch.randn(x.size()).to(x.device) * p | |
| edge_index_dict = data.edge_index_dict | |
| return x_dict, edge_index_dict |