Adnan855570 commited on
Commit
a5fa5e3
·
verified ·
1 Parent(s): 106230d

Readme done

Browse files
Files changed (1) hide show
  1. README.md +198 -3
README.md CHANGED
@@ -1,3 +1,198 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ur
4
+ library_name: transformers
5
+ pipeline_tag: text-classification
6
+ tags:
7
+ - roberta
8
+ - urdu
9
+ - hate-speech
10
+ - sequence-classification
11
+ - pytorch
12
+ - safety
13
+ - moderation
14
+ license: other # Update to the correct license for your model/checkpoint
15
+ ---
16
+
17
+ ## Urdu RoBERTa Hate Speech Classifier
18
+
19
+ - **Base model**: `urduhack/roberta-urdu-small`
20
+ - **Task**: Binary text classification (hate vs. not_hate)
21
+ - **Language**: Urdu (ur)
22
+ - **Labels**:
23
+ - 0 → `not_hate`
24
+ - 1 → `hate`
25
+
26
+ This model fine-tunes a small RoBERTa for Urdu to detect hate speech. It is intended for content moderation, research, and educational uses. Do not use as the sole basis for enforcement or punitive actions.
27
+
28
+ ### Intended uses and limitations
29
+
30
+ - Intended:
31
+ - Flagging potentially hateful content in Urdu text (e.g., tweets, comments)
32
+ - Assisting human moderators and analysts
33
+ - Research and educational demos
34
+ - Limitations:
35
+ - May misclassify satire, reclaimed slurs, or dialectal expressions
36
+ - Sensitive to domain shift (platform/topic/user community)
37
+ - Biases may reflect the data it was trained on
38
+ - Risks:
39
+ - False positives can suppress legitimate speech
40
+ - False negatives can miss harmful content
41
+ - Mitigations:
42
+ - Use with a human-in-the-loop
43
+ - Monitor performance and update thresholds per deployment domain
44
+
45
+ ### How to use (Transformers)
46
+
47
+ ```python
48
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
49
+ import torch
50
+
51
+ MODEL_ID = "your-username/urdu-roberta-hate" # replace with your repo id
52
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
53
+ model = AutoModelForSequenceClassification.from_pretrained(MODEL_ID)
54
+ model.eval()
55
+
56
+ def predict_label(text: str) -> dict:
57
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
58
+ with torch.no_grad():
59
+ outputs = model(**inputs)
60
+ probs = outputs.logits.softmax(dim=-1).squeeze().tolist()
61
+ pred_id = int(outputs.logits.argmax(dim=-1).item())
62
+ id2label = model.config.id2label
63
+ return {
64
+ "label_id": pred_id,
65
+ "label": id2label.get(str(pred_id), id2label.get(pred_id, str(pred_id))),
66
+ "scores": {"not_hate": probs[0], "hate": probs[1]},
67
+ }
68
+
69
+ print(predict_label("یہ نفرت انگیز مواد ہے یا نہیں؟"))
70
+ ```
71
+
72
+ Or with a pipeline:
73
+
74
+ ```python
75
+ from transformers import pipeline
76
+ clf = pipeline("text-classification", model="your-username/urdu-roberta-hate", top_k=None)
77
+ print(clf("یہ نفرت انگیز مواد ہے یا نہیں؟"))
78
+ ```
79
+
80
+ ### Inference API (no code download)
81
+
82
+ - Python (requests):
83
+
84
+ ```python
85
+ import os, requests
86
+
87
+ API_URL = "https://api-inference.huggingface.co/models/your-username/urdu-roberta-hate"
88
+ HEADERS = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN', '')}"}
89
+
90
+ def infer(text: str):
91
+ r = requests.post(API_URL, headers=HEADERS, json={"inputs": text}, timeout=30)
92
+ r.raise_for_status()
93
+ return r.json() # [{label, score}, ...] OR [[{label, score}, ...]] depending on config
94
+
95
+ print(infer("یہ نفرت انگیز مواد ہے یا نہیں؟"))
96
+ ```
97
+
98
+ - cURL:
99
+
100
+ ```bash
101
+ curl -X POST \
102
+ -H "Authorization: Bearer $HF_TOKEN" \
103
+ -H "Content-Type: application/json" \
104
+ -d '{"inputs":"یہ نفرت انگیز مواد ہے یا نہیں؟"}' \
105
+ https://api-inference.huggingface.co/models/your-username/urdu-roberta-hate
106
+ ```
107
+
108
+ - huggingface_hub client:
109
+
110
+ ```python
111
+ from huggingface_hub import InferenceClient
112
+ client = InferenceClient(model="your-username/urdu-roberta-hate", token=os.environ.get("HF_TOKEN"))
113
+ print(client.text_classification("یہ نفرت انگیز مواد ہے یا نہیں؟"))
114
+ ```
115
+
116
+ ### Expected input and output
117
+
118
+ - Input: a single Urdu string (short to medium-length, e.g., tweet or comment)
119
+ - Output:
120
+ - Transformers: logits or labels via pipeline
121
+ - Recommended mapping:
122
+ - `id2label = {"0": "not_hate", "1": "hate"}`
123
+ - `label2id = {"not_hate": 0, "hate": 1}`
124
+
125
+ If you want 0/1 numeric outputs in an API, map `label` to `{not_hate: 0, hate: 1}`.
126
+
127
+ ### Preprocessing
128
+
129
+ - Standard RoBERTa tokenization (`AutoTokenizer` for the base model).
130
+ - Truncation and padding to the model max length (e.g., 128/256). Adjust as needed.
131
+
132
+ ### Training details
133
+
134
+ - Base: `urduhack/roberta-urdu-small`
135
+ - Objective: Cross-entropy, 2 classes
136
+ - Hardware: CPU or single GPU
137
+ - Hyperparameters (example; update with your actual settings):
138
+ - lr: 2e-5
139
+ - batch_size: 16
140
+ - epochs: 3–5
141
+ - max_length: 128–256
142
+ - weight_decay: 0.01
143
+ - warmup_ratio: 0.1
144
+
145
+ ### Data
146
+
147
+ - Source: Custom Urdu hate speech dataset (e.g., tweets/comments)
148
+ - Class balance: Please document distribution if available (helps threshold setting)
149
+ - Cleaning: Standard text normalization as applicable
150
+
151
+ ### Evaluation
152
+
153
+ - Metrics to report (fill in your numbers):
154
+ - Accuracy: TBD
155
+ - F1 (macro): TBD
156
+ - Precision/Recall (hate class): TBD
157
+ - Suggested threshold: argmax for 2-class; for imbalanced data, consider probability threshold tuning on a validation set.
158
+
159
+ ### Limitations and bias
160
+
161
+ - May misinterpret context, irony, or reclaimed language
162
+ - Potential domain and demographic bias
163
+ - Performance can degrade on long-form or code-mixed content
164
+
165
+ ### Responsible AI and safety
166
+
167
+ - Use as an assistive tool with human review
168
+ - Provide user appeals and error reporting
169
+ - Regularly audit for disparities
170
+
171
+ ### Deployment tips
172
+
173
+ - Direct load in Python: `from_pretrained("your-username/urdu-roberta-hate")`
174
+ - Render/Flask: set `MODEL_ID` to this repo id and load via `AutoTokenizer/AutoModelForSequenceClassification.from_pretrained(MODEL_ID)`
175
+ - HF Inference API: use bearer token for private repos or higher rate limits
176
+ - HF Space: create a Docker Space exposing `/predict` for a custom API interface
177
+
178
+ ### License
179
+
180
+ - The license must be compatible with the base model and your data usage. Update the `license:` field above and add details here.
181
+
182
+ ### Citation
183
+
184
+ If you use this model, please cite the base model and your fine-tuning work.
185
+
186
+ ```bibtex
187
+ @misc{urdu_roberta_hate_2025,
188
+ title = {Urdu RoBERTa Hate Speech Classifier},
189
+ author = {Your Name},
190
+ year = {2025},
191
+ howpublished = {\url{https://huggingface.co/your-username/urdu-roberta-hate}}
192
+ }
193
+ ```
194
+
195
+ ### Acknowledgements
196
+
197
+ - Base model: `urduhack/roberta-urdu-small`
198
+ - Libraries: 🤗 Transformers, PyTorch