KevinGeertjens commited on
Commit
2868a91
1 Parent(s): 690ab37

Upload model

Browse files
Files changed (3) hide show
  1. bert_classification_model.py +24 -0
  2. config.json +3 -0
  3. pytorch_model.bin +1 -1
bert_classification_model.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch
2
+
3
+ from typing import Tuple
4
+ from transformers import PreTrainedModel, BertModel
5
+ from torch import nn
6
+
7
+
8
+ class BertClassificationModel(PreTrainedModel):
9
+
10
+ def __init__(self, config, num_main_segment=None, num_sub_segment=None):
11
+ super(BertClassificationModel, self).__init__(config=config)
12
+ self.num_main_segment = num_main_segment if num_main_segment else config.num_main_segment
13
+ self.num_sub_segment = num_sub_segment if num_sub_segment else config.num_sub_segment
14
+ self.bert = BertModel.from_pretrained("bert-base-multilingual-uncased")
15
+ self.dropout = nn.Dropout(0.1)
16
+ self.hidden_2 = nn.Linear(768, 768)
17
+ self.fc_main = nn.Linear(768, self.num_main_segment)
18
+ self.fc_sub = nn.Linear(768, self.num_sub_segment)
19
+
20
+ def forward(self, input_ids: torch.tensor, attention_masks: torch.Tensor) -> Tuple[torch.Tensor, torch.Tensor]:
21
+ outputs = self.bert(input_ids=input_ids,
22
+ attention_mask=attention_masks)
23
+ last_hidden_state_cls = outputs[0][:, 0, :]
24
+ return self.fc_main(last_hidden_state_cls), self.fc_sub(last_hidden_state_cls)
config.json CHANGED
@@ -3,6 +3,9 @@
3
  "BertClassificationModel"
4
  ],
5
  "attention_probs_dropout_prob": 0.1,
 
 
 
6
  "classifier_dropout": null,
7
  "hidden_act": "gelu",
8
  "hidden_dropout_prob": 0.1,
 
3
  "BertClassificationModel"
4
  ],
5
  "attention_probs_dropout_prob": 0.1,
6
+ "auto_map": {
7
+ "AutoModel": "bert_classification_model.BertClassificationModel"
8
+ },
9
  "classifier_dropout": null,
10
  "hidden_act": "gelu",
11
  "hidden_dropout_prob": 0.1,
pytorch_model.bin CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:c8640f9aa43de09fc7f3aacdb97faf1ef0095821627f70315bd3a986d16221fe
3
  size 671857125
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:18b607e5e17d75afbb4b65e8c03fda9e28d87a1c9259a4c9cc5f291696317003
3
  size 671857125