anonymous-CAP commited on
Commit
fee1785
·
verified ·
1 Parent(s): e9debf4

anounymos upload 3 files

Browse files
Files changed (3) hide show
  1. config.json +20 -0
  2. model.safetensors +3 -0
  3. modeling_cap.py +34 -0
config.json ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "CAPModel"
4
+ ],
5
+ "base_model_name": "roberta-base",
6
+ "dropout": 0.1,
7
+ "dtype": "float32",
8
+ "id2label": {
9
+ "0": "LABEL_0",
10
+ "1": "LABEL_1",
11
+ "2": "LABEL_2"
12
+ },
13
+ "label2id": {
14
+ "LABEL_0": 0,
15
+ "LABEL_1": 1,
16
+ "LABEL_2": 2
17
+ },
18
+ "model_type": "cap",
19
+ "transformers_version": "5.13.1"
20
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c4cf4506f60e3d3d300061b605b35c1aeb99e90d919d8a22707e0c052a85a7c4
3
+ size 498616084
modeling_cap.py ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # modeling_cap.py
2
+ import torch
3
+ import torch.nn as nn
4
+ from transformers import AutoModel, PreTrainedModel, PretrainedConfig
5
+
6
+ class CAPConfig(PretrainedConfig):
7
+ model_type = "cap"
8
+ def __init__(self, base_model_name="roberta-base", num_labels=3, dropout=0.1, **kwargs):
9
+ super().__init__(**kwargs)
10
+ self.base_model_name = base_model_name
11
+ self.num_labels = num_labels
12
+ self.dropout = dropout
13
+
14
+ class CAPModel(PreTrainedModel):
15
+ config_class = CAPConfig
16
+ base_model_prefix = "backbone"
17
+
18
+ def __init__(self, config):
19
+ super().__init__(config)
20
+ self.backbone = AutoModel.from_pretrained(config.base_model_name)
21
+ hidden_size = self.backbone.config.hidden_size
22
+ self.num_labels = config.num_labels
23
+ self.dropout = nn.Dropout(config.dropout)
24
+ self.head = nn.Linear(hidden_size, config.num_labels)
25
+
26
+ def forward(self, input_ids, attention_mask, token_valid_mask):
27
+ outputs = self.backbone(input_ids=input_ids, attention_mask=attention_mask)
28
+ subword_states = self.dropout(outputs.last_hidden_state)
29
+ token_logits = self.head(subword_states)
30
+ valid_mask = token_valid_mask.unsqueeze(-1)
31
+ masked_token_logits = token_logits * valid_mask
32
+ valid_counts = token_valid_mask.sum(dim=1, keepdim=True).clamp(min=1e-9)
33
+ sequence_logits = masked_token_logits.sum(dim=1) / valid_counts
34
+ return sequence_logits, token_logits