()
| 121 | |
| 122 | |
| 123 | def main(): |
| 124 | device = torch.device('cuda') |
| 125 | path = osp.join(osp.expanduser('~'), 'datasets', 'WikiCS') |
| 126 | dataset = WikiCS(path, transform=T.NormalizeFeatures()) |
| 127 | data = dataset[0].to(device) |
| 128 | |
| 129 | aug1 = A.Compose([A.EdgeRemoving(pe=0.5), A.FeatureMasking(pf=0.1)]) |
| 130 | aug2 = A.Compose([A.EdgeRemoving(pe=0.5), A.FeatureMasking(pf=0.1)]) |
| 131 | |
| 132 | gconv = GConv(input_dim=dataset.num_features, hidden_dim=256, num_layers=2).to(device) |
| 133 | encoder_model = Encoder(encoder=gconv, augmentor=(aug1, aug2), hidden_dim=256).to(device) |
| 134 | contrast_model = BootstrapContrast(loss=L.BootstrapLatent(), mode='L2L').to(device) |
| 135 | |
| 136 | optimizer = Adam(encoder_model.parameters(), lr=0.01) |
| 137 | |
| 138 | with tqdm(total=100, desc='(T)') as pbar: |
| 139 | for epoch in range(1, 101): |
| 140 | loss = train(encoder_model, contrast_model, data, optimizer) |
| 141 | pbar.set_postfix({'loss': loss}) |
| 142 | pbar.update() |
| 143 | |
| 144 | test_result = test(encoder_model, data) |
| 145 | print(f'(E): Best test F1Mi={test_result["micro_f1"]:.4f}, F1Ma={test_result["macro_f1"]:.4f}') |
| 146 | |
| 147 | |
| 148 | if __name__ == '__main__': |
no test coverage detected