File size: 3,919 Bytes
ddac10d
 
d3619b2
 
 
 
 
 
 
 
 
 
 
 
ddac10d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0496001
ddac10d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d3619b2
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
---
license: apache-2.0
datasets:
- gplsi/SocialTOX
language:
- es
metrics:
- f1
- precision
- recall
- confusion_matrix
base_model:
- meta-llama/Llama-3.1-8B-Instruct
library_name: transformers
---

# ๐Ÿง  Toxicity_model_Llama_3.1_8B โ€“ Spanish Toxicity Classifier (Instruction-Tuned)

## ๐Ÿ“Œ Model Description

This model is an **instruction-tuned version** of `LLaMA 3.1 8B Instruct`, specifically trained to classify the toxicity level of **Spanish-language user comments on news articles**. It distinguishes between three categories:

- **Non-toxic**
- **Slightly toxic**
- **Toxic**

The model follows instruction-based prompts and returns a single classification label in response.

---

## ๐Ÿ“‚ Training Data

The model was fine-tuned on the **[SocialTOX dataset](https://huggingface.co/datasets/gplsi/SocialTOX)**, a collection of Spanish-language comments annotated for varying levels of toxicity. These comments come from news platforms and represent real-world scenarios of online discourse.

---

## ๐Ÿ’ฌ Instruction Format

The model expects input in a structured conversational format like the one below:

```json
[
  {
    "role": "system",
    "content": "You are an expert in detecting toxicity in comments, and your goal is to classify comments based on their level of toxicity. The comments were made on news articles. The toxicity categories are:
    Slightly toxic: Comments that express sarcasm, irony, or rhetorical questions, but do not directly attack or degrade others.
    Toxic: Comments that contain derogatory or pejorative language, inappropriate jokes, fearmongering, denial of facts, threats, personal attacks, insults, degradation, or racist or sexist language. Only classify a comment as โ€œtoxicโ€ if it contains clear attack language, direct insults, or demeaning references.
    Non-toxic: Neutral or critical comments that do not include Toxic or Slightly toxic elements. Note that negative or critical comments (those with a serious or discontented tone) are Not toxic or Slightly toxic unless they meet the criteria of the categories above.
    Please write the corresponding category immediately after the word 'answer.' In case of doubt between two labels, choose the one with the lowest or no toxicity level."
  },
  {
    "role": "user",
    "content": "Text: "Narco-Bolivarian Communism"
  },
  {
    "role": "assistant",
    "content": "Toxic"
  }
]
```

## Training hyperparameters
- epochs: 3
- learning_rate: 1e-5
- beta1: 0.9
- beta2: 0.95
- weight_decay: 0.1
- batch_size global: 4
- micro_batch_size: 1
- lr_warmup_steps: 100
- max_seq_length: 512


## ๐Ÿ“Š Evaluation

The model was evaluated on a held-out **test set of 968 manually annotated comments**. Below are the confusion matrix and classification metrics:

### ๐Ÿงฎ Confusion Matrix

|                           | Non-toxic | Slightly Toxic | Toxic |
| ------------------------- | ------------------- | ------------------------ | --------------- |
| **Non-toxic**      | 325                 | 52                       | 62              |
| **Slightly Toxic** | 116                 | 257                      | 8               |
| **Toxic**          | 67                  | 12                       | 69              |

#### ๐Ÿ“ˆ Classification Report

| Class                 | Precision | Recall | F1-score   | Support |
| --------------------- | --------- | ------ | ---------- | ------- |
| **Non-toxic**      | 0.8006    | 0.6745 | 0.7322     | 381     |
| **Slightly toxic** | 0.6398    | 0.7403 | 0.6864     | 439     |
| **Toxic**          | 0.4964    | 0.4662 | 0.4808     | 148     |
|                       |           |        |            |         |
| **Accuracy**          |           |        | **0.6725** | **968** |
| **Macro average**     | 0.6456    | 0.6270 | 0.6331     | 968     |
| **Weighted average**  | 0.6812    | 0.6725 | 0.6730     | 968     |

**Macro F1-score**: `0.6331`