Text Classification
Transformers
Safetensors
English
bert_universal_classifier
feature-extraction
bert
insurance
universal
kinetic
riskguru
custom_code
Instructions to use injala/bert-universal-classifier-7class with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use injala/bert-universal-classifier-7class with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="injala/bert-universal-classifier-7class", trust_remote_code=True)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("injala/bert-universal-classifier-7class", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
File size: 1,277 Bytes
39272b1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | """Custom 7-class universal BERT page classifier (Kinetic / RG / Wrap production architecture)."""
from transformers import BertConfig, BertModel, BertPreTrainedModel
import torch.nn as nn
class BertUniversalClassifierConfig(BertConfig):
model_type = "bert_universal_classifier"
class BertUniversalClassifier(BertPreTrainedModel):
config_class = BertUniversalClassifierConfig
def __init__(self, config):
super().__init__(config)
self.bert = BertModel(config)
self.dropout = nn.Dropout(0.2)
self.classifier = nn.Linear(config.hidden_size, config.num_labels)
self.relu = nn.ReLU()
self.post_init()
def forward(
self,
input_ids=None,
attention_mask=None,
token_type_ids=None,
labels=None,
**kwargs,
):
outputs = self.bert(
input_ids,
attention_mask=attention_mask,
token_type_ids=token_type_ids,
)
pooled_output = self.dropout(outputs.pooler_output)
logits = self.relu(self.classifier(pooled_output))
loss = None
if labels is not None:
loss_fn = nn.CrossEntropyLoss()
loss = loss_fn(logits, labels)
return {"loss": loss, "logits": logits}
|