AmritJain commited on
Commit
1aabcde
·
verified ·
1 Parent(s): b8b266e

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +263 -199
README.md CHANGED
@@ -1,199 +1,263 @@
1
- ---
2
- library_name: transformers
3
- tags: []
4
- ---
5
-
6
- # Model Card for Model ID
7
-
8
- <!-- Provide a quick summary of what the model is/does. -->
9
-
10
-
11
-
12
- ## Model Details
13
-
14
- ### Model Description
15
-
16
- <!-- Provide a longer summary of what this model is. -->
17
-
18
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
110
-
111
- <!-- This should link to a Dataset Card if possible. -->
112
-
113
- [More Information Needed]
114
-
115
- #### Factors
116
-
117
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
118
-
119
- [More Information Needed]
120
-
121
- #### Metrics
122
-
123
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
124
-
125
- [More Information Needed]
126
-
127
- ### Results
128
-
129
- [More Information Needed]
130
-
131
- #### Summary
132
-
133
-
134
-
135
- ## Model Examination [optional]
136
-
137
- <!-- Relevant interpretability work for the model goes here -->
138
-
139
- [More Information Needed]
140
-
141
- ## Environmental Impact
142
-
143
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
144
-
145
- Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
146
-
147
- - **Hardware Type:** [More Information Needed]
148
- - **Hours used:** [More Information Needed]
149
- - **Cloud Provider:** [More Information Needed]
150
- - **Compute Region:** [More Information Needed]
151
- - **Carbon Emitted:** [More Information Needed]
152
-
153
- ## Technical Specifications [optional]
154
-
155
- ### Model Architecture and Objective
156
-
157
- [More Information Needed]
158
-
159
- ### Compute Infrastructure
160
-
161
- [More Information Needed]
162
-
163
- #### Hardware
164
-
165
- [More Information Needed]
166
-
167
- #### Software
168
-
169
- [More Information Needed]
170
-
171
- ## Citation [optional]
172
-
173
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
174
-
175
- **BibTeX:**
176
-
177
- [More Information Needed]
178
-
179
- **APA:**
180
-
181
- [More Information Needed]
182
-
183
- ## Glossary [optional]
184
-
185
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
186
-
187
- [More Information Needed]
188
-
189
- ## More Information [optional]
190
-
191
- [More Information Needed]
192
-
193
- ## Model Card Authors [optional]
194
-
195
- [More Information Needed]
196
-
197
- ## Model Card Contact
198
-
199
- [More Information Needed]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: apache-2.0
4
+ tags:
5
+ - toxicity-detection
6
+ - text-classification
7
+ - dendritic-optimization
8
+ - perforated-backpropagation
9
+ - bert-tiny
10
+ - efficient-ml
11
+ datasets:
12
+ - jigsaw-toxic-comment-classification-challenge
13
+ metrics:
14
+ - f1
15
+ - accuracy
16
+ - precision
17
+ - recall
18
+ model-index:
19
+ - name: dendritic-bert-tiny-toxicity
20
+ results:
21
+ - task:
22
+ type: text-classification
23
+ name: Toxicity Detection
24
+ dataset:
25
+ name: Civil Comments
26
+ type: jigsaw_toxicity_pred
27
+ metrics:
28
+ - type: f1
29
+ value: 0.358
30
+ name: F1 Score (Toxic Class)
31
+ - type: accuracy
32
+ value: 0.918
33
+ name: Accuracy
34
+ - type: inference_time
35
+ value: 2.25
36
+ name: Inference Latency (ms)
37
+ ---
38
+
39
+ # Dendritic BERT-Tiny for Toxicity Detection
40
+
41
+ ## Model Description
42
+
43
+ This model applies **Perforated Backpropagation with Dendritic Optimization** to enhance a compact BERT-Tiny model (4.8M parameters) for toxicity classification. It achieves performance comparable to BERT-Base (109M parameters) while maintaining **17.8x faster inference speed**.
44
+
45
+ **Key Features:**
46
+ - **22.8x smaller** than BERT-Base (4.8M vs 109M parameters)
47
+ - **17.8x faster** inference (2.25ms vs 40ms)
48
+ - **Superior toxic detection** (F1=0.358 vs BERT-Base F1=0.05)
49
+ - **Dendritic optimization** using PerforatedAI
50
+ - **Edge-ready** for real-time deployment
51
+
52
+ ## Model Details
53
+
54
+ - **Model Type:** BERT-Tiny with Dendritic Optimization
55
+ - **Language:** English
56
+ - **Task:** Binary Text Classification (Toxic/Non-Toxic)
57
+ - **Base Model:** [prajjwal1/bert-tiny](https://huggingface.co/prajjwal1/bert-tiny)
58
+ - **Framework:** PyTorch 2.9.1 + PerforatedAI 3.0.7
59
+ - **Parameters:** 4,798,468
60
+ - **Model Size:** 19.3 MB
61
+
62
+ ## Performance Metrics
63
+
64
+ | Metric | Dendritic BERT-Tiny | BERT-Base | Improvement |
65
+ |--------|---------------------|-----------|-------------|
66
+ | **Parameters** | 4.8M | 109M | 22.8x smaller |
67
+ | **F1 Score (Toxic)** | 0.358 | 0.050 | 7.16x better |
68
+ | **Accuracy** | 91.8% | 91.0% | +0.8% |
69
+ | **Inference Time** | 2.25ms | 40.1ms | 17.8x faster |
70
+ | **Throughput** | 444 samples/s | 25 samples/s | 17.8x higher |
71
+
72
+ ## Intended Use
73
+
74
+ ### Primary Use Cases
75
+ - Real-time content moderation in online forums and social media
76
+ - Edge device deployment for resource-constrained environments
77
+ - High-throughput toxicity screening systems
78
+ - Research in efficient NLP and dendritic optimization
79
+
80
+ ### Limitations
81
+ - Trained on Civil Comments dataset (English only)
82
+ - May not generalize to all forms of toxicity or cultural contexts
83
+ - Class imbalance handling (94% non-toxic samples)
84
+ - Best suited for binary toxicity detection
85
+
86
+ ## How to Use
87
+
88
+ ### Installation
89
+
90
+ ```bash
91
+ pip install transformers torch perforatedai
92
+ ```
93
+
94
+ ### Quick Start
95
+
96
+ ```python
97
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
98
+ import torch
99
+
100
+ # Load model and tokenizer
101
+ model_name = "your-username/dendritic-bert-tiny-toxicity"
102
+ tokenizer = AutoTokenizer.from_pretrained("prajjwal1/bert-tiny")
103
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
104
+
105
+ # Prepare input
106
+ text = "This is a sample comment to classify"
107
+ inputs = tokenizer(text, return_tensors="pt", max_length=128, truncation=True, padding=True)
108
+
109
+ # Inference
110
+ model.eval()
111
+ with torch.no_grad():
112
+ outputs = model(**inputs)
113
+ logits = outputs.logits
114
+ prediction = torch.argmax(logits, dim=-1)
115
+
116
+ # Get result
117
+ label = "toxic" if prediction.item() == 1 else "non-toxic"
118
+ confidence = torch.softmax(logits, dim=-1)[0][prediction].item()
119
+ print(f"Prediction: {label} (confidence: {confidence:.2%})")
120
+ ```
121
+
122
+ ### Batch Processing for High Throughput
123
+
124
+ ```python
125
+ import torch
126
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
127
+
128
+ model_name = "your-username/dendritic-bert-tiny-toxicity"
129
+ tokenizer = AutoTokenizer.from_pretrained("prajjwal1/bert-tiny")
130
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
131
+
132
+ # Example batch of comments
133
+ comments = [
134
+ "This is a great discussion!",
135
+ "You are absolutely terrible",
136
+ "I disagree but respect your opinion",
137
+ ]
138
+
139
+ # Tokenize batch
140
+ inputs = tokenizer(comments, return_tensors="pt", max_length=128,
141
+ truncation=True, padding=True)
142
+
143
+ # Batch inference
144
+ model.eval()
145
+ with torch.no_grad():
146
+ outputs = model(**inputs)
147
+ predictions = torch.argmax(outputs.logits, dim=-1)
148
+ probabilities = torch.softmax(outputs.logits, dim=-1)
149
+
150
+ # Display results
151
+ for comment, pred, probs in zip(comments, predictions, probabilities):
152
+ label = "toxic" if pred.item() == 1 else "non-toxic"
153
+ confidence = probs[pred].item()
154
+ print(f"'{comment}' -> {label} ({confidence:.2%})")
155
+ ```
156
+
157
+ ### Edge Deployment with Quantization
158
+
159
+ ```python
160
+ import torch
161
+ from transformers import AutoModelForSequenceClassification
162
+
163
+ model = AutoModelForSequenceClassification.from_pretrained(
164
+ "your-username/dendritic-bert-tiny-toxicity"
165
+ )
166
+
167
+ # Dynamic quantization for edge devices
168
+ quantized_model = torch.quantization.quantize_dynamic(
169
+ model, {torch.nn.Linear}, dtype=torch.qint8
170
+ )
171
+
172
+ # Model is now ~75% smaller and faster on CPU
173
+ ```
174
+
175
+ ## Training Details
176
+
177
+ ### Training Dataset
178
+ - **Source:** Civil Comments / Jigsaw Toxicity Dataset
179
+ - **Train samples:** 5,000 (4.54% toxic)
180
+ - **Validation samples:** 1,000 (6.60% toxic)
181
+ - **Test samples:** 1,000 (9.00% toxic)
182
+
183
+ ### Training Procedure
184
+ - **Optimizer:** AdamW (lr=2e-5, weight_decay=0.01)
185
+ - **Epochs:** 10
186
+ - **Batch size:** 32
187
+ - **Max sequence length:** 128 tokens
188
+ - **Loss function:** Cross-entropy with class weights (1.0, 21.0)
189
+ - **Warmup steps:** 500
190
+ - **Early stopping:** Patience 3 epochs
191
+
192
+ ### Dendritic Optimization
193
+ This model uses **Perforated Backpropagation** with dendritic nodes to enhance learning capacity:
194
+ - Correlation threshold: 0.95
195
+ - Perforated AI version: 3.0.7
196
+ - Configuration: 3D tensor output dimensions for transformer layers
197
+
198
+ ## Technical Architecture
199
+
200
+ ```
201
+ Input Text (max 128 tokens)
202
+ ↓
203
+ BERT-Tiny Tokenizer
204
+ ↓
205
+ Embedding Layer (vocab_size: 30522, hidden: 128)
206
+ ↓
207
+ Transformer Layer 1 (2 attention heads) + Dendritic Nodes
208
+ ↓
209
+ Transformer Layer 2 (2 attention heads) + Dendritic Nodes
210
+ ↓
211
+ Pooler Layer (CLS token)
212
+ ↓
213
+ Classification Head (128 → 2)
214
+ ↓
215
+ Output: [non-toxic_logit, toxic_logit]
216
+ ```
217
+
218
+ ## Ethical Considerations
219
+
220
+ ### Bias and Fairness
221
+ - Model may inherit biases from the Civil Comments dataset
222
+ - Performance may vary across demographic groups and cultural contexts
223
+ - Should not be the sole decision-maker in content moderation
224
+
225
+ ### Recommended Practices
226
+ - Use as part of a human-in-the-loop moderation system
227
+ - Regularly evaluate for fairness across user demographics
228
+ - Combine with other signals for critical decisions
229
+ - Provide appeal mechanisms for users
230
+
231
+ ## Citation
232
+
233
+ If you use this model in your research, please cite:
234
+
235
+ ```bibtex
236
+ @misc{dendritic-bert-tiny-2026,
237
+ title={Giant-Killer NLP: Dendritic Optimization for Toxicity Classification},
238
+ author={PROJECT-Z Team},
239
+ year={2026},
240
+ publisher={HuggingFace Hub},
241
+ howpublished={\url{https://huggingface.co/your-username/dendritic-bert-tiny-toxicity}},
242
+ note={PyTorch Dendritic Optimization Hackathon}
243
+ }
244
+ ```
245
+
246
+ ## Acknowledgments
247
+
248
+ - **Base Model:** BERT-Tiny by [prajjwal1](https://huggingface.co/prajjwal1)
249
+ - **Optimization Framework:** [PerforatedAI](https://perforatedai.com/)
250
+ - **Dataset:** Jigsaw/Google Civil Comments
251
+ - **Hackathon:** PyTorch Dendritic Optimization Challenge
252
+
253
+ ## License
254
+
255
+ Apache 2.0
256
+
257
+ ## Contact
258
+
259
+ For questions, issues, or collaboration opportunities, please open an issue on the [GitHub repository](https://github.com/your-username/dendritic-bert-tiny-toxicity).
260
+
261
+ ---
262
+
263
+ **Developed for the PyTorch Dendritic Optimization Hackathon - January 2026**