Huhujingjing
commited on
Commit
•
64fa2ae
1
Parent(s):
2444fad
Upload model
Browse files- modeling_gcn.py +41 -35
modeling_gcn.py
CHANGED
@@ -1,47 +1,24 @@
|
|
1 |
-
|
|
|
2 |
import torch.nn as nn
|
3 |
import torch.nn.functional as F
|
4 |
-
from torch_scatter import scatter
|
5 |
-
from transformers import PreTrainedModel
|
6 |
-
from gcn_model.configuration_gcn import GCNConfig
|
7 |
-
import torch
|
8 |
-
from rdkit import Chem
|
9 |
-
from rdkit.Chem import AllChem
|
10 |
-
import torch
|
11 |
-
from torch_geometric.data import Data
|
12 |
-
import os
|
13 |
-
from transformers import PretrainedConfig
|
14 |
-
from typing import List
|
15 |
-
from torch_geometric.loader import DataLoader
|
16 |
from tqdm import tqdm
|
17 |
import pandas as pd
|
18 |
-
from
|
19 |
-
class GCNConfig(PretrainedConfig):
|
20 |
-
model_type = "gcn"
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
input_feature: int=64,
|
25 |
-
emb_input: int=20,
|
26 |
-
hidden_size: int=64,
|
27 |
-
n_layers: int=6,
|
28 |
-
num_classes: int=1,
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
):
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
self.num_classes = num_classes # the number of output classes
|
40 |
|
41 |
-
self.smiles = smiles # process smiles
|
42 |
-
self.processor_class = processor_class
|
43 |
|
44 |
-
super().__init__(**kwargs)
|
45 |
class SmilesDataset(torch.utils.data.Dataset):
|
46 |
def __init__(self, smiles):
|
47 |
self.smiles_list = smiles
|
@@ -176,6 +153,35 @@ class GCNNet(torch.nn.Module):
|
|
176 |
|
177 |
return x.squeeze(-1)
|
178 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
179 |
class GCNModel(PreTrainedModel):
|
180 |
config_class = GCNConfig
|
181 |
|
|
|
1 |
+
import os
|
2 |
+
import torch
|
3 |
import torch.nn as nn
|
4 |
import torch.nn.functional as F
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
from tqdm import tqdm
|
6 |
import pandas as pd
|
7 |
+
from typing import List
|
|
|
|
|
8 |
|
9 |
+
from rdkit import Chem
|
10 |
+
from rdkit.Chem import AllChem
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
from transformers import PretrainedConfig
|
13 |
+
from transformers import PreTrainedModel
|
14 |
+
from transformers import AutoModel
|
|
|
15 |
|
16 |
+
from torch_geometric.nn import GCNConv
|
17 |
+
from torch_geometric.data import Data
|
18 |
+
from torch_geometric.loader import DataLoader
|
19 |
+
from torch_scatter import scatter
|
|
|
20 |
|
|
|
|
|
21 |
|
|
|
22 |
class SmilesDataset(torch.utils.data.Dataset):
|
23 |
def __init__(self, smiles):
|
24 |
self.smiles_list = smiles
|
|
|
153 |
|
154 |
return x.squeeze(-1)
|
155 |
|
156 |
+
|
157 |
+
class GCNConfig(PretrainedConfig):
|
158 |
+
model_type = "gcn"
|
159 |
+
|
160 |
+
def __init__(
|
161 |
+
self,
|
162 |
+
input_feature: int=64,
|
163 |
+
emb_input: int=20,
|
164 |
+
hidden_size: int=64,
|
165 |
+
n_layers: int=6,
|
166 |
+
num_classes: int=1,
|
167 |
+
|
168 |
+
smiles: List[str] = None,
|
169 |
+
processor_class: str = "SmilesProcessor",
|
170 |
+
**kwargs,
|
171 |
+
):
|
172 |
+
|
173 |
+
self.input_feature = input_feature # the dimension of input feature
|
174 |
+
self.emb_input = emb_input # the embedding dimension of input feature
|
175 |
+
self.hidden_size = hidden_size # the hidden size of GCN
|
176 |
+
self.n_layers = n_layers # the number of GCN layers
|
177 |
+
self.num_classes = num_classes # the number of output classes
|
178 |
+
|
179 |
+
self.smiles = smiles # process smiles
|
180 |
+
self.processor_class = processor_class
|
181 |
+
|
182 |
+
super().__init__(**kwargs)
|
183 |
+
|
184 |
+
|
185 |
class GCNModel(PreTrainedModel):
|
186 |
config_class = GCNConfig
|
187 |
|