Berketarak commited on
Commit
a3ba203
1 Parent(s): 11e4292

Upload model.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. model.py +37 -0
model.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ class CustomBertModel(BertPreTrainedModel):
2
+ def __init__(self, config):
3
+ super().__init__(config)
4
+ self.bert = BertModel(config)
5
+ # Freeze first 6 layers
6
+ for param in self.bert.encoder.layer[:6].parameters():
7
+ param.requires_grad = False
8
+ self.dropout = nn.Dropout(0.22)
9
+ self.fc1 = nn.Linear(768, 512)
10
+ self.relu1 = nn.ReLU()
11
+ self.fc2 = nn.Linear(512, 512)
12
+ self.relu2 = nn.ReLU()
13
+ self.fc3 = nn.Linear(512, 128)
14
+ self.relu3 = nn.ReLU()
15
+ self.fc4 = nn.Linear(128, 1)
16
+ self.sigmoid = nn.Sigmoid()
17
+ self.init_weights()
18
+
19
+ def forward(self, input_ids, attention_mask=None, token_type_ids=None):
20
+ outputs = self.bert(
21
+ input_ids,
22
+ attention_mask=attention_mask,
23
+ token_type_ids=token_type_ids,
24
+ )
25
+ pooled_output = outputs.pooler_output
26
+
27
+ x = self.dropout(pooled_output)
28
+ x = self.fc1(x)
29
+ x = self.relu1(x)
30
+ x = self.fc2(x)
31
+ x = self.relu2(x)
32
+ x = self.fc3(x)
33
+ x = self.relu3(x)
34
+ x = self.fc4(x)
35
+ logits = self.sigmoid(x)
36
+
37
+ return logits