Instructions to use SaeedLab/TITAN-BBB with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use SaeedLab/TITAN-BBB with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("SaeedLab/TITAN-BBB", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Delete classification
Browse files- classification/__init__.py +0 -2
- classification/__pycache__/__init__.cpython-310.pyc +0 -0
- classification/__pycache__/config_bbb.cpython-310.pyc +0 -0
- classification/__pycache__/modeling_bbb.cpython-310.pyc +0 -0
- classification/config.json +0 -26
- classification/config_bbb.py +0 -28
- classification/config_bbb_model.py +0 -28
- classification/configuration_bbb_model.py +0 -28
- classification/modeling_bbb.py +0 -150
- classification/modeling_bbb_model.py +0 -150
- classification/pytorch_model.bin +0 -3
classification/__init__.py
DELETED
|
@@ -1,2 +0,0 @@
|
|
| 1 |
-
from .configuration_bbb_model import BBBConfig
|
| 2 |
-
from .modeling_bbb_model import BBBModel, BBBModelForSequenceClassification
|
|
|
|
|
|
|
|
|
classification/__pycache__/__init__.cpython-310.pyc
DELETED
|
Binary file (481 Bytes)
|
|
|
classification/__pycache__/config_bbb.cpython-310.pyc
DELETED
|
Binary file (1.03 kB)
|
|
|
classification/__pycache__/modeling_bbb.cpython-310.pyc
DELETED
|
Binary file (3.78 kB)
|
|
|
classification/config.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
{
|
| 2 |
-
"architectures": [
|
| 3 |
-
"BBBModelForSequenceClassification"
|
| 4 |
-
],
|
| 5 |
-
"dropout": 0.1,
|
| 6 |
-
"gnn_hidden": 512,
|
| 7 |
-
"gnn_layers": 4,
|
| 8 |
-
"id2label": {
|
| 9 |
-
"0": "LABEL_0"
|
| 10 |
-
},
|
| 11 |
-
"input_dim": 768,
|
| 12 |
-
"label2id": {
|
| 13 |
-
"LABEL_0": 0
|
| 14 |
-
},
|
| 15 |
-
"model_type": "bbb-model",
|
| 16 |
-
"neurons_fc": [
|
| 17 |
-
256
|
| 18 |
-
],
|
| 19 |
-
"num_features": 2265,
|
| 20 |
-
"num_heads": 8,
|
| 21 |
-
"problem_type": "single_label_classification",
|
| 22 |
-
"proj_dim": 1024,
|
| 23 |
-
"task": "classification",
|
| 24 |
-
"torch_dtype": "float32",
|
| 25 |
-
"transformers_version": "4.25.1"
|
| 26 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/config_bbb.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
from transformers import PretrainedConfig
|
| 2 |
-
|
| 3 |
-
class BBBConfig(PretrainedConfig):
|
| 4 |
-
model_type = "bbb-model"
|
| 5 |
-
|
| 6 |
-
def __init__(
|
| 7 |
-
self,
|
| 8 |
-
gnn_layers: int = 4,
|
| 9 |
-
gnn_hidden: int = 512,
|
| 10 |
-
dropout: float = 0.1,
|
| 11 |
-
num_heads: int = 8,
|
| 12 |
-
num_features: int = 2265,
|
| 13 |
-
proj_dim: int = 1024,
|
| 14 |
-
neurons_fc: list[int] = [256],
|
| 15 |
-
input_dim: int = 768,
|
| 16 |
-
task: str = 'classification',
|
| 17 |
-
**kwargs):
|
| 18 |
-
|
| 19 |
-
self.gnn_layers = gnn_layers
|
| 20 |
-
self.gnn_hidden = gnn_hidden
|
| 21 |
-
self.dropout = dropout
|
| 22 |
-
self.num_heads = num_heads
|
| 23 |
-
self.num_features = num_features
|
| 24 |
-
self.proj_dim = proj_dim
|
| 25 |
-
self.neurons_fc = neurons_fc
|
| 26 |
-
self.input_dim = input_dim
|
| 27 |
-
self.task = task
|
| 28 |
-
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/config_bbb_model.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
from transformers import PretrainedConfig
|
| 2 |
-
|
| 3 |
-
class BBBConfig(PretrainedConfig):
|
| 4 |
-
model_type = "bbb-model"
|
| 5 |
-
|
| 6 |
-
def __init__(
|
| 7 |
-
self,
|
| 8 |
-
gnn_layers: int = 4,
|
| 9 |
-
gnn_hidden: int = 512,
|
| 10 |
-
dropout: float = 0.1,
|
| 11 |
-
num_heads: int = 8,
|
| 12 |
-
num_features: int = 2265,
|
| 13 |
-
proj_dim: int = 1024,
|
| 14 |
-
neurons_fc: list[int] = [256],
|
| 15 |
-
input_dim: int = 768,
|
| 16 |
-
task: str = 'classification',
|
| 17 |
-
**kwargs):
|
| 18 |
-
|
| 19 |
-
self.gnn_layers = gnn_layers
|
| 20 |
-
self.gnn_hidden = gnn_hidden
|
| 21 |
-
self.dropout = dropout
|
| 22 |
-
self.num_heads = num_heads
|
| 23 |
-
self.num_features = num_features
|
| 24 |
-
self.proj_dim = proj_dim
|
| 25 |
-
self.neurons_fc = neurons_fc
|
| 26 |
-
self.input_dim = input_dim
|
| 27 |
-
self.task = task
|
| 28 |
-
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/configuration_bbb_model.py
DELETED
|
@@ -1,28 +0,0 @@
|
|
| 1 |
-
from transformers import PretrainedConfig
|
| 2 |
-
|
| 3 |
-
class BBBConfig(PretrainedConfig):
|
| 4 |
-
model_type = "bbb-model"
|
| 5 |
-
|
| 6 |
-
def __init__(
|
| 7 |
-
self,
|
| 8 |
-
gnn_layers: int = 4,
|
| 9 |
-
gnn_hidden: int = 512,
|
| 10 |
-
dropout: float = 0.1,
|
| 11 |
-
num_heads: int = 8,
|
| 12 |
-
num_features: int = 2265,
|
| 13 |
-
proj_dim: int = 1024,
|
| 14 |
-
neurons_fc: list[int] = [256],
|
| 15 |
-
input_dim: int = 768,
|
| 16 |
-
task: str = 'classification',
|
| 17 |
-
**kwargs):
|
| 18 |
-
|
| 19 |
-
self.gnn_layers = gnn_layers
|
| 20 |
-
self.gnn_hidden = gnn_hidden
|
| 21 |
-
self.dropout = dropout
|
| 22 |
-
self.num_heads = num_heads
|
| 23 |
-
self.num_features = num_features
|
| 24 |
-
self.proj_dim = proj_dim
|
| 25 |
-
self.neurons_fc = neurons_fc
|
| 26 |
-
self.input_dim = input_dim
|
| 27 |
-
self.task = task
|
| 28 |
-
super().__init__(**kwargs)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/modeling_bbb.py
DELETED
|
@@ -1,150 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
import torch.nn.functional as F
|
| 4 |
-
from torch_geometric.nn import GATConv
|
| 5 |
-
|
| 6 |
-
from transformers import PreTrainedModel
|
| 7 |
-
from transformers.modeling_outputs import BaseModelOutputWithPooling, SequenceClassifierOutput
|
| 8 |
-
|
| 9 |
-
from .config_bbb import BBBConfig
|
| 10 |
-
|
| 11 |
-
class BBBModel(PreTrainedModel):
|
| 12 |
-
config_class = BBBConfig
|
| 13 |
-
|
| 14 |
-
def __init__(self, config: BBBConfig):
|
| 15 |
-
super().__init__(config)
|
| 16 |
-
|
| 17 |
-
self.config = config
|
| 18 |
-
|
| 19 |
-
self.activation = nn.LeakyReLU()
|
| 20 |
-
|
| 21 |
-
self.gats = nn.ModuleList()
|
| 22 |
-
self.bns = nn.ModuleList()
|
| 23 |
-
|
| 24 |
-
for i in range(config.gnn_layers):
|
| 25 |
-
if i == 0:
|
| 26 |
-
self.gats.append(GATConv(config.input_dim,
|
| 27 |
-
config.gnn_hidden,
|
| 28 |
-
heads=config.num_heads,
|
| 29 |
-
concat=True,
|
| 30 |
-
dropout=config.dropout))
|
| 31 |
-
else:
|
| 32 |
-
self.gats.append(GATConv(config.gnn_hidden * config.num_heads,
|
| 33 |
-
config.gnn_hidden,
|
| 34 |
-
heads=config.num_heads,
|
| 35 |
-
concat=True,
|
| 36 |
-
dropout=config.dropout))
|
| 37 |
-
self.bns.append(nn.BatchNorm1d(config.gnn_hidden * config.num_heads))
|
| 38 |
-
|
| 39 |
-
self.proj_gnn = nn.Sequential(
|
| 40 |
-
nn.Linear(config.gnn_hidden * config.num_heads, config.proj_dim),
|
| 41 |
-
nn.LeakyReLU(),
|
| 42 |
-
nn.Dropout(config.dropout),
|
| 43 |
-
nn.BatchNorm1d(config.proj_dim)
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
self.proj_feat = nn.Sequential(
|
| 47 |
-
nn.Linear(config.num_features, config.proj_dim),
|
| 48 |
-
nn.LeakyReLU(),
|
| 49 |
-
nn.Dropout(config.dropout),
|
| 50 |
-
nn.BatchNorm1d(config.proj_dim)
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
def forward(self,
|
| 54 |
-
x: torch.Tensor = None,
|
| 55 |
-
edge_index: torch.Tensor = None,
|
| 56 |
-
batch: torch.Tensor = None,
|
| 57 |
-
features: torch.Tensor = None,
|
| 58 |
-
# standard input from HF
|
| 59 |
-
output_attentions = None,
|
| 60 |
-
output_hidden_states=None,
|
| 61 |
-
return_dict=None):
|
| 62 |
-
|
| 63 |
-
if x is None or edge_index is None or batch is None or features is None:
|
| 64 |
-
raise ValueError('You have to specify x, edge_index, batch, and features')
|
| 65 |
-
|
| 66 |
-
for gat, bn in zip(self.gats, self.bns):
|
| 67 |
-
x = gat(x, edge_index)
|
| 68 |
-
x = bn(x)
|
| 69 |
-
x = self.activation(x)
|
| 70 |
-
|
| 71 |
-
super_nodes = []
|
| 72 |
-
for i in range(batch.max().item() + 1):
|
| 73 |
-
mask = (batch == i)
|
| 74 |
-
node_idx = mask.nonzero(as_tuple=True)[0]
|
| 75 |
-
super_node_idx = node_idx[-1]
|
| 76 |
-
super_nodes.append(x[super_node_idx])
|
| 77 |
-
|
| 78 |
-
x_super_nodes = torch.stack(super_nodes, dim=0)
|
| 79 |
-
|
| 80 |
-
gnn_proj = self.proj_gnn(x_super_nodes)
|
| 81 |
-
feat_proj = self.proj_feat(features)
|
| 82 |
-
|
| 83 |
-
combined = torch.cat([gnn_proj, feat_proj], dim=1)
|
| 84 |
-
|
| 85 |
-
return BaseModelOutputWithPooling(
|
| 86 |
-
last_hidden_state=x_super_nodes,
|
| 87 |
-
pooler_output=combined,
|
| 88 |
-
hidden_states=None,
|
| 89 |
-
attentions=None
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
class BBBModelForSequenceClassification(PreTrainedModel):
|
| 93 |
-
config_class = BBBConfig
|
| 94 |
-
|
| 95 |
-
def __init__(self, config: BBBConfig):
|
| 96 |
-
super().__init__(config)
|
| 97 |
-
|
| 98 |
-
self.config = config
|
| 99 |
-
|
| 100 |
-
self.base_model = BBBModel(config)
|
| 101 |
-
|
| 102 |
-
layers = []
|
| 103 |
-
input_dim = config.proj_dim * 2
|
| 104 |
-
for output_dim in config.neurons_fc:
|
| 105 |
-
layers.append(nn.Linear(input_dim, output_dim))
|
| 106 |
-
layers.append(nn.LeakyReLU())
|
| 107 |
-
layers.append(nn.Dropout(config.dropout))
|
| 108 |
-
layers.append(nn.BatchNorm1d(output_dim))
|
| 109 |
-
input_dim = output_dim
|
| 110 |
-
|
| 111 |
-
layers.append(nn.Linear(input_dim, 1))
|
| 112 |
-
self.fc = nn.Sequential(*layers)
|
| 113 |
-
|
| 114 |
-
def forward(self,
|
| 115 |
-
x: torch.Tensor = None,
|
| 116 |
-
edge_index: torch.Tensor = None,
|
| 117 |
-
batch: torch.Tensor = None,
|
| 118 |
-
features: torch.Tensor = None,
|
| 119 |
-
labels: torch.Tensor = None,
|
| 120 |
-
# standard input from HF
|
| 121 |
-
output_attentions = None,
|
| 122 |
-
output_hidden_states=None,
|
| 123 |
-
return_dict=None):
|
| 124 |
-
|
| 125 |
-
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 126 |
-
|
| 127 |
-
outputs = self.base_model(x=x,
|
| 128 |
-
edge_index=edge_index,
|
| 129 |
-
batch=batch,
|
| 130 |
-
features=features,
|
| 131 |
-
return_dict=return_dict)
|
| 132 |
-
|
| 133 |
-
combined_features = outputs.pooler_output
|
| 134 |
-
logits = self.fc(combined_features)
|
| 135 |
-
|
| 136 |
-
loss = None
|
| 137 |
-
if labels is not None:
|
| 138 |
-
if self.config.task == "regression":
|
| 139 |
-
loss_fct = nn.MSELoss()
|
| 140 |
-
loss = loss_fct(logits.squeeze(-1), labels.squeeze(-1))
|
| 141 |
-
elif self.config.task == "classification":
|
| 142 |
-
loss_fct = nn.BCEWithLogitsLoss()
|
| 143 |
-
loss = loss_fct(logits, labels.float().unsqueeze(-1))
|
| 144 |
-
|
| 145 |
-
return SequenceClassifierOutput(
|
| 146 |
-
loss=loss,
|
| 147 |
-
logits=logits,
|
| 148 |
-
hidden_states=outputs.hidden_states,
|
| 149 |
-
attentions=outputs.attentions
|
| 150 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/modeling_bbb_model.py
DELETED
|
@@ -1,150 +0,0 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import torch.nn as nn
|
| 3 |
-
import torch.nn.functional as F
|
| 4 |
-
from torch_geometric.nn import GATConv
|
| 5 |
-
|
| 6 |
-
from transformers import PreTrainedModel
|
| 7 |
-
from transformers.modeling_outputs import BaseModelOutputWithPooling, SequenceClassifierOutput
|
| 8 |
-
|
| 9 |
-
from .configuration_bbb_model import BBBConfig
|
| 10 |
-
|
| 11 |
-
class BBBModel(PreTrainedModel):
|
| 12 |
-
config_class = BBBConfig
|
| 13 |
-
|
| 14 |
-
def __init__(self, config: BBBConfig):
|
| 15 |
-
super().__init__(config)
|
| 16 |
-
|
| 17 |
-
self.config = config
|
| 18 |
-
|
| 19 |
-
self.activation = nn.LeakyReLU()
|
| 20 |
-
|
| 21 |
-
self.gats = nn.ModuleList()
|
| 22 |
-
self.bns = nn.ModuleList()
|
| 23 |
-
|
| 24 |
-
for i in range(config.gnn_layers):
|
| 25 |
-
if i == 0:
|
| 26 |
-
self.gats.append(GATConv(config.input_dim,
|
| 27 |
-
config.gnn_hidden,
|
| 28 |
-
heads=config.num_heads,
|
| 29 |
-
concat=True,
|
| 30 |
-
dropout=config.dropout))
|
| 31 |
-
else:
|
| 32 |
-
self.gats.append(GATConv(config.gnn_hidden * config.num_heads,
|
| 33 |
-
config.gnn_hidden,
|
| 34 |
-
heads=config.num_heads,
|
| 35 |
-
concat=True,
|
| 36 |
-
dropout=config.dropout))
|
| 37 |
-
self.bns.append(nn.BatchNorm1d(config.gnn_hidden * config.num_heads))
|
| 38 |
-
|
| 39 |
-
self.proj_gnn = nn.Sequential(
|
| 40 |
-
nn.Linear(config.gnn_hidden * config.num_heads, config.proj_dim),
|
| 41 |
-
nn.LeakyReLU(),
|
| 42 |
-
nn.Dropout(config.dropout),
|
| 43 |
-
nn.BatchNorm1d(config.proj_dim)
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
self.proj_feat = nn.Sequential(
|
| 47 |
-
nn.Linear(config.num_features, config.proj_dim),
|
| 48 |
-
nn.LeakyReLU(),
|
| 49 |
-
nn.Dropout(config.dropout),
|
| 50 |
-
nn.BatchNorm1d(config.proj_dim)
|
| 51 |
-
)
|
| 52 |
-
|
| 53 |
-
def forward(self,
|
| 54 |
-
x: torch.Tensor = None,
|
| 55 |
-
edge_index: torch.Tensor = None,
|
| 56 |
-
batch: torch.Tensor = None,
|
| 57 |
-
features: torch.Tensor = None,
|
| 58 |
-
# standard input from HF
|
| 59 |
-
output_attentions = None,
|
| 60 |
-
output_hidden_states=None,
|
| 61 |
-
return_dict=None):
|
| 62 |
-
|
| 63 |
-
if x is None or edge_index is None or batch is None or features is None:
|
| 64 |
-
raise ValueError('You have to specify x, edge_index, batch, and features')
|
| 65 |
-
|
| 66 |
-
for gat, bn in zip(self.gats, self.bns):
|
| 67 |
-
x = gat(x, edge_index)
|
| 68 |
-
x = bn(x)
|
| 69 |
-
x = self.activation(x)
|
| 70 |
-
|
| 71 |
-
super_nodes = []
|
| 72 |
-
for i in range(batch.max().item() + 1):
|
| 73 |
-
mask = (batch == i)
|
| 74 |
-
node_idx = mask.nonzero(as_tuple=True)[0]
|
| 75 |
-
super_node_idx = node_idx[-1]
|
| 76 |
-
super_nodes.append(x[super_node_idx])
|
| 77 |
-
|
| 78 |
-
x_super_nodes = torch.stack(super_nodes, dim=0)
|
| 79 |
-
|
| 80 |
-
gnn_proj = self.proj_gnn(x_super_nodes)
|
| 81 |
-
feat_proj = self.proj_feat(features)
|
| 82 |
-
|
| 83 |
-
combined = torch.cat([gnn_proj, feat_proj], dim=1)
|
| 84 |
-
|
| 85 |
-
return BaseModelOutputWithPooling(
|
| 86 |
-
last_hidden_state=x_super_nodes,
|
| 87 |
-
pooler_output=combined,
|
| 88 |
-
hidden_states=None,
|
| 89 |
-
attentions=None
|
| 90 |
-
)
|
| 91 |
-
|
| 92 |
-
class BBBModelForSequenceClassification(PreTrainedModel):
|
| 93 |
-
config_class = BBBConfig
|
| 94 |
-
|
| 95 |
-
def __init__(self, config: BBBConfig):
|
| 96 |
-
super().__init__(config)
|
| 97 |
-
|
| 98 |
-
self.config = config
|
| 99 |
-
|
| 100 |
-
self.base_model = BBBModel(config)
|
| 101 |
-
|
| 102 |
-
layers = []
|
| 103 |
-
input_dim = config.proj_dim * 2
|
| 104 |
-
for output_dim in config.neurons_fc:
|
| 105 |
-
layers.append(nn.Linear(input_dim, output_dim))
|
| 106 |
-
layers.append(nn.LeakyReLU())
|
| 107 |
-
layers.append(nn.Dropout(config.dropout))
|
| 108 |
-
layers.append(nn.BatchNorm1d(output_dim))
|
| 109 |
-
input_dim = output_dim
|
| 110 |
-
|
| 111 |
-
layers.append(nn.Linear(input_dim, 1))
|
| 112 |
-
self.fc = nn.Sequential(*layers)
|
| 113 |
-
|
| 114 |
-
def forward(self,
|
| 115 |
-
x: torch.Tensor = None,
|
| 116 |
-
edge_index: torch.Tensor = None,
|
| 117 |
-
batch: torch.Tensor = None,
|
| 118 |
-
features: torch.Tensor = None,
|
| 119 |
-
labels: torch.Tensor = None,
|
| 120 |
-
# standard input from HF
|
| 121 |
-
output_attentions = None,
|
| 122 |
-
output_hidden_states=None,
|
| 123 |
-
return_dict=None):
|
| 124 |
-
|
| 125 |
-
return_dict = return_dict if return_dict is not None else self.config.use_return_dict
|
| 126 |
-
|
| 127 |
-
outputs = self.base_model(x=x,
|
| 128 |
-
edge_index=edge_index,
|
| 129 |
-
batch=batch,
|
| 130 |
-
features=features,
|
| 131 |
-
return_dict=return_dict)
|
| 132 |
-
|
| 133 |
-
combined_features = outputs.pooler_output
|
| 134 |
-
logits = self.fc(combined_features)
|
| 135 |
-
|
| 136 |
-
loss = None
|
| 137 |
-
if labels is not None:
|
| 138 |
-
if self.config.task == "regression":
|
| 139 |
-
loss_fct = nn.MSELoss()
|
| 140 |
-
loss = loss_fct(logits.squeeze(-1), labels.squeeze(-1))
|
| 141 |
-
elif self.config.task == "classification":
|
| 142 |
-
loss_fct = nn.BCEWithLogitsLoss()
|
| 143 |
-
loss = loss_fct(logits, labels.float().unsqueeze(-1))
|
| 144 |
-
|
| 145 |
-
return SequenceClassifierOutput(
|
| 146 |
-
loss=loss,
|
| 147 |
-
logits=logits,
|
| 148 |
-
hidden_states=outputs.hidden_states,
|
| 149 |
-
attentions=outputs.attentions
|
| 150 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
classification/pytorch_model.bin
DELETED
|
@@ -1,3 +0,0 @@
|
|
| 1 |
-
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:bd49aa1c7c45f55e9ac164ed4863f204cac71df06cd1cef2584f5c0fd6f2b0c1
|
| 3 |
-
size 242585311
|
|
|
|
|
|
|
|
|
|
|
|