Create README.md
Browse files
README.md
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Model Card: Topic Classification
|
| 2 |
+
|
| 3 |
+
## Model Overview
|
| 4 |
+
|
| 5 |
+
**Model Name:** sdd-topic-classification
|
| 6 |
+
**Base Model:** `indobenchmark/indobert-base-p2`
|
| 7 |
+
**Task:** Multi-class text classification (13 news categories)
|
| 8 |
+
**Language:** Indonesian
|
| 9 |
+
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
## Model Description
|
| 13 |
+
|
| 14 |
+
Fine-tuned IndoBERT for classifying Indonesian news articles into 13 topic categories.
|
| 15 |
+
|
| 16 |
+
**Categories:**
|
| 17 |
+
Budaya, Ekonomi, Entertainment, HukumDanKriminal, Kesehatan, Lifestyle, Otomotif, Pendidikan, Politik, Sport, Tekno, Wisata, Lainnya
|
| 18 |
+
|
| 19 |
+
---
|
| 20 |
+
|
| 21 |
+
## Performance Metrics
|
| 22 |
+
|
| 23 |
+
| Metric | Value |
|
| 24 |
+
|---|---|
|
| 25 |
+
| Accuracy | 0.8167 |
|
| 26 |
+
| Macro F1 | 0.7871 |
|
| 27 |
+
| Latency (mean) | 9.36 ms |
|
| 28 |
+
| Model Size | 474.7 MB |
|
| 29 |
+
|
| 30 |
+
---
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
### Load Model
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 38 |
+
import torch
|
| 39 |
+
|
| 40 |
+
model_name = "AzrilFahmiardi/sdd-topic-classification"
|
| 41 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 42 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 43 |
+
|
| 44 |
+
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
| 45 |
+
model = model.to(device)
|
| 46 |
+
```
|
| 47 |
+
|
| 48 |
+
### Inference
|
| 49 |
+
|
| 50 |
+
```python
|
| 51 |
+
def classify_text(text: str) -> dict:
|
| 52 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256).to(device)
|
| 53 |
+
|
| 54 |
+
with torch.no_grad():
|
| 55 |
+
outputs = model(**inputs)
|
| 56 |
+
logits = outputs.logits
|
| 57 |
+
|
| 58 |
+
probabilities = torch.softmax(logits, dim=-1)[0].cpu()
|
| 59 |
+
predicted_class = logits.argmax(-1).item()
|
| 60 |
+
predicted_label = model.config.id2label[predicted_class]
|
| 61 |
+
confidence = probabilities[predicted_class].item()
|
| 62 |
+
|
| 63 |
+
return {
|
| 64 |
+
"topic": predicted_label,
|
| 65 |
+
"confidence": confidence
|
| 66 |
+
}
|
| 67 |
+
|
| 68 |
+
# Example
|
| 69 |
+
text = "Bank Indonesia pertahankan suku bunga acuan di tengah tekanan inflasi global."
|
| 70 |
+
result = classify_text(text)
|
| 71 |
+
print(f"Topic: {result['topic']} ({result['confidence']:.2%})")
|
| 72 |
+
```
|
| 73 |
+
|
| 74 |
+
### Output Format
|
| 75 |
+
|
| 76 |
+
```json
|
| 77 |
+
{
|
| 78 |
+
"topic": "Ekonomi",
|
| 79 |
+
"confidence": 0.9523
|
| 80 |
+
}
|
| 81 |
+
```
|
| 82 |
+
|
| 83 |
+
---
|
| 84 |
+
|
| 85 |
+
## Input/Output
|
| 86 |
+
|
| 87 |
+
| Parameter | Type | Example |
|
| 88 |
+
|---|---|---|
|
| 89 |
+
| **Input** | str | Indonesian news text, max 256 tokens |
|
| 90 |
+
| **Output** | dict | `{"topic": "Ekonomi", "confidence": 0.95}` |
|