Pragformer commited on
Commit
f051583
1 Parent(s): 71b6cec

Upload BERT_Arch

Browse files
Files changed (4) hide show
  1. config.json +4 -0
  2. model.py +48 -0
  3. model_config.py +13 -0
  4. pytorch_model.bin +1 -1
config.json CHANGED
@@ -2,6 +2,10 @@
2
  "architectures": [
3
  "BERT_Arch"
4
  ],
 
 
 
 
5
  "bert": {
6
  "_commit_hash": "43cf2d48e8c75d255dccab2a19e40d4774fd8853",
7
  "_name_or_path": "NTUYG/DeepSCC-RoBERTa",
 
2
  "architectures": [
3
  "BERT_Arch"
4
  ],
5
+ "auto_map": {
6
+ "AutoConfig": "model_config.PragFormerConfig",
7
+ "AutoModel": "model.BERT_Arch"
8
+ },
9
  "bert": {
10
  "_commit_hash": "43cf2d48e8c75d255dccab2a19e40d4774fd8853",
11
  "_name_or_path": "NTUYG/DeepSCC-RoBERTa",
model.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoModel, AutoConfig
2
+ import torch.nn as nn
3
+ from transformers import BertPreTrainedModel, AutoModel, PreTrainedModel
4
+ from model_config import PragFormerConfig
5
+
6
+
7
+
8
+ class BERT_Arch(PreTrainedModel): #(BertPreTrainedModel):
9
+ config_class = PragFormerConfig
10
+
11
+ def __init__(self, config):
12
+ super().__init__(config)
13
+ print(config.bert)
14
+ self.bert = AutoModel.from_pretrained(config.bert['_name_or_path'])
15
+
16
+ # dropout layer
17
+ self.dropout = nn.Dropout(config.dropout)
18
+
19
+ # relu activation function
20
+ self.relu = nn.ReLU()
21
+
22
+ # dense layer 1
23
+ self.fc1 = nn.Linear(self.config.bert['hidden_size'], config.fc1)
24
+ # self.fc1 = nn.Linear(768, 512)
25
+
26
+ # dense layer 2 (Output layer)
27
+ self.fc2 = nn.Linear(config.fc1, config.fc2)
28
+
29
+ # softmax activation function
30
+ self.softmax = nn.LogSoftmax(dim = config.softmax_dim)
31
+
32
+ # define the forward pass
33
+ def forward(self, input_ids, attention_mask):
34
+ # pass the inputs to the model
35
+ _, cls_hs = self.bert(input_ids, attention_mask = attention_mask, return_dict=False)
36
+
37
+ x = self.fc1(cls_hs)
38
+
39
+ x = self.relu(x)
40
+
41
+ x = self.dropout(x)
42
+
43
+ # output layer
44
+ x = self.fc2(x)
45
+
46
+ # apply softmax activation
47
+ x = self.softmax(x)
48
+ return x
model_config.py ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import PretrainedConfig
2
+
3
+
4
+ class PragFormerConfig(PretrainedConfig):
5
+ model_type = "pragformer"
6
+
7
+ def __init__(self, bert=None, dropout=0.2, fc1=512, fc2=2, softmax_dim=1, **kwargs):
8
+ self.bert = bert
9
+ self.dropout = dropout
10
+ self.fc1 = fc1
11
+ self.fc2 = fc2
12
+ self.softmax_dim = softmax_dim
13
+ super().__init__(**kwargs)
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:816862e8a2fc62fac62de92357c9394c6649e27b134f3da267e4dbfedad0e544
3
  size 500230377
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c662ec6193215ce2edf8b419eea4c8d8e8e907282811a58565093d0797b6638f
3
  size 500230377