| # Model Card: Topic Classification |
|
|
| ## Model Overview |
|
|
| **Model Name:** sdd-topic-classification |
| **Base Model:** `indobenchmark/indobert-base-p2` |
| **Task:** Multi-class text classification (13 news categories) |
| **Language:** Indonesian |
|
|
| --- |
|
|
| ## Model Description |
|
|
| Fine-tuned IndoBERT for classifying Indonesian news articles into 13 topic categories. |
|
|
| **Categories:** |
| Budaya, Ekonomi, Entertainment, HukumDanKriminal, Kesehatan, Lifestyle, Otomotif, Pendidikan, Politik, Sport, Tekno, Wisata, Lainnya |
|
|
| --- |
|
|
| ## Performance Metrics |
|
|
| | Metric | Value | |
| |---|---| |
| | Accuracy | 0.8167 | |
| | Macro F1 | 0.7871 | |
| | Latency (mean) | 9.36 ms | |
| | Model Size | 474.7 MB | |
|
|
| --- |
|
|
| ## Usage |
|
|
| ### Load Model |
|
|
| ```python |
| from transformers import AutoTokenizer, AutoModelForSequenceClassification |
| import torch |
| |
| model_name = "AzrilFahmiardi/sdd-topic-classification" |
| tokenizer = AutoTokenizer.from_pretrained(model_name) |
| model = AutoModelForSequenceClassification.from_pretrained(model_name) |
| |
| device = torch.device("cuda" if torch.cuda.is_available() else "cpu") |
| model = model.to(device) |
| ``` |
|
|
| ### Inference |
|
|
| ```python |
| def classify_text(text: str) -> dict: |
| inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256).to(device) |
| |
| with torch.no_grad(): |
| outputs = model(**inputs) |
| logits = outputs.logits |
| |
| probabilities = torch.softmax(logits, dim=-1)[0].cpu() |
| predicted_class = logits.argmax(-1).item() |
| predicted_label = model.config.id2label[predicted_class] |
| confidence = probabilities[predicted_class].item() |
| |
| return { |
| "topic": predicted_label, |
| "confidence": confidence |
| } |
| |
| # Example |
| text = "Bank Indonesia pertahankan suku bunga acuan di tengah tekanan inflasi global." |
| result = classify_text(text) |
| print(f"Topic: {result['topic']} ({result['confidence']:.2%})") |
| ``` |
|
|
| ### Output Format |
|
|
| ```json |
| { |
| "topic": "Ekonomi", |
| "confidence": 0.9523 |
| } |
| ``` |
|
|
| --- |
|
|
| ## Input/Output |
|
|
| | Parameter | Type | Example | |
| |---|---|---| |
| | **Input** | str | Indonesian news text, max 256 tokens | |
| | **Output** | dict | `{"topic": "Ekonomi", "confidence": 0.95}` | |
|
|