Views
No views yet
322e-51002560.0150050.83880.30410.76520.27960.33331from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4# Load model and tokenizer
5model_name = "visolex/bilstm-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()}")bilstm) uses custom vocabulary-based tokenization and does not include a Hugging Face tokenizer. You will need to implement custom tokenization or load a tokenizer from a compatible base model. The model expects word-level tokenized input.