Upload BERTClassifier
Browse files- config.json +3 -0
- model.py +28 -0
- model.safetensors +1 -1
config.json
CHANGED
|
@@ -4,6 +4,9 @@
|
|
| 4 |
"BERTClassifier"
|
| 5 |
],
|
| 6 |
"attention_probs_dropout_prob": 0.1,
|
|
|
|
|
|
|
|
|
|
| 7 |
"classifier_dropout": null,
|
| 8 |
"gradient_checkpointing": false,
|
| 9 |
"hidden_act": "gelu",
|
|
|
|
| 4 |
"BERTClassifier"
|
| 5 |
],
|
| 6 |
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"auto_map": {
|
| 8 |
+
"AutoModel": "model.BERTClassifier"
|
| 9 |
+
},
|
| 10 |
"classifier_dropout": null,
|
| 11 |
"gradient_checkpointing": false,
|
| 12 |
"hidden_act": "gelu",
|
model.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from torch import nn
|
| 2 |
+
from transformers import BertModel, PreTrainedModel
|
| 3 |
+
|
| 4 |
+
class BERTClassifier(PreTrainedModel):
|
| 5 |
+
def __init__(self, config):
|
| 6 |
+
super().__init__(config)
|
| 7 |
+
self.bert = BertModel(config)
|
| 8 |
+
self.dropout = nn.Dropout(0.1)
|
| 9 |
+
self.fc = nn.Linear(self.bert.config.hidden_size, 16)
|
| 10 |
+
|
| 11 |
+
def forward(self, input_ids, attention_mask):
|
| 12 |
+
outputs = self.bert(input_ids=input_ids, attention_mask=attention_mask)
|
| 13 |
+
pooled_output = outputs.pooler_output
|
| 14 |
+
x = self.dropout(pooled_output)
|
| 15 |
+
logits = self.fc(x)
|
| 16 |
+
return logits
|
| 17 |
+
|
| 18 |
+
def print_test(self, x):
|
| 19 |
+
return "lmao"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
if __name__ == "__main__":
|
| 23 |
+
|
| 24 |
+
from transformers import BertConfig, BertModel, BertForMaskedLM, AutoConfig
|
| 25 |
+
|
| 26 |
+
# Initializing a BERT google-bert/bert-base-uncased style configuration
|
| 27 |
+
config = AutoConfig.from_pretrained('google-bert/bert-base-uncased', trust_remote_code=True)
|
| 28 |
+
model = BERTClassifier(config)
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 438001696
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a7bd7ed63579a02de09de21fe7d95b4df37dcb129ecef34c95653af627cc5745
|
| 3 |
size 438001696
|