File size: 2,111 Bytes
4d2c5be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
language: vi
tags:
- hate-speech-detection
- vietnamese
- phobert
license: apache-2.0
datasets:
- visolex/ViHOS
metrics:
- precision
- recall
- f1
model-index:
- name: phobert-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:
- vinai/phobert-base
pipeline_tag: token-classification
---

# PhoBERT-HSD-Span

Fine-tuned from [`vinai/phobert-base`](https://huggingface.co/vinai/phobert-base) on **visolex/ViHOS** for token-level hate/offensive span detection.

## Model Details

* **Base Model**: [`vinai/phobert-base`](https://huggingface.co/vinai/phobert-base)
* **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/phobert-hsd-span")
model = AutoModelForTokenClassification.from_pretrained("visolex/phobert-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]

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))
```