Views
No views yet
322e-51002560.0150050.93720.82410.93790.81600.83571from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "visolex/visobert-hsd"
6tokenizer = AutoTokenizer.from_pretrained(model_name)
7model = AutoModelForSequenceClassification.from_pretrained(
8 model_name
9)
10
11# Classify text
12text = "Văn bản tiếng Việt cần phân loại"
13inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)
14
15with torch.no_grad():
16 outputs = model(**inputs)
17 predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
18 predicted_label = torch.argmax(predictions, dim=-1).item()
19
20# Label mapping
21label_names = {
22 0: "CLEAN",
23 1: "OFFENSIVE",
24 2: "HATE"
25}
26
27print(f"Predicted label: {label_names[predicted_label]}")
28print(f"Confidence scores: {predictions[0].tolist()}")