Create README.md
Browse files
README.md
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: en
|
3 |
+
tags:
|
4 |
+
- roberta
|
5 |
+
- multilabel-classification
|
6 |
+
- policy-analysis
|
7 |
+
- huggingface
|
8 |
+
datasets:
|
9 |
+
- custom
|
10 |
+
license: apache-2.0
|
11 |
+
---
|
12 |
+
|
13 |
+
# RoBERTa for Multi-label Classification of Policy Instruments
|
14 |
+
|
15 |
+
This model fine-tunes `roberta-base` for multilabel classification of policies, targets, and themes.
|
16 |
+
|
17 |
+
## Model Details
|
18 |
+
- Base model: roberta-base
|
19 |
+
- Max length: 512
|
20 |
+
- Output: 47 multilabel classes (PI - Policy Instrument, TG - Target Group, TH - Theme). There are three main classes that have further sub-categories in them.
|
21 |
+
- Threshold: 0.25
|
22 |
+
|
23 |
+
## Intended Use
|
24 |
+
Classify policy documents descriptions into thematic categories.
|
25 |
+
|
26 |
+
## How to Use
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
30 |
+
import torch
|
31 |
+
import numpy as np
|
32 |
+
import joblib
|
33 |
+
import requests
|
34 |
+
|
35 |
+
model_path = "toqeerehsan/multilabel-indicator-classification"
|
36 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_path)
|
37 |
+
tokenizer = AutoTokenizer.from_pretrained(model_path)
|
38 |
+
|
39 |
+
mlb_url = "https://huggingface.co/toqeerehsan/multilabel-indicator-classification/resolve/main/mlb.pkl"
|
40 |
+
mlb_path = "mlb.pkl"
|
41 |
+
|
42 |
+
with open(mlb_path, "wb") as f:
|
43 |
+
f.write(requests.get(mlb_url).content)
|
44 |
+
mlb = joblib.load(mlb_path)
|
45 |
+
|
46 |
+
text = "This program supports clean technology and sustainable development in industries."
|
47 |
+
|
48 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
|
49 |
+
|
50 |
+
model.eval()
|
51 |
+
with torch.no_grad():
|
52 |
+
logits = model(**inputs).logits
|
53 |
+
probs = torch.sigmoid(logits).squeeze().numpy()
|
54 |
+
|
55 |
+
# Threshold
|
56 |
+
binary_preds = (probs > 0.25).astype(int)
|
57 |
+
predicted_labels = [label for i, label in enumerate(mlb.classes_) if binary_preds[i] == 1]
|
58 |
+
|
59 |
+
print("Predicted Labels:", predicted_labels)
|
60 |
+
|
61 |
+
# Predicted Labels: ['PI007', 'PI008', 'TG20', 'TG21', 'TG22', 'TG25', 'TG29', 'TG31', 'TH31']
|