pronics2004
commited on
Commit
•
3ed34fd
1
Parent(s):
8d1e7ae
Update README.md
Browse files
README.md
CHANGED
@@ -3,4 +3,41 @@ license: apache-2.0
|
|
3 |
language:
|
4 |
- en
|
5 |
pipeline_tag: text-classification
|
6 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
language:
|
4 |
- en
|
5 |
pipeline_tag: text-classification
|
6 |
+
---
|
7 |
+
|
8 |
+
## Model Description
|
9 |
+
This model is IBM's lightweight, 4-layer toxicity binary classifier for English. Its latency characteristics make it a suitable guardrail for any large language model. It can also be used for bulk processing of data where high throughput is needed. It has been trained on several benchmark datasets in English, specifically for detecting hateful, abusive, profane and other toxic content in plain text.
|
10 |
+
|
11 |
+
|
12 |
+
## Feature
|
13 |
+
This model offers very low inference latency and is capable of running on CPUs apart from GPUs and AIUs. It features 38 million parameters, reducing the number of hidden layers from 12 to 4, decreasing the hidden size from 768 to 576, and the intermediate size from 3072 to 768, compared to the original RoBERTa model architecture.
|
14 |
+
|
15 |
+
![Description of Image](38m_latency.png)
|
16 |
+
|
17 |
+
|
18 |
+
|
19 |
+
## Model Usage
|
20 |
+
```python
|
21 |
+
# Example of how to use the model
|
22 |
+
import torch
|
23 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
24 |
+
|
25 |
+
model_name_or_path = 'ibm-granite/granite-guardian-hap-38m'
|
26 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name_or_path)
|
27 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name_or_path)
|
28 |
+
|
29 |
+
# Sample text
|
30 |
+
text = ["This is the 1st test", "This is the 2nd test"]
|
31 |
+
input = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
|
32 |
+
|
33 |
+
with torch.no_grad():
|
34 |
+
logits = model(**input).logits
|
35 |
+
prediction = torch.argmax(logits, dim=1).detach().numpy().tolist() # Binary prediction where label 1 indicates toxicity.
|
36 |
+
probability = torch.softmax(logits, dim=1).detach().numpy()[:,1].tolist() # Probability of toxicity.
|
37 |
+
|
38 |
+
```
|
39 |
+
## Performance Comparison with Other Models
|
40 |
+
The model delivers competitive performance with significantly lower inference latency. If a better F1 score is required, please refer to IBM's 12-layer model here.
|
41 |
+
|
42 |
+
![Description of Image](38m_comparison_a.png)
|
43 |
+
![Description of Image](38m_comparison_b.png)
|