File size: 2,219 Bytes
64cf04b
2609a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64cf04b
2609a1b
 
 
 
 
 
 
 
478400d
2609a1b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language: vi
tags:
- hate-speech-detection
- vietnamese
- transformer
license: apache-2.0
datasets:
- visolex/ViHOS
metrics:
- precision
- recall
- f1
model-index:
- name: visobert-hsd-span
  results:
  - task:
      type: token-classification
      name: Hate Speech Span Detection
    dataset:
      name: ViHOS
      type: custom
    metrics:
    - name: Precision
      type: precision
      value: <INSERT_PRECISION>
    - name: Recall
      type: recall
      value: <INSERT_RECALL>
    - name: F1 Score
      type: f1
      value: <INSERT_F1>
base_model:
- uitnlp/visobert
pipeline_tag: token-classification
---

# ViSoBERT-HSD-Span

This model is fine-tuned from [`uitnlp/visobert`](https://huggingface.co/uitnlp/visobert) on the **visolex/ViHOS** dataset for span-level hate/offensive detection in Vietnamese comments.

## Model Details

* **Base Model**: [`uitnlp/visobert`](https://huggingface.co/uitnlp/visobert)
* **Dataset**: [visolex/ViHOS](https://huggingface.co/datasets/visolex/ViHOS)
* **Fine-tuning**: HuggingFace Transformers

### Hyperparameters

* Batch size: `16`
* Learning rate: `5e-5`
* Epochs: `100`
* Max sequence length: `128`
* Early stopping: `5`

## Usage

```python
from transformers import AutoTokenizer, AutoModelForTokenClassification

tokenizer = AutoTokenizer.from_pretrained("visolex/visobert-hsd-span")
model = AutoModelForTokenClassification.from_pretrained("visolex/visobert-hsd-span")

text = "Nói cái lol . t thấy thô tục vl"
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
with torch.no_grad():
    outputs = model(**inputs)
logits = outputs.logits  # [batch, seq_len, num_labels]
# For binary: use sigmoid, for multi-class: use softmax+argmax
probs = torch.sigmoid(logits)
preds = (probs > 0.5).long().squeeze().tolist()  # [seq_len]
tokens = tokenizer.convert_ids_to_tokens(inputs['input_ids'][0])

span_labels = [p[0] for p in preds]

# Lấy token có nhãn span = 1, loại bỏ <s> và </s> nếu muốn
span_tokens = [token for token, label in zip(tokens, span_labels) if label == 1 and token not in ['<s>', '</s>']]

print("Span tokens:", span_tokens)
print("Span text:", tokenizer.convert_tokens_to_string(span_tokens))
```