File size: 3,296 Bytes
29ac3a2
 
 
 
 
 
ed86227
29ac3a2
f80b598
1b15921
 
 
f80b598
 
 
1b15921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45fd2d9
1b15921
 
 
 
1d4a3f0
 
 
1b15921
1d4a3f0
 
 
 
 
 
 
 
1b15921
 
 
 
 
 
67eaea7
1b15921
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45fd2d9
1b15921
 
 
29ac3a2
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
---
language:
- en
base_model:
- s-nlp/roberta_toxicity_classifier
pipeline_tag: text-classification
library_name: transformers
---
## Student Chat Toxicity Classifier

This model is a fine-tuned version of the `s-nlp/roberta_toxicity_classifier` and is designed to classify text-based messages in student conversations as **toxic** or **non-toxic**. It is specifically tailored to detect and flag malpractice suggestions, unethical advice, or any toxic communication while encouraging ethical and positive interactions among students.

---
๐Ÿš€ **Try the model live in this [Hugging Face Space](https://huggingface.co/spaces/Sk1306/Student_Ethics_Chat_Classifier)** ๐Ÿš€

---

## Model Details

- **Language**: English (`en`)
- **Base Model**: `s-nlp/roberta_toxicity_classifier`
- **Task**: Text Classification (Binary)
  - **Class 0**: Non-Toxic
  - **Class 1**: Toxic

### Key Features
- Detects messages promoting cheating or malpractice.
- Flags harmful or unethical advice in student chats.
- Encourages ethical and constructive communication.

---

## Training Details

- **Dataset**: The model was fine-tuned on a custom dataset containing examples of student conversations labeled as toxic (malpractice suggestions, harmful advice) or non-toxic (positive and constructive communication).
- **Preprocessing**:
  - Tokenization using `RobertaTokenizer`.
  - Truncation and padding applied for consistent input length (`max_length=128`).
- **Framework**: Hugging Face's `transformers` library.
- **Optimizer**: `AdamW`
- **Loss Function**: `CrossEntropyLoss`
- **Epochs**: 3 (adjusted for convergence)

---

## Intended Use

This model is intended for educational platforms, chat moderation tools, and student communication apps. Its purpose is to:
1. Detect toxic messages, such as cheating suggestions, harmful advice, or unethical recommendations.
2. Promote a positive and respectful chat environment for students.

---
## Use it with Gradio API:
```python
from gradio_client import Client

client = Client("Sk1306/Student_Ethics_Chat_Classifier")
result = client.predict(
		text="you can copy in exam to pass!!",
		api_name="/predict"
)
print(result)
```
## By loading Model

```python
import torch
from transformers import RobertaTokenizer, RobertaForSequenceClassification

# Load the model and tokenizer
model_name = "Sk1306/student_chat_toxicity_classifier_model"
tokenizer = RobertaTokenizer.from_pretrained(model_name)
model = RobertaForSequenceClassification.from_pretrained(model_name)

# Function for toxicity prediction
def predict_toxicity(text):
    # Tokenize the input text
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)

    # Run the text through the model
    with torch.no_grad():
        outputs = model(**inputs)
    
    # Extract logits and apply softmax to get probabilities
    logits = outputs.logits
    probabilities = torch.nn.functional.softmax(logits, dim=-1)

    # Get the predicted class (0 = Non-Toxic, 1 = Toxic)
    predicted_class = torch.argmax(probabilities, dim=-1).item()
    return "Non-Toxic" if predicted_class == 0 else "Toxic"

# Test the model
message = "You can copy answers during the exam."
prediction = predict_toxicity(message)
print(f"Message: {message}\nPrediction: {prediction}")