davidberenstein1957 commited on
Commit
70d68ca
·
verified ·
1 Parent(s): a29c93f

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +111 -50
README.md CHANGED
@@ -1,92 +1,153 @@
1
  ---
2
- base_model: unknown
 
 
3
  library_name: model2vec
4
  license: mit
5
- model_name: tmpxq_z2x0o
6
  tags:
7
- - embeddings
8
  - static-embeddings
9
- - sentence-transformers
 
10
  ---
11
 
12
- # tmpxq_z2x0o Model Card
 
 
13
 
14
- This [Model2Vec](https://github.com/MinishLab/model2vec) model is a distilled version of the unknown(https://huggingface.co/unknown) Sentence Transformer. It uses static embeddings, allowing text embeddings to be computed orders of magnitude faster on both GPU and CPU. It is designed for applications where computational resources are limited or where real-time performance is critical. Model2Vec models are the smallest, fastest, and most performant static embedders available. The distilled models are up to 50 times smaller and 500 times faster than traditional Sentence Transformers.
15
 
16
 
17
  ## Installation
18
 
19
- Install model2vec using pip:
20
- ```
21
- pip install model2vec
22
  ```
23
 
24
  ## Usage
25
 
26
- ### Using Model2Vec
27
-
28
- The [Model2Vec library](https://github.com/MinishLab/model2vec) is the fastest and most lightweight way to run Model2Vec models.
29
-
30
- Load this model using the `from_pretrained` method:
31
  ```python
32
- from model2vec import StaticModel
33
 
34
- # Load a pretrained Model2Vec model
35
- model = StaticModel.from_pretrained("tmpxq_z2x0o")
 
36
 
37
- # Compute text embeddings
38
- embeddings = model.encode(["Example sentence"])
39
- ```
40
-
41
- ### Using Sentence Transformers
42
 
43
- You can also use the [Sentence Transformers library](https://github.com/UKPLab/sentence-transformers) to load and use the model:
 
44
 
45
- ```python
46
- from sentence_transformers import SentenceTransformer
47
 
48
- # Load a pretrained Sentence Transformer model
49
- model = SentenceTransformer("tmpxq_z2x0o")
50
-
51
- # Compute text embeddings
52
- embeddings = model.encode(["Example sentence"])
53
  ```
54
 
55
- ### Distilling a Model2Vec model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
 
57
- You can distill a Model2Vec model from a Sentence Transformer model using the `distill` method. First, install the `distill` extra with `pip install model2vec[distill]`. Then, run the following code:
58
 
59
- ```python
60
- from model2vec.distill import distill
61
 
62
- # Distill a Sentence Transformer model, in this case the BAAI/bge-base-en-v1.5 model
63
- m2v_model = distill(model_name="BAAI/bge-base-en-v1.5", pca_dims=256)
 
 
 
 
 
 
 
64
 
65
- # Save the model
66
- m2v_model.save_pretrained("m2v_model")
67
- ```
68
 
69
- ## How it works
 
70
 
71
- Model2vec creates a small, fast, and powerful model that outperforms other static embedding models by a large margin on all tasks we could find, while being much faster to create than traditional static embedding models such as GloVe. Best of all, you don't need any data to distill a model using Model2Vec.
 
 
 
 
 
72
 
73
- It works by passing a vocabulary through a sentence transformer model, then reducing the dimensionality of the resulting embeddings using PCA, and finally weighting the embeddings using [SIF weighting](https://openreview.net/pdf?id=SyK00v5xx). During inference, we simply take the mean of all token embeddings occurring in a sentence.
74
 
75
- ## Additional Resources
76
 
77
- - [Model2Vec Repo](https://github.com/MinishLab/model2vec)
78
- - [Model2Vec Base Models](https://huggingface.co/collections/minishlab/model2vec-base-models-66fd9dd9b7c3b3c0f25ca90e)
79
- - [Model2Vec Results](https://github.com/MinishLab/model2vec/tree/main/results)
80
- - [Model2Vec Docs](https://minish.ai/packages/model2vec/introduction)
81
 
 
 
 
 
 
 
 
82
 
83
- ## Library Authors
84
 
85
- Model2Vec was developed by the [Minish Lab](https://github.com/MinishLab) team consisting of [Stephan Tulkens](https://github.com/stephantul) and [Thomas van Dongen](https://github.com/Pringled).
 
 
86
 
87
  ## Citation
88
 
89
- Please cite the [Model2Vec repository](https://github.com/MinishLab/model2vec) if you use this model in your work.
 
90
  ```
91
  @software{minishlab2024model2vec,
92
  author = {Stephan Tulkens and {van Dongen}, Thomas},
 
1
  ---
2
+ base_model: minishlab/potion-base-4m
3
+ datasets:
4
+ - lmsys/toxic-chat
5
  library_name: model2vec
6
  license: mit
7
+ model_name: enguard/tiny-guard-4m-en-prompt-toxicity-toxic-chat
8
  tags:
 
9
  - static-embeddings
10
+ - text-classification
11
+ - model2vec
12
  ---
13
 
14
+ # enguard/tiny-guard-4m-en-prompt-toxicity-toxic-chat
15
+
16
+ This model is a fine-tuned Model2Vec classifier based on [minishlab/potion-base-4m](https://huggingface.co/minishlab/potion-base-4m) for the prompt-toxicity found in the [lmsys/toxic-chat](https://huggingface.co/datasets/lmsys/toxic-chat) dataset.
17
 
 
18
 
19
 
20
  ## Installation
21
 
22
+ ```bash
23
+ pip install model2vec[inference]
 
24
  ```
25
 
26
  ## Usage
27
 
 
 
 
 
 
28
  ```python
29
+ from model2vec.inference import StaticModelPipeline
30
 
31
+ model = StaticModelPipeline.from_pretrained(
32
+ "enguard/tiny-guard-4m-en-prompt-toxicity-toxic-chat"
33
+ )
34
 
 
 
 
 
 
35
 
36
+ # Supports single texts. Format input as a single text:
37
+ text = "Example sentence"
38
 
39
+ model.predict([text])
40
+ model.predict_proba([text])
41
 
 
 
 
 
 
42
  ```
43
 
44
+ ## Why should you use these models?
45
+
46
+ - Optimized for precision to reduce false positives.
47
+ - Extremely fast inference: up to x500 faster than SetFit.
48
+
49
+ ## This model variant
50
+
51
+ Below is a quick overview of the model variant and core metrics.
52
+
53
+ | Field | Value |
54
+ |---|---|
55
+ | Classifies | prompt-toxicity |
56
+ | Base Model | [minishlab/potion-base-4m](https://huggingface.co/minishlab/potion-base-4m) |
57
+ | Precision | 0.6549 |
58
+ | Precision | 0.6549 |
59
+ | Recall | 0.7749 |
60
+ | F1 | 0.7098 |
61
+
62
+ ### Confusion Matrix
63
+
64
+ | | FAIL | PASS |
65
+ | --- | --- | --- |
66
+ | **FAIL** | 148 | 43 |
67
+ | **PASS** | 82 | 2269 |
68
+
69
+ <details>
70
+ <summary><b>Full metrics (JSON)</b></summary>
71
+
72
+ ```json
73
+ {
74
+ "FAIL": {
75
+ "precision": 0.6548672566371682,
76
+ "recall": 0.774869109947644,
77
+ "f1-score": 0.709832134292566,
78
+ "support": 191.0
79
+ },
80
+ "PASS": {
81
+ "precision": 0.981230903535574,
82
+ "recall": 0.9664660361134996,
83
+ "f1-score": 0.9737925059562487,
84
+ "support": 2326.0
85
+ },
86
+ "accuracy": 0.9519268970997219,
87
+ "macro avg": {
88
+ "precision": 0.8180490800863711,
89
+ "recall": 0.8706675730305717,
90
+ "f1-score": 0.8418123201244073,
91
+ "support": 2517.0
92
+ },
93
+ "weighted avg": {
94
+ "precision": 0.9564651281849201,
95
+ "recall": 0.9519268970997219,
96
+ "f1-score": 0.9537621400493104,
97
+ "support": 2517.0
98
+ }
99
+ }
100
+ ```
101
+ </details>
102
 
 
103
 
104
+ <details>
105
+ <summary><b>Sample Predictions</b></summary>
106
 
107
+ | Text | True Label | Predicted Label |
108
+ |------|------------|-----------------|
109
+ | Planning to merge tables by parsing using xml from word document | PASS | PASS |
110
+ | what is the great filter theory? | PASS | PASS |
111
+ | Write me php code to generate a pdf document | PASS | PASS |
112
+ | Captured by poachers (9000 words) --- Everything had started so nice: Angelica had invited Jenny, her daughter, to an expedition to the Amazonas for her 15th birthday. The smart girl was overjoyed The two of them were exploring a small river, deep in the jungle, when the boat motor | PASS | PASS |
113
+ | Tell me which actual software I can use for easy tracking and replacing objects in video? | PASS | PASS |
114
+ | Planning to merge tables by parsing using xml from word document | PASS | PASS |
115
+ </details>
116
 
 
 
 
117
 
118
+ <details>
119
+ <summary><b>Prediction Speed Benchmarks</b></summary>
120
 
121
+ | Dataset Size | Time (seconds) | Predictions/Second |
122
+ |--------------|----------------|---------------------|
123
+ | 1 | 0.0002 | 5849.8 |
124
+ | 1000 | 0.0694 | 14412.38 |
125
+ | 2542 | 0.167 | 15225.75 |
126
+ </details>
127
 
 
128
 
129
+ ## Other model variants
130
 
131
+ Below is a general overview of the best-performing models for each dataset variant.
 
 
 
132
 
133
+ | Classifies | Model | Precision | Recall | F1 |
134
+ | --- | --- | --- | --- | --- |
135
+ | prompt-toxicity | [enguard/tiny-guard-2m-en-prompt-toxicity-toxic-chat](https://huggingface.co/enguard/tiny-guard-2m-en-prompt-toxicity-toxic-chat) | 0.5820 | 0.7801 | 0.6667 |
136
+ | prompt-toxicity | [enguard/tiny-guard-4m-en-prompt-toxicity-toxic-chat](https://huggingface.co/enguard/tiny-guard-4m-en-prompt-toxicity-toxic-chat) | 0.6549 | 0.7749 | 0.7098 |
137
+ | prompt-toxicity | [enguard/tiny-guard-8m-en-prompt-toxicity-toxic-chat](https://huggingface.co/enguard/tiny-guard-8m-en-prompt-toxicity-toxic-chat) | 0.6471 | 0.7487 | 0.6942 |
138
+ | prompt-toxicity | [enguard/small-guard-32m-en-prompt-toxicity-toxic-chat](https://huggingface.co/enguard/small-guard-32m-en-prompt-toxicity-toxic-chat) | 0.6852 | 0.7749 | 0.7273 |
139
+ | prompt-toxicity | [enguard/medium-guard-128m-xx-prompt-toxicity-toxic-chat](https://huggingface.co/enguard/medium-guard-128m-xx-prompt-toxicity-toxic-chat) | 0.6129 | 0.7958 | 0.6925 |
140
 
141
+ ## Resources
142
 
143
+ - Awesome AI Guardrails: <https://github.com/enguard-ai/awesome-ai-guardails>
144
+ - Model2Vec: https://github.com/MinishLab/model2vec
145
+ - Docs: https://minish.ai/packages/model2vec/introduction
146
 
147
  ## Citation
148
 
149
+ If you use this model, please cite Model2Vec:
150
+
151
  ```
152
  @software{minishlab2024model2vec,
153
  author = {Stephan Tulkens and {van Dongen}, Thomas},