Update README.md
Browse files
README.md
CHANGED
@@ -6,8 +6,21 @@ language:
|
|
6 |
# Text Classification GoEmotions
|
7 |
|
8 |
This is a quantized onnx model and is a fined-tuned version of [nreimers/MiniLMv2-L6-H384-distilled-from-BERT-Large](https://huggingface.co/nreimers/MiniLMv2-L6-H384-distilled-from-BERT-Large) on the on the [Jigsaw 1st Kaggle competition](https://www.kaggle.com/competitions/jigsaw-toxic-comment-classification-challenge) dataset using [unitary/toxic-bert](https://huggingface.co/unitary/toxic-bert) as teacher model.
|
|
|
9 |
|
10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
```py
|
13 |
import os
|
@@ -18,9 +31,7 @@ from tokenizers import Tokenizer
|
|
18 |
from onnxruntime import InferenceSession
|
19 |
|
20 |
|
21 |
-
|
22 |
-
|
23 |
-
model_name = "Ngit/MiniLM-L6-toxic-all-labels-onnx"
|
24 |
tokenizer = Tokenizer.from_pretrained(model_name)
|
25 |
tokenizer.enable_padding(
|
26 |
pad_token="<pad>",
|
@@ -31,9 +42,9 @@ batch_size = 16
|
|
31 |
|
32 |
texts = ["This is pure trash",]
|
33 |
outputs = []
|
34 |
-
model = InferenceSession("
|
35 |
|
36 |
-
with open(os.path.join("
|
37 |
config = json.load(f)
|
38 |
|
39 |
output_names = [output.name for output in model.get_outputs()]
|
@@ -43,13 +54,13 @@ for subtexts in np.array_split(np.array(texts), len(texts) // batch_size + 1):
|
|
43 |
encodings = tokenizer.encode_batch(list(subtexts))
|
44 |
inputs = {
|
45 |
"input_ids": np.vstack(
|
46 |
-
[encoding.ids for encoding in encodings],
|
47 |
),
|
48 |
"attention_mask": np.vstack(
|
49 |
-
[encoding.attention_mask for encoding in encodings],
|
50 |
),
|
51 |
"token_type_ids": np.vstack(
|
52 |
-
[encoding.type_ids for encoding in encodings],
|
53 |
),
|
54 |
}
|
55 |
|
@@ -77,7 +88,15 @@ for item in scores:
|
|
77 |
scores.append(float(s))
|
78 |
results.append({"labels": labels, "scores": scores})
|
79 |
|
80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
```
|
82 |
|
83 |
# Training hyperparameters
|
@@ -96,7 +115,7 @@ The following hyperparameters were used during training:
|
|
96 |
|
97 |
| Teacher (params) | Student (params) | Set (metric) | Score (teacher) | Score (student) |
|
98 |
|--------------------|-------------|----------|--------| --------|
|
99 |
-
| unitary/toxic-bert (110M) | MiniLMv2-
|
100 |
|
101 |
# Deployment
|
102 |
|
|
|
6 |
# Text Classification GoEmotions
|
7 |
|
8 |
This is a quantized onnx model and is a fined-tuned version of [nreimers/MiniLMv2-L6-H384-distilled-from-BERT-Large](https://huggingface.co/nreimers/MiniLMv2-L6-H384-distilled-from-BERT-Large) on the on the [Jigsaw 1st Kaggle competition](https://www.kaggle.com/competitions/jigsaw-toxic-comment-classification-challenge) dataset using [unitary/toxic-bert](https://huggingface.co/unitary/toxic-bert) as teacher model.
|
9 |
+
The original model can be found [here](https://huggingface.co/minuva/MiniLMv2-toxic-jijgsaw)
|
10 |
|
11 |
+
|
12 |
+
# Usage
|
13 |
+
|
14 |
+
## Installation
|
15 |
+
|
16 |
+
```bash
|
17 |
+
pip install tokenizers
|
18 |
+
pip install onnxruntime
|
19 |
+
git clone https://huggingface.co/minuva/MiniLMv2-toxic-jijgsaw-onnx
|
20 |
+
```
|
21 |
+
|
22 |
+
|
23 |
+
## Load the Model
|
24 |
|
25 |
```py
|
26 |
import os
|
|
|
31 |
from onnxruntime import InferenceSession
|
32 |
|
33 |
|
34 |
+
model_name = "minuva/MiniLMv2-toxic-jijgsaw-onnx"
|
|
|
|
|
35 |
tokenizer = Tokenizer.from_pretrained(model_name)
|
36 |
tokenizer.enable_padding(
|
37 |
pad_token="<pad>",
|
|
|
42 |
|
43 |
texts = ["This is pure trash",]
|
44 |
outputs = []
|
45 |
+
model = InferenceSession("MiniLMv2-toxic-jijgsaw-onnx/model_optimized_quantized.onnx", providers=['CUDAExecutionProvider'])
|
46 |
|
47 |
+
with open(os.path.join("MiniLMv2-toxic-jijgsaw-onnx", "config.json"), "r") as f:
|
48 |
config = json.load(f)
|
49 |
|
50 |
output_names = [output.name for output in model.get_outputs()]
|
|
|
54 |
encodings = tokenizer.encode_batch(list(subtexts))
|
55 |
inputs = {
|
56 |
"input_ids": np.vstack(
|
57 |
+
[encoding.ids for encoding in encodings],
|
58 |
),
|
59 |
"attention_mask": np.vstack(
|
60 |
+
[encoding.attention_mask for encoding in encodings],
|
61 |
),
|
62 |
"token_type_ids": np.vstack(
|
63 |
+
[encoding.type_ids for encoding in encodings],
|
64 |
),
|
65 |
}
|
66 |
|
|
|
88 |
scores.append(float(s))
|
89 |
results.append({"labels": labels, "scores": scores})
|
90 |
|
91 |
+
res = []
|
92 |
+
|
93 |
+
for result in results:
|
94 |
+
joined = list(zip(result['labels'], result['scores']))
|
95 |
+
max_score = max(joined, key=lambda x: x[1])
|
96 |
+
res.append(max_score)
|
97 |
+
|
98 |
+
res
|
99 |
+
# [('toxic', 0.736885666847229)]
|
100 |
```
|
101 |
|
102 |
# Training hyperparameters
|
|
|
115 |
|
116 |
| Teacher (params) | Student (params) | Set (metric) | Score (teacher) | Score (student) |
|
117 |
|--------------------|-------------|----------|--------| --------|
|
118 |
+
| unitary/toxic-bert (110M) | MiniLMv2-toxic-jijgsaw-onnx (23M) | Test (ROC_AUC) | 0.98636 | 0.98130 |
|
119 |
|
120 |
# Deployment
|
121 |
|