Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,92 +1,152 @@
|
|
| 1 |
---
|
| 2 |
-
base_model:
|
|
|
|
|
|
|
| 3 |
library_name: model2vec
|
| 4 |
license: mit
|
| 5 |
-
model_name:
|
| 6 |
tags:
|
| 7 |
-
- embeddings
|
| 8 |
- static-embeddings
|
| 9 |
-
-
|
|
|
|
| 10 |
---
|
| 11 |
|
| 12 |
-
#
|
|
|
|
|
|
|
| 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 |
-
|
| 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
|
| 33 |
|
| 34 |
-
|
| 35 |
-
|
|
|
|
| 36 |
|
| 37 |
-
# Compute text embeddings
|
| 38 |
-
embeddings = model.encode(["Example sentence"])
|
| 39 |
-
```
|
| 40 |
-
|
| 41 |
-
### Using Sentence Transformers
|
| 42 |
|
| 43 |
-
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
| 47 |
|
| 48 |
-
# Load a pretrained Sentence Transformer model
|
| 49 |
-
model = SentenceTransformer("tmpvsa4rrfx")
|
| 50 |
-
|
| 51 |
-
# Compute text embeddings
|
| 52 |
-
embeddings = model.encode(["Example sentence"])
|
| 53 |
```
|
| 54 |
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
-
# Save the model
|
| 66 |
-
m2v_model.save_pretrained("m2v_model")
|
| 67 |
-
```
|
| 68 |
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
##
|
| 76 |
|
| 77 |
-
-
|
| 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 |
-
##
|
| 84 |
|
| 85 |
-
|
|
|
|
|
|
|
| 86 |
|
| 87 |
## Citation
|
| 88 |
|
| 89 |
-
|
|
|
|
| 90 |
```
|
| 91 |
@software{minishlab2024model2vec,
|
| 92 |
author = {Stephan Tulkens and {van Dongen}, Thomas},
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: minishlab/potion-base-4m
|
| 3 |
+
datasets:
|
| 4 |
+
- nicholasKluge/harmful-text
|
| 5 |
library_name: model2vec
|
| 6 |
license: mit
|
| 7 |
+
model_name: enguard/tiny-guard-4m-en-prompt-harmfulness-binary-mix
|
| 8 |
tags:
|
|
|
|
| 9 |
- static-embeddings
|
| 10 |
+
- text-classification
|
| 11 |
+
- model2vec
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# enguard/tiny-guard-4m-en-prompt-harmfulness-binary-mix
|
| 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-harmfulness-binary found in the [nicholasKluge/harmful-text](https://huggingface.co/datasets/nicholasKluge/harmful-text) 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-harmfulness-binary-mix"
|
| 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-harmfulness-binary |
|
| 56 |
+
| Base Model | [minishlab/potion-base-4m](https://huggingface.co/minishlab/potion-base-4m) |
|
| 57 |
+
| Precision | 0.9570 |
|
| 58 |
+
| Recall | 0.8941 |
|
| 59 |
+
| F1 | 0.9245 |
|
| 60 |
+
|
| 61 |
+
### Confusion Matrix
|
| 62 |
+
|
| 63 |
+
| True \ Predicted | FAIL | PASS |
|
| 64 |
+
| --- | --- | --- |
|
| 65 |
+
| **FAIL** | 3747 | 422 |
|
| 66 |
+
| **PASS** | 155 | 4045 |
|
| 67 |
+
|
| 68 |
+
<details>
|
| 69 |
+
<summary><b>Full metrics (JSON)</b></summary>
|
| 70 |
+
|
| 71 |
+
```json
|
| 72 |
+
{
|
| 73 |
+
"FAIL": {
|
| 74 |
+
"precision": 0.9569564009997223,
|
| 75 |
+
"recall": 0.8941359626362221,
|
| 76 |
+
"f1-score": 0.9244802146210597,
|
| 77 |
+
"support": 3854.0
|
| 78 |
+
},
|
| 79 |
+
"PASS": {
|
| 80 |
+
"precision": 0.908273381294964,
|
| 81 |
+
"recall": 0.9630512514898689,
|
| 82 |
+
"f1-score": 0.934860580816846,
|
| 83 |
+
"support": 4195.0
|
| 84 |
+
},
|
| 85 |
+
"accuracy": 0.9300534227854392,
|
| 86 |
+
"macro avg": {
|
| 87 |
+
"precision": 0.9326148911473432,
|
| 88 |
+
"recall": 0.9285936070630455,
|
| 89 |
+
"f1-score": 0.9296703977189529,
|
| 90 |
+
"support": 8049.0
|
| 91 |
+
},
|
| 92 |
+
"weighted avg": {
|
| 93 |
+
"precision": 0.9315836506380053,
|
| 94 |
+
"recall": 0.9300534227854392,
|
| 95 |
+
"f1-score": 0.9298902824793431,
|
| 96 |
+
"support": 8049.0
|
| 97 |
+
}
|
| 98 |
+
}
|
| 99 |
+
```
|
| 100 |
+
</details>
|
| 101 |
|
|
|
|
| 102 |
|
| 103 |
+
<details>
|
| 104 |
+
<summary><b>Sample Predictions</b></summary>
|
| 105 |
|
| 106 |
+
| Text | True Label | Predicted Label |
|
| 107 |
+
|------|------------|-----------------|
|
| 108 |
+
| answer explain reviewing particular piece kryptonite | PASS | PASS |
|
| 109 |
+
| also remove old talk page discussions page discretion need speak please post new messages bottom talk page sign four tildes left note talk page likely respond comments either incivil flame bait personal attacks trolling deleted signpost deliveries automatically archived user talk sjones signpost thanks | PASS | PASS |
|
| 110 |
+
| A new task force to tackle mutilation was being launched, the panel said. | PASS | PASS |
|
| 111 |
+
| much quoting barnes lipstadt used source quote barnes words much need sources either put work context historians journalists responding time finally done near end respond points historians written recently many deaths destruction allied bombing human cost expulsion ethnic germans eastern europe drawing conclusions acknowledging abuses repeated according quotes article quotes thing said example add anything thought enough assessment others thought | PASS | PASS |
|
| 112 |
+
| angle sucks find better one | FAIL | FAIL |
|
| 113 |
+
| answer explain reviewing particular piece kryptonite | PASS | PASS |
|
| 114 |
+
</details>
|
| 115 |
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
+
<details>
|
| 118 |
+
<summary><b>Prediction Speed Benchmarks</b></summary>
|
| 119 |
|
| 120 |
+
| Dataset Size | Time (seconds) | Predictions/Second |
|
| 121 |
+
|--------------|----------------|---------------------|
|
| 122 |
+
| 1 | 0.0002 | 5526.09 |
|
| 123 |
+
| 1000 | 0.0811 | 12333.47 |
|
| 124 |
+
| 8369 | 0.5894 | 14200.2 |
|
| 125 |
+
</details>
|
| 126 |
|
|
|
|
| 127 |
|
| 128 |
+
## Other model variants
|
| 129 |
|
| 130 |
+
Below is a general overview of the best-performing models for each dataset variant.
|
|
|
|
|
|
|
|
|
|
| 131 |
|
| 132 |
+
| Classifies | Model | Precision | Recall | F1 |
|
| 133 |
+
| --- | --- | --- | --- | --- |
|
| 134 |
+
| prompt-harmfulness-binary | [enguard/tiny-guard-2m-en-prompt-harmfulness-binary-mix](https://huggingface.co/enguard/tiny-guard-2m-en-prompt-harmfulness-binary-mix) | 0.9533 | 0.8640 | 0.9065 |
|
| 135 |
+
| prompt-harmfulness-binary | [enguard/tiny-guard-4m-en-prompt-harmfulness-binary-mix](https://huggingface.co/enguard/tiny-guard-4m-en-prompt-harmfulness-binary-mix) | 0.9570 | 0.8941 | 0.9245 |
|
| 136 |
+
| prompt-harmfulness-binary | [enguard/tiny-guard-8m-en-prompt-harmfulness-binary-mix](https://huggingface.co/enguard/tiny-guard-8m-en-prompt-harmfulness-binary-mix) | 0.9522 | 0.9100 | 0.9306 |
|
| 137 |
+
| prompt-harmfulness-binary | [enguard/small-guard-32m-en-prompt-harmfulness-binary-mix](https://huggingface.co/enguard/small-guard-32m-en-prompt-harmfulness-binary-mix) | 0.9579 | 0.9141 | 0.9355 |
|
| 138 |
+
| prompt-harmfulness-binary | [enguard/medium-guard-128m-xx-prompt-harmfulness-binary-mix](https://huggingface.co/enguard/medium-guard-128m-xx-prompt-harmfulness-binary-mix) | 0.9558 | 0.8923 | 0.9230 |
|
| 139 |
|
| 140 |
+
## Resources
|
| 141 |
|
| 142 |
+
- Awesome AI Guardrails: <https://github.com/enguard-ai/awesome-ai-guardails>
|
| 143 |
+
- Model2Vec: https://github.com/MinishLab/model2vec
|
| 144 |
+
- Docs: https://minish.ai/packages/model2vec/introduction
|
| 145 |
|
| 146 |
## Citation
|
| 147 |
|
| 148 |
+
If you use this model, please cite Model2Vec:
|
| 149 |
+
|
| 150 |
```
|
| 151 |
@software{minishlab2024model2vec,
|
| 152 |
author = {Stephan Tulkens and {van Dongen}, Thomas},
|