Update modeling_cap.py
Browse files- modeling_cap.py +4 -3
modeling_cap.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
-
# modeling_cap.py
|
| 2 |
import torch
|
| 3 |
import torch.nn as nn
|
| 4 |
-
from transformers import AutoModel, PreTrainedModel, PretrainedConfig
|
| 5 |
|
| 6 |
|
| 7 |
class CAPConfig(PretrainedConfig):
|
|
@@ -20,11 +19,13 @@ class CAPModel(PreTrainedModel):
|
|
| 20 |
|
| 21 |
def __init__(self, config):
|
| 22 |
super().__init__(config)
|
| 23 |
-
|
|
|
|
| 24 |
hidden_size = self.backbone.config.hidden_size
|
| 25 |
self.num_labels = config.num_labels
|
| 26 |
self.dropout = nn.Dropout(config.dropout)
|
| 27 |
self.head = nn.Linear(hidden_size, config.num_labels)
|
|
|
|
| 28 |
|
| 29 |
def forward(self, input_ids, attention_mask, token_valid_mask):
|
| 30 |
outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
import torch.nn as nn
|
| 3 |
+
from transformers import AutoModel, AutoConfig, PreTrainedModel, PretrainedConfig
|
| 4 |
|
| 5 |
|
| 6 |
class CAPConfig(PretrainedConfig):
|
|
|
|
| 19 |
|
| 20 |
def __init__(self, config):
|
| 21 |
super().__init__(config)
|
| 22 |
+
backbone_config = AutoConfig.from_pretrained(config.base_model_name)
|
| 23 |
+
self.backbone = AutoModel.from_config(backbone_config)
|
| 24 |
hidden_size = self.backbone.config.hidden_size
|
| 25 |
self.num_labels = config.num_labels
|
| 26 |
self.dropout = nn.Dropout(config.dropout)
|
| 27 |
self.head = nn.Linear(hidden_size, config.num_labels)
|
| 28 |
+
self.post_init()
|
| 29 |
|
| 30 |
def forward(self, input_ids, attention_mask, token_valid_mask):
|
| 31 |
outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
|