Downloads · 30 days
10
29% of all-time downloads
openchlsystem/CHS_tz_classifier_distilbert
CHS_tz_classifier_distilbert is a machine learning model from openchlsystem. Use it for the machine learning task on the model card, and read the license before you ship it in a product. It is set up for transformers.
This repository hosts a fine-tuned DistilBERT-base-uncased model for multi-label classification of call center transcripts. It is designed for real-time case categorization, urgency detection, and intervention recomme…
Downloads · 30 days
10
29% of all-time downloads
All-time downloads
34
Public
Parameters
67M
268 MB on disk
Likes
1
Public
Click a slice to open those files.
.safetensors268 MB · 99%
From the Hugging Face model README
This repository hosts a fine-tuned DistilBERT-base-uncased model for multi-label classification of call center transcripts.
It is designed for real-time case categorization, urgency detection, and intervention recommendations in helpline and child protection contexts.
distilbert-base-uncasedlabel mappings are alongside models, and are used to map the prediction and classification logits against class labels defined in the json files.
import torch
import json
import re
import numpy as np
from transformers import AutoTokenizer, AutoConfig, AutoModel
# Repo name on Hugging Face
model_name = "openchlsystem/CHS_tz_classifier_distilbert"
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Load config
config = AutoConfig.from_pretrained(model_name)
# We re-define the distilbert Custom model class used in training
import torch.nn as nn
from transformers import DistilBertModel, DistilBertPreTrainedModel
class MultiTaskDistilBert(DistilBertPreTrainedModel):
def __init__(self, config, num_main, num_sub, num_interv, num_priority):
super().__init__(config)
self.distilbert = DistilBertModel(config)
self.pre_classifier = nn.Linear(config.dim, config.dim)
self.classifier_main = nn.Linear(config.dim, num_main)
self.classifier_sub = nn.Linear(config.dim, num_sub)
self.classifier_interv = nn.Linear(config.dim, num_interv)
self.classifier_priority = nn.Linear(config.dim, num_priority)
self.dropout = nn.Dropout(config.dropout)
self.init_weights()
def forward(self, input_ids=None, attention_mask=None, **kwargs):
distilbert_output = self.distilbert(
input_ids=input_ids,
attention_mask=attention_mask,
return_dict=True
)
hidden_state = distilbert_output.last_hidden_state
pooled_output = hidden_state[:, 0]
pooled_output = self.pre_classifier(pooled_output)
pooled_output = nn.ReLU()(pooled_output)
pooled_output = self.dropout(pooled_output)
logits_main = self.classifier_main(pooled_output)
logits_sub = self.classifier_sub(pooled_output)
logits_interv = self.classifier_interv(pooled_output)
logits_priority = self.classifier_priority(pooled_output)
return logits_main, logits_sub, logits_interv, logits_priority
# Downloading the class labels for mapping
from huggingface_hub import hf_hub_download
main_categories = json.load(open(hf_hub_download(model_name, "main_categories.json")))
sub_categories = json.load(open(hf_hub_download(model_name, "sub_categories.json")))
interventions = json.load(open(hf_hub_download(model_name, "interventions.json")))
priorities = json.load(open(hf_hub_download(model_name, "priorities.json")))
model = MultiTaskDistilBert.from_pretrained(
model_name,
num_main=len(main_categories),
num_sub=len(sub_categories),
num_interv=len(interventions),
num_priority=len(priorities)
)
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
model = model.to(device)
# inference
def classify_multitask_case(narrative: str):
"""
Classifies a given narrative text into multiple categories using a multitask model.
Args:
narrative (str): The input text to be classified.
Returns:
dict: A dictionary containing the predicted labels for each task:
- "main_category": Predicted main category label.
- "sub_category": Predicted sub-category label.
- "intervention": Predicted intervention label.
- "priority": Predicted priority label.
Notes:
- The function preprocesses the input text by lowercasing and removing non-alphanumeric characters.
- It uses a tokenizer and a multitask classification model to generate predictions.
- Probabilities for each class are computed using softmax, and the label with the highest probability is selected for each task.
"""
text = narrative.lower().strip()
text = re.sub(r'[^a-z0-9\s]', '', text)
inputs = tokenizer(
text,
truncation=True,
padding="max_length",
max_length=256,
return_tensors="pt"
).to(device)
with torch.no_grad():
logits_main, logits_sub, logits_interv, logits_priority = model(**inputs)
# Convert to probabilities (softmax per task)
probs_main = torch.softmax(logits_main, dim=1).cpu().numpy()[0]
probs_sub = torch.softmax(logits_sub, dim=1).cpu().numpy()[0]
probs_interv = torch.softmax(logits_interv, dim=1).cpu().numpy()[0]
probs_priority = torch.softmax(logits_priority, dim=1).cpu().numpy()[0]
# Get predicted labels (argmax)
pred_main = int(np.argmax(probs_main))
pred_sub = int(np.argmax(probs_sub))
pred_interv = int(np.argmax(probs_interv))
pred_priority = int(np.argmax(probs_priority))
return {
"main_category": {
main_categories[pred_main],
# "probabilities": dict(zip(main_categories, probs_main.tolist()))
},
"sub_category": {
sub_categories[pred_sub],
# "probabilities": dict(zip(sub_categories, probs_sub.tolist()))
},
"intervention": {
interventions[pred_interv],
# "probabilities": dict(zip(interventions, probs_interv.tolist()))
},
"priority": {
priorities[pred_priority],
# "probabilities": dict(zip(priorities, probs_priority.tolist()))
},
}
# test
narrative= " Hello, I've been trying to find help for my son Ken. He's only ten years old and... he's been going through a terrible time at school. There's this boy, James Kibet, who keeps harassing him. It started with name-calling and teasing, but it's escalated to physical violence. I don't know what to do, Sarah. I can't bear to see my child suffer like this. I'm truly sorry to hear about your situation, Mary. It's never easy when our children are in pain. Can you tell me more about the school Ken attends and its location? We might be able to reach out to them for help. The school is Unknown Landmark, Muthambi Ward, Unknown Subcounty, Tharaka-Nithi County. I... I didn't want to burden anyone with this problem. But it seems like things are only getting worse. I don't know who else to turn to. Don't worry, Mary. You've taken the right step by reaching out to us today. We can help guide you through this difficult time. Let me first assure you that your call will be kept confidential. Now, I need to gather more information about the incidents. Can you describe any specific instances where Ken has been hurt or bullied? Oh, there have been so many times... one instance stands out though. About a week ago, James punched Ken during recess. He was left with a bloody lip and a black eye. The school officials were informed but they didn't seem to take any action against James.That sounds very serious, Mary. I'm afraid we may need to escalate this matter to the authorities if the school doesn't take appropriate action. We can provide you with resources and guidance on how to report this case to the police or child welfare services. Would that be alright? Yes, please. I'm willing to do whatever it takes to protect Ken. I just want him to feel safe again. Thank you for your help, Sarah"
print(classify_multitask_case(narrative))
Expected output
{'main_category': {'Advice and Counselling'}, 'sub_category': {'School Related Issues'}, 'intervention': {'Counselling'}, 'priority': {2}}
The model was fine-tuned on a proprietary dataset of over 11,000 call transcripts (1,000+ anonymized real calls and 10,000+ synthetic calls). The data was annotated for four multi-label tasks:
Main Topic: 7 classes (e.g., GBV, Nutrition) Sub-Topic: 50+ classes (e.g., Albinism, Birth Registration) Intervention: 4 classes (e.g., Referred, Counselling) Priority: 3 classes (Low, Medium, High)
The dataset was stratified and balanced to minimize bias and maximize generalization.
Text was tokenized using the DistilBERT tokenizer (distilbert-base-uncased) with a maximum sequence length of 512 tokens. Standard normalization (lowercasing) was applied.
Training Hyperparameters
Training regime: fp16 mixed precision Learning Rate: 2e-5 Train Batch Size: 16 Epochs: 12 Optimizer: AdamW Weight Decay: 0.01 Loss Function: Combined Cross-Entropy Loss (Multi-Task Learning) Evaluation
Model evaluation was performed on a held-out validation set (10% of the total data), stratified by sub-category to ensure representative distribution.
Primary Metric: Micro F1-Score (aggregated across all labels)
Secondary Metrics: Precision, Recall, and F1-score for each individual class and task.
Overall Metric: eval_avg_acc (average accuracy across all four tasks) was used for model selection.
The model achieves strong performance across all tasks, with a high Micro F1-Score. Performance is consistently high on majority classes. Continuous learning cycles are used to improve performance on minority classes.
| Task | Micro F1-Score | Notes |
|---|---|---|
| Main Topic | High (e.g., >0.90) | Robust performance on primary categorization. |
| Sub-Topic | Good (e.g., >0.80) | Performance varies; higher on frequent sub-topics. |
| Intervention | High (e.g., >0.85) | Accurate prediction of recommended actions. |
| Priority | High (e.g., >0.88) | Critical for effective routing and escalation. |
| Task | Labels | Purpose |
|---|---|---|
| Sub-Category | Adoption, Albinism, Balanced Diet, Birth Registration, Breast Feeding, etc. | Identifies detailed case topics |
| Priority/Urgency | Low, Medium, High | Flags urgency for escalation |
| Main Category | Advice & Counselling, Child Custody, Disability, GBV, VANE, Nutrition, Information | High-level categorization |
| Intervention | Referred, Counselling, Signposting, Awareness/Information | Suggests next action |
If you use this model, please cite:
@software{chs_distilbert_multilabel,
author = {Bitz AI Team},
title = {DistilBERT Multi-Label Classifier for Call Center Transcripts},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/openchlsystem/CHS_tz_classifier_distilbert}
}
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).