DhruvMevada3 commited on
Commit
39272b1
·
verified ·
1 Parent(s): 0d7dfe1

Export 7-class Universal BERT from best_model.pt with production ReLU architecture

Browse files
README.md ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: other
4
+ tags:
5
+ - text-classification
6
+ - bert
7
+ - insurance
8
+ - universal
9
+ - kinetic
10
+ - riskguru
11
+ pipeline_tag: text-classification
12
+ library_name: transformers
13
+ ---
14
+
15
+ # BERT 7-Class Universal Page Classifier
16
+
17
+ Fine-tuned BERT model for classifying insurance document pages (Universal / Kinetic / RG / Wrap 7-class model).
18
+
19
+ Used for document-type signals when OpenAI classification is unavailable (e.g. Kinetic fallback) and for page routing in RG/Wrap pipelines.
20
+
21
+ ## Labels
22
+
23
+ | ID | Label |
24
+ |----|-------|
25
+ | 0 | acord |
26
+ | 1 | contract |
27
+ | 2 | declaration |
28
+ | 3 | endorsements |
29
+ | 4 | forms |
30
+ | 5 | others |
31
+ | 6 | rating |
32
+
33
+ ## Usage (RunPod / Foundry / any HF runtime)
34
+
35
+ ```python
36
+ import os
37
+ import torch
38
+ from transformers import AutoTokenizer, AutoModel
39
+
40
+ repo = "injala/bert-universal-classifier-7class"
41
+ token = os.environ.get("HF_TOKEN")
42
+
43
+ tokenizer = AutoTokenizer.from_pretrained(repo, token=token)
44
+ model = AutoModel.from_pretrained(repo, token=token, trust_remote_code=True)
45
+ model.eval()
46
+
47
+ text = "ACORD 25 CERTIFICATE OF LIABILITY INSURANCE ..."
48
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
49
+ with torch.no_grad():
50
+ logits = model(**inputs)["logits"]
51
+ probs = torch.softmax(logits, dim=-1)
52
+ pred_id = probs.argmax(dim=-1).item()
53
+ label = model.config.id2label[str(pred_id)]
54
+ ```
55
+
56
+ **Note:** Input should be full OCR page text (up to 512 tokens), not short snippets. Production uses ReLU on classifier logits (matches legacy `BERT_Model` inference).
57
+
58
+ ## Source
59
+
60
+ Exported from `injala/rg_berts_21classes_7classes/best_model.pt`.
bert_universal_classifier_model.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Custom 7-class universal BERT page classifier (Kinetic / RG / Wrap production architecture)."""
2
+
3
+ from transformers import BertConfig, BertModel, BertPreTrainedModel
4
+ import torch.nn as nn
5
+
6
+
7
+ class BertUniversalClassifierConfig(BertConfig):
8
+ model_type = "bert_universal_classifier"
9
+
10
+
11
+ class BertUniversalClassifier(BertPreTrainedModel):
12
+ config_class = BertUniversalClassifierConfig
13
+
14
+ def __init__(self, config):
15
+ super().__init__(config)
16
+ self.bert = BertModel(config)
17
+ self.dropout = nn.Dropout(0.2)
18
+ self.classifier = nn.Linear(config.hidden_size, config.num_labels)
19
+ self.relu = nn.ReLU()
20
+ self.post_init()
21
+
22
+ def forward(
23
+ self,
24
+ input_ids=None,
25
+ attention_mask=None,
26
+ token_type_ids=None,
27
+ labels=None,
28
+ **kwargs,
29
+ ):
30
+ outputs = self.bert(
31
+ input_ids,
32
+ attention_mask=attention_mask,
33
+ token_type_ids=token_type_ids,
34
+ )
35
+ pooled_output = self.dropout(outputs.pooler_output)
36
+ logits = self.relu(self.classifier(pooled_output))
37
+
38
+ loss = None
39
+ if labels is not None:
40
+ loss_fn = nn.CrossEntropyLoss()
41
+ loss = loss_fn(logits, labels)
42
+
43
+ return {"loss": loss, "logits": logits}
config.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertUniversalClassifier"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "id2label": {
11
+ "0": "acord",
12
+ "1": "contract",
13
+ "2": "declaration",
14
+ "3": "endorsements",
15
+ "4": "forms",
16
+ "5": "others",
17
+ "6": "rating"
18
+ },
19
+ "initializer_range": 0.02,
20
+ "intermediate_size": 3072,
21
+ "label2id": {
22
+ "acord": 0,
23
+ "contract": 1,
24
+ "declaration": 2,
25
+ "endorsements": 3,
26
+ "forms": 4,
27
+ "others": 5,
28
+ "rating": 6
29
+ },
30
+ "layer_norm_eps": 1e-12,
31
+ "max_position_embeddings": 512,
32
+ "model_type": "bert_universal_classifier",
33
+ "num_attention_heads": 12,
34
+ "num_hidden_layers": 12,
35
+ "pad_token_id": 0,
36
+ "position_embedding_type": "absolute",
37
+ "torch_dtype": "float32",
38
+ "transformers_version": "4.29.2",
39
+ "type_vocab_size": 2,
40
+ "use_cache": true,
41
+ "vocab_size": 30522,
42
+ "auto_map": {
43
+ "AutoConfig": "bert_universal_classifier_model.BertUniversalClassifierConfig",
44
+ "AutoModel": "bert_universal_classifier_model.BertUniversalClassifier"
45
+ }
46
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:06c52b0687f9ee9e796d3f710d9d6ab697f113e071ec3816d4d5840f9c04732f
3
+ size 437978212
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer_config.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": true,
6
+ "mask_token": "[MASK]",
7
+ "model_max_length": 512,
8
+ "never_split": null,
9
+ "pad_token": "[PAD]",
10
+ "sep_token": "[SEP]",
11
+ "strip_accents": null,
12
+ "tokenize_chinese_chars": true,
13
+ "tokenizer_class": "BertTokenizer",
14
+ "unk_token": "[UNK]"
15
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff