yutingg commited on
Commit
4d71960
·
1 Parent(s): ead2f04

Upload DistillBERTSentenceLabel

Browse files
config.json CHANGED
@@ -2,6 +2,10 @@
2
  "architectures": [
3
  "DistillBERTSentenceLabel"
4
  ],
 
 
 
 
5
  "model_type": "distill_bert_sentence_label",
6
  "torch_dtype": "float32",
7
  "transformers_version": "4.24.0"
 
2
  "architectures": [
3
  "DistillBERTSentenceLabel"
4
  ],
5
+ "auto_map": {
6
+ "AutoConfig": "configuration_sentence_label.DistillBERTSentenceLabelConfig",
7
+ "AutoModel": "modeling_sentence_label.DistillBERTSentenceLabel"
8
+ },
9
  "model_type": "distill_bert_sentence_label",
10
  "torch_dtype": "float32",
11
  "transformers_version": "4.24.0"
configuration_sentence_label.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class DistillBERTSentenceLabelConfig(PretrainedConfig):
5
+ model_type = "distill_bert_sentence_label"
6
+
7
+ def __init__(
8
+ self,
9
+ **kwargs,
10
+ ):
11
+ super().__init__(**kwargs)
modeling_sentence_label.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ import torch
3
+ from transformers import DistilBertModel, PreTrainedModel
4
+ from configuration_sentence_label import DistillBERTSentenceLabelConfig
5
+
6
+ class DistillBERTSentenceLabel(PreTrainedModel):
7
+ config_class = DistillBERTSentenceLabelConfig
8
+
9
+ def __init__(self, config):
10
+ super().__init__(config)
11
+ self.l1 = DistilBertModel.from_pretrained("distilbert-base-uncased")
12
+ self.pre_classifier = torch.nn.Linear(768, 768)
13
+ self.dropout = torch.nn.Dropout(0.3)
14
+ self.classifier = torch.nn.Linear(768, 1)
15
+ # https://glassboxmedicine.com/2019/05/26/classification-sigmoid-vs-softmax/
16
+ # self.softmax = torch.nn.Softmax(dim=1)
17
+ # self.sigmoid = torch.nn.Sigmoid() # apply sigmoid on vector of 1*4
18
+
19
+
20
+ def forward(self, ids=None, mask=None):
21
+ output_1 = self.l1(input_ids=ids, attention_mask=mask)
22
+ hidden_state = output_1[0]
23
+ pooler = hidden_state[:, 0]
24
+ pooler = self.pre_classifier(pooler)
25
+ pooler = torch.nn.ReLU()(pooler)
26
+ pooler = self.dropout(pooler)
27
+ output = self.classifier(pooler)
28
+ # output = self.sigmoid(output)
29
+ # output = self.softmax(output)
30
+ return output