prabhaskenche
commited on
Upload 9 files
Browse files- README (1).md +73 -0
- app (2).py +22 -0
- config.json +28 -0
- merges (1).txt +0 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +51 -0
- tokenizer_config (1).json +56 -0
- vocab.json +0 -0
README (1).md
ADDED
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: afl-3.0
|
3 |
+
language:
|
4 |
+
- en
|
5 |
+
- te
|
6 |
+
metrics:
|
7 |
+
- accuracy
|
8 |
+
pipeline_tag: text-classification
|
9 |
+
library_name: transformers
|
10 |
+
tags:
|
11 |
+
- toxic-comment-classification
|
12 |
+
- roberta
|
13 |
+
- text-classification
|
14 |
+
---
|
15 |
+
# Toxic Comment Classification Using RoBERTa
|
16 |
+
|
17 |
+
## Overview
|
18 |
+
|
19 |
+
This project provides a toxic comment classification model based on RoBERTa (Robustly optimized BERT approach). The model is designed to classify comments as toxic or non-toxic, helping in moderating online discussions and improving community interactions.
|
20 |
+
|
21 |
+
## Model Details
|
22 |
+
|
23 |
+
- **Model Name**: RoBERTa for Toxic Comment Classification
|
24 |
+
- **Architecture**: RoBERTa
|
25 |
+
- **Fine-tuning Task**: Binary classification (toxic vs. non-toxic)
|
26 |
+
- **Evaluation Metrics**:
|
27 |
+
- Accuracy
|
28 |
+
- F1 Score
|
29 |
+
- Precision
|
30 |
+
- Recall
|
31 |
+
|
32 |
+
## Files
|
33 |
+
|
34 |
+
- `pytorch_model.bin`: The trained model weights.
|
35 |
+
- `config.json`: Model configuration file.
|
36 |
+
- `merges.txt`: BPE tokenizer merges file.
|
37 |
+
- `model.safetensors`: Model weights in safetensors format.
|
38 |
+
- `special_tokens_map.json`: Tokenizer special tokens mapping.
|
39 |
+
- `tokenizer_config.json`: Tokenizer configuration file.
|
40 |
+
- `vocab.json`: Tokenizer vocabulary file.
|
41 |
+
- `roberta-toxic-comment-classifier.pkl`: Serialized best model state dictionary (for PyTorch).
|
42 |
+
- `README.md`: This documentation file.
|
43 |
+
|
44 |
+
## Model Performance
|
45 |
+
|
46 |
+
- **Accuracy**: 0.9599
|
47 |
+
- **F1 Score**: 0.9615
|
48 |
+
- **Precision**: 0.9646
|
49 |
+
- **Recall**: 0.9599
|
50 |
+
|
51 |
+
## Load the model
|
52 |
+
```
|
53 |
+
from transformers import pipeline
|
54 |
+
|
55 |
+
# Load the model and tokenizer
|
56 |
+
model_name = "prabhaskenche/pk-toxic-comment-classification-using-RoBERTa"
|
57 |
+
classifier = pipeline("text-classification", model=model_name)
|
58 |
+
|
59 |
+
# Example usage
|
60 |
+
text = "You're the worst person I've ever met."
|
61 |
+
result = classifier(text)
|
62 |
+
print(result)
|
63 |
+
|
64 |
+
```
|
65 |
+
|
66 |
+
## Usage
|
67 |
+
|
68 |
+
### Installation
|
69 |
+
|
70 |
+
Install the required packages:
|
71 |
+
|
72 |
+
```bash
|
73 |
+
pip install torch transformers sklearn
|
app (2).py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Load the model using the correct identifier
|
5 |
+
classifier = pipeline('text-classification', model='prabhaskenche/toxic-comment-classification-using-RoBERTa')
|
6 |
+
|
7 |
+
def classify(text):
|
8 |
+
results = classifier(text)
|
9 |
+
# Adjust the label names based on your model's label mapping
|
10 |
+
non_toxic_score = next((item['score'] for item in results[0] if item['label'] == 'LABEL_0'), 0)
|
11 |
+
toxic_score = next((item['score'] for item in results[0] if item['label'] == 'LABEL_1'), 0)
|
12 |
+
return f"{non_toxic_score:.3f} non-toxic, {toxic_score:.3f} toxic"
|
13 |
+
|
14 |
+
# Create the Gradio interface
|
15 |
+
interface = gr.Interface(
|
16 |
+
fn=classify,
|
17 |
+
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
|
18 |
+
outputs="text"
|
19 |
+
)
|
20 |
+
|
21 |
+
# Launch the interface
|
22 |
+
interface.launch()
|
config.json
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "roberta-large",
|
3 |
+
"architectures": [
|
4 |
+
"RobertaForSequenceClassification"
|
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": 1024,
|
13 |
+
"initializer_range": 0.02,
|
14 |
+
"intermediate_size": 4096,
|
15 |
+
"layer_norm_eps": 1e-05,
|
16 |
+
"max_position_embeddings": 514,
|
17 |
+
"model_type": "roberta",
|
18 |
+
"num_attention_heads": 16,
|
19 |
+
"num_hidden_layers": 24,
|
20 |
+
"pad_token_id": 1,
|
21 |
+
"position_embedding_type": "absolute",
|
22 |
+
"problem_type": "single_label_classification",
|
23 |
+
"torch_dtype": "float32",
|
24 |
+
"transformers_version": "4.42.4",
|
25 |
+
"type_vocab_size": 1,
|
26 |
+
"use_cache": true,
|
27 |
+
"vocab_size": 50265
|
28 |
+
}
|
merges (1).txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9ae7732394eb090294e53d529b75236c40bacf9927cdde6f70ffbe375120e210
|
3 |
+
size 1421495416
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:9813a554fe148818b949baeb3b80e4f5114c58a17491a65582ecf251e4b30211
|
3 |
+
size 1421612078
|
special_tokens_map.json
ADDED
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"bos_token": {
|
3 |
+
"content": "<s>",
|
4 |
+
"lstrip": false,
|
5 |
+
"normalized": true,
|
6 |
+
"rstrip": false,
|
7 |
+
"single_word": false
|
8 |
+
},
|
9 |
+
"cls_token": {
|
10 |
+
"content": "<s>",
|
11 |
+
"lstrip": false,
|
12 |
+
"normalized": true,
|
13 |
+
"rstrip": false,
|
14 |
+
"single_word": false
|
15 |
+
},
|
16 |
+
"eos_token": {
|
17 |
+
"content": "</s>",
|
18 |
+
"lstrip": false,
|
19 |
+
"normalized": true,
|
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": true,
|
34 |
+
"rstrip": false,
|
35 |
+
"single_word": false
|
36 |
+
},
|
37 |
+
"sep_token": {
|
38 |
+
"content": "</s>",
|
39 |
+
"lstrip": false,
|
40 |
+
"normalized": true,
|
41 |
+
"rstrip": false,
|
42 |
+
"single_word": false
|
43 |
+
},
|
44 |
+
"unk_token": {
|
45 |
+
"content": "<unk>",
|
46 |
+
"lstrip": false,
|
47 |
+
"normalized": true,
|
48 |
+
"rstrip": false,
|
49 |
+
"single_word": false
|
50 |
+
}
|
51 |
+
}
|
tokenizer_config (1).json
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"add_prefix_space": false,
|
3 |
+
"added_tokens_decoder": {
|
4 |
+
"0": {
|
5 |
+
"content": "<s>",
|
6 |
+
"lstrip": false,
|
7 |
+
"normalized": true,
|
8 |
+
"rstrip": false,
|
9 |
+
"single_word": false,
|
10 |
+
"special": true
|
11 |
+
},
|
12 |
+
"1": {
|
13 |
+
"content": "<pad>",
|
14 |
+
"lstrip": false,
|
15 |
+
"normalized": true,
|
16 |
+
"rstrip": false,
|
17 |
+
"single_word": false,
|
18 |
+
"special": true
|
19 |
+
},
|
20 |
+
"2": {
|
21 |
+
"content": "</s>",
|
22 |
+
"lstrip": false,
|
23 |
+
"normalized": true,
|
24 |
+
"rstrip": false,
|
25 |
+
"single_word": false,
|
26 |
+
"special": true
|
27 |
+
},
|
28 |
+
"3": {
|
29 |
+
"content": "<unk>",
|
30 |
+
"lstrip": false,
|
31 |
+
"normalized": true,
|
32 |
+
"rstrip": false,
|
33 |
+
"single_word": false,
|
34 |
+
"special": true
|
35 |
+
},
|
36 |
+
"50264": {
|
37 |
+
"content": "<mask>",
|
38 |
+
"lstrip": true,
|
39 |
+
"normalized": false,
|
40 |
+
"rstrip": false,
|
41 |
+
"single_word": false,
|
42 |
+
"special": true
|
43 |
+
}
|
44 |
+
},
|
45 |
+
"bos_token": "<s>",
|
46 |
+
"clean_up_tokenization_spaces": true,
|
47 |
+
"cls_token": "<s>",
|
48 |
+
"eos_token": "</s>",
|
49 |
+
"errors": "replace",
|
50 |
+
"mask_token": "<mask>",
|
51 |
+
"model_max_length": 512,
|
52 |
+
"pad_token": "<pad>",
|
53 |
+
"sep_token": "</s>",
|
54 |
+
"tokenizer_class": "RobertaTokenizer",
|
55 |
+
"unk_token": "<unk>"
|
56 |
+
}
|
vocab.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|