Views
No views yet
roberta-base for multilabel classification of policies, targets, and themes.1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3import numpy as np
4import joblib
5import requests
6
7model_path = "vtt-qsts-ai/multilabel-indicator-classification-roberta-base"
8model = AutoModelForSequenceClassification.from_pretrained(model_path)
9tokenizer = AutoTokenizer.from_pretrained(model_path)
10
11mlb_url = "https://huggingface.co/vtt-qsts-ai/multilabel-indicator-classification-roberta-base/resolve/main/mlb.pkl"
12mlb_path = "mlb.pkl"
13
14with open(mlb_path, "wb") as f:
15 f.write(requests.get(mlb_url).content)
16mlb = joblib.load(mlb_path)
17
18text = "This program supports clean technology and sustainable development in industries."
19
20inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
21
22model.eval()
23with torch.no_grad():
24 logits = model(**inputs).logits
25 probs = torch.sigmoid(logits).squeeze().numpy()
26
27# Threshold
28binary_preds = (probs > 0.25).astype(int)
29predicted_labels = [label for i, label in enumerate(mlb.classes_) if binary_preds[i] == 1]
30
31print("Predicted Labels:", predicted_labels)
32
33# Predicted Labels: ['PI007', 'PI008', 'TG20', 'TG21', 'TG22', 'TG25', 'TG29', 'TG31', 'TH31']