File size: 2,116 Bytes
84d1543
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# 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}` |