Upload folder using huggingface_hub
Browse files- README.md +77 -0
- config.json +47 -0
- model.safetensors +3 -0
- sentencepiece.bpe.model +3 -0
- special_tokens_map.json +51 -0
- tokenizer_config.json +56 -0
README.md
ADDED
@@ -0,0 +1,77 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: multilingual
|
3 |
+
license: apache-2.0
|
4 |
+
tags:
|
5 |
+
- toxicity-detection
|
6 |
+
- content-moderation
|
7 |
+
- text-classification
|
8 |
+
- multi-label-classification
|
9 |
+
datasets:
|
10 |
+
- jigsaw-toxic-comment-classification
|
11 |
+
metrics:
|
12 |
+
- f1
|
13 |
+
base_model: FacebookAI/xlm-roberta-base
|
14 |
+
widget:
|
15 |
+
- text: "This is a normal comment."
|
16 |
+
- text: "I hate you, you're stupid!"
|
17 |
+
- text: "Let's discuss this respectfully."
|
18 |
+
---
|
19 |
+
|
20 |
+
# XLM-RoBERTa Toxicity Classifier
|
21 |
+
|
22 |
+
This model is a fine-tuned version of [FacebookAI/xlm-roberta-base](https://huggingface.co/FacebookAI/xlm-roberta-base) for multi-label toxicity classification.
|
23 |
+
|
24 |
+
## Model Description
|
25 |
+
|
26 |
+
This model can classify text into the following toxicity categories:
|
27 |
+
- Toxic
|
28 |
+
- Severe Toxic
|
29 |
+
- Obscene
|
30 |
+
- Threat
|
31 |
+
- Insult
|
32 |
+
- Identity Hate
|
33 |
+
- None (for non-toxic content)
|
34 |
+
|
35 |
+
## Usage
|
36 |
+
|
37 |
+
```python
|
38 |
+
from transformers import XLMRobertaForSequenceClassification, XLMRobertaTokenizer
|
39 |
+
import torch
|
40 |
+
|
41 |
+
# Load model and tokenizer
|
42 |
+
model = XLMRobertaForSequenceClassification.from_pretrained("oleksiizirka/xlm-roberta-toxicity-classifier")
|
43 |
+
tokenizer = XLMRobertaTokenizer.from_pretrained("oleksiizirka/xlm-roberta-toxicity-classifier")
|
44 |
+
|
45 |
+
# Prepare input
|
46 |
+
text = "Your text here"
|
47 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
|
48 |
+
|
49 |
+
# Get predictions
|
50 |
+
with torch.no_grad():
|
51 |
+
outputs = model(**inputs)
|
52 |
+
predictions = torch.sigmoid(outputs.logits)
|
53 |
+
|
54 |
+
# Print results
|
55 |
+
labels = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate', 'none']
|
56 |
+
for label, score in zip(labels, predictions[0]):
|
57 |
+
if score > 0.5:
|
58 |
+
print(f"{label}: {score:.3f}")
|
59 |
+
```
|
60 |
+
|
61 |
+
## Training Data
|
62 |
+
|
63 |
+
The model was trained on the Jigsaw Toxic Comment Classification dataset.
|
64 |
+
|
65 |
+
## Training Procedure
|
66 |
+
|
67 |
+
- Base model: FacebookAI/xlm-roberta-base
|
68 |
+
- Training approach: Multi-label classification with BCEWithLogitsLoss
|
69 |
+
- Optimization: AdamW with learning rate 2e-5
|
70 |
+
- Batch size: 16
|
71 |
+
- Epochs: 3-5 with early stopping
|
72 |
+
|
73 |
+
## Limitations
|
74 |
+
|
75 |
+
- Trained primarily on English text
|
76 |
+
- May exhibit biases present in the training data
|
77 |
+
- Should be used as part of a larger content moderation system
|
config.json
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "./toxicity_classifier",
|
3 |
+
"architectures": [
|
4 |
+
"XLMRobertaForSequenceClassification"
|
5 |
+
],
|
6 |
+
"attention_probs_dropout_prob": 0.1,
|
7 |
+
"bos_token_id": 0,
|
8 |
+
"classifier_dropout": null,
|
9 |
+
"eos_token_id": 2,
|
10 |
+
"hidden_act": "gelu",
|
11 |
+
"hidden_dropout_prob": 0.1,
|
12 |
+
"hidden_size": 768,
|
13 |
+
"id2label": {
|
14 |
+
"0": "toxic",
|
15 |
+
"1": "severe_toxic",
|
16 |
+
"2": "obscene",
|
17 |
+
"3": "threat",
|
18 |
+
"4": "insult",
|
19 |
+
"5": "identity_hate",
|
20 |
+
"6": "none"
|
21 |
+
},
|
22 |
+
"initializer_range": 0.02,
|
23 |
+
"intermediate_size": 3072,
|
24 |
+
"label2id": {
|
25 |
+
"toxic": 0,
|
26 |
+
"severe_toxic": 1,
|
27 |
+
"obscene": 2,
|
28 |
+
"threat": 3,
|
29 |
+
"insult": 4,
|
30 |
+
"identity_hate": 5,
|
31 |
+
"none": 6
|
32 |
+
},
|
33 |
+
"layer_norm_eps": 1e-05,
|
34 |
+
"max_position_embeddings": 514,
|
35 |
+
"model_type": "xlm-roberta",
|
36 |
+
"num_attention_heads": 12,
|
37 |
+
"num_hidden_layers": 12,
|
38 |
+
"output_past": true,
|
39 |
+
"pad_token_id": 1,
|
40 |
+
"position_embedding_type": "absolute",
|
41 |
+
"problem_type": "multi_label_classification",
|
42 |
+
"torch_dtype": "float32",
|
43 |
+
"transformers_version": "4.49.0",
|
44 |
+
"type_vocab_size": 1,
|
45 |
+
"use_cache": true,
|
46 |
+
"vocab_size": 250002
|
47 |
+
}
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:a8cd434a26c2e654d0047f9905a0e70a5016daaff1e92404b2d92dcf2ecf6c60
|
3 |
+
size 1112220388
|
sentencepiece.bpe.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
|
3 |
+
size 5069051
|
special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": false,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": false,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": false,
|
20 |
+
"rstrip": false,
|
21 |
+
"single_word": false
|
22 |
+
},
|
23 |
+
"mask_token": {
|
24 |
+
"content": "<mask>",
|
25 |
+
"lstrip": true,
|
26 |
+
"normalized": false,
|
27 |
+
"rstrip": false,
|
28 |
+
"single_word": false
|
29 |
+
},
|
30 |
+
"pad_token": {
|
31 |
+
"content": "<pad>",
|
32 |
+
"lstrip": false,
|
33 |
+
"normalized": false,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": false,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": false,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer_config.json
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"added_tokens_decoder": {
|
3 |
+
"0": {
|
4 |
+
"content": "<s>",
|
5 |
+
"lstrip": false,
|
6 |
+
"normalized": false,
|
7 |
+
"rstrip": false,
|
8 |
+
"single_word": false,
|
9 |
+
"special": true
|
10 |
+
},
|
11 |
+
"1": {
|
12 |
+
"content": "<pad>",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"2": {
|
20 |
+
"content": "</s>",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"3": {
|
28 |
+
"content": "<unk>",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"250001": {
|
36 |
+
"content": "<mask>",
|
37 |
+
"lstrip": true,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"bos_token": "<s>",
|
45 |
+
"clean_up_tokenization_spaces": false,
|
46 |
+
"cls_token": "<s>",
|
47 |
+
"eos_token": "</s>",
|
48 |
+
"extra_special_tokens": {},
|
49 |
+
"mask_token": "<mask>",
|
50 |
+
"model_max_length": 512,
|
51 |
+
"pad_token": "<pad>",
|
52 |
+
"sep_token": "</s>",
|
53 |
+
"sp_model_kwargs": {},
|
54 |
+
"tokenizer_class": "XLMRobertaTokenizer",
|
55 |
+
"unk_token": "<unk>"
|
56 |
+
}
|